From 0d683eb9d2dcf97d48e864230e8fa918d8056911 Mon Sep 17 00:00:00 2001 From: Jono Brandel Date: Fri, 20 Sep 2024 21:28:19 -0700 Subject: [PATCH] Handle negative scale values --- src/renderers/webgl.js | 42 ++++++++++++++++++++++++++-------------- wiki/changelog/README.md | 1 + 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/renderers/webgl.js b/src/renderers/webgl.js index 389f1d31..56d9ab83 100644 --- a/src/renderers/webgl.js +++ b/src/renderers/webgl.js @@ -546,13 +546,16 @@ const webgl = { if (!(this._renderer.scale instanceof Vector)) { this._renderer.scale = new Vector(); } + let sx, sy; if (this._scale instanceof Vector) { - this._renderer.scale.x = this._scale.x * parent._renderer.scale.x; - this._renderer.scale.y = this._scale.y * parent._renderer.scale.y; + sx = this._scale.x * parent._renderer.scale.x; + sy = this._scale.y * parent._renderer.scale.y; } else { - this._renderer.scale.x = this._scale * parent._renderer.scale.x; - this._renderer.scale.y = this._scale * parent._renderer.scale.y; + sx = this._scale * parent._renderer.scale.x; + sy = this._scale * parent._renderer.scale.y; } + this._renderer.scale.x = sx < 0 ? -sx : sx; + this._renderer.scale.y = sy < 0 ? -sy : sy; if (parentChanged) { this._renderer.parent = parent; @@ -839,13 +842,16 @@ const webgl = { if (!(this._renderer.scale instanceof Vector)) { this._renderer.scale = new Vector(); } + let sx, sy; if (this._scale instanceof Vector) { - this._renderer.scale.x = this._scale.x * parent._renderer.scale.x; - this._renderer.scale.y = this._scale.y * parent._renderer.scale.y; + sx = this._scale.x * parent._renderer.scale.x; + sy = this._scale.y * parent._renderer.scale.y; } else { - this._renderer.scale.x = this._scale * parent._renderer.scale.x; - this._renderer.scale.y = this._scale * parent._renderer.scale.y; + sx = this._scale * parent._renderer.scale.x; + sy = this._scale * parent._renderer.scale.y; } + this._renderer.scale.x = sx < 0 ? -sx : sx; + this._renderer.scale.y = sy < 0 ? -sy : sy; if (parentChanged) { this._renderer.parent = parent; @@ -1270,13 +1276,16 @@ const webgl = { if (!(this._renderer.scale instanceof Vector)) { this._renderer.scale = new Vector(); } + let sx, sy; if (this._scale instanceof Vector) { - this._renderer.scale.x = this._scale.x * parent._renderer.scale.x; - this._renderer.scale.y = this._scale.y * parent._renderer.scale.y; + sx = this._scale.x * parent._renderer.scale.x; + sy = this._scale.y * parent._renderer.scale.y; } else { - this._renderer.scale.x = this._scale * parent._renderer.scale.x; - this._renderer.scale.y = this._scale * parent._renderer.scale.y; + sx = this._scale * parent._renderer.scale.x; + sy = this._scale * parent._renderer.scale.y; } + this._renderer.scale.x = sx < 0 ? -sx : sx; + this._renderer.scale.y = sy < 0 ? -sy : sy; if (parentChanged) { this._renderer.parent = parent; @@ -1516,11 +1525,16 @@ const webgl = { this._renderer.scale = new Vector(); } + let sx, sy; if (this._scale instanceof Vector) { - this._renderer.scale.copy(this._scale); + sx = this._scale.x; + sy = this._scale.y; } else { - this._renderer.scale.set(this._scale, this._scale); + sx = this._scale; + sy = this._scale; } + this._renderer.scale.x = sx < 0 ? -sx : sx; + this._renderer.scale.y = sy < 0 ? -sy : sy; } return this.flagReset(); diff --git a/wiki/changelog/README.md b/wiki/changelog/README.md index ad786ab2..19cb5565 100644 --- a/wiki/changelog/README.md +++ b/wiki/changelog/README.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. The format ## Nightly ++ `Two.WebGLRenderer` correctly handles negative scale values + `Two.Path.noStroke`, `Two.Text.noStroke`, and derivative methods now include setting both the stroke color to `"none"` and the line width to 0 + Fixed `Two.Arc` flag behavior for `Two.Arc.width` and `Two.Arc.height` properties