From 5f50d9e59e27a568c34879595c48ac36b0eadece Mon Sep 17 00:00:00 2001 From: jonasengelmann <40031476+jonasengelmann@users.noreply.github.com> Date: Mon, 22 Aug 2022 15:34:29 +0200 Subject: [PATCH] reworked setRotation to allow all degree values --- src/viewport.js | 16 +++++++++------- test/modules/viewport.js | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/viewport.js b/src/viewport.js index 9a058968..f8d7ea24 100644 --- a/src/viewport.js +++ b/src/viewport.js @@ -917,16 +917,18 @@ $.Viewport.prototype = { if (immediately) { this.degreesSpring.resetTo(degrees); } else { - var from = $.euclideanModulo(this.degreesSpring.current.value, 360); - this.degreesSpring.resetTo(from); - var to = $.euclideanModulo(degrees, 360); - var diff = to - from; + var normalizedFrom = $.positiveModulo(this.degreesSpring.current.value, 360); + var normalizedTo = $.positiveModulo(degrees, 360); + var diff = normalizedTo - normalizedFrom; if (diff > 180) { - to -= 360; + normalizedTo -= 360; } else if (diff < -180) { - to += 360; + normalizedTo += 360; } - this.degreesSpring.springTo(to); + + var reverseDiff = normalizedFrom - normalizedTo; + this.degreesSpring.resetTo(degrees + reverseDiff); + this.degreesSpring.springTo(degrees); } this._setContentBounds( diff --git a/test/modules/viewport.js b/test/modules/viewport.js index 804af1e9..59597060 100644 --- a/test/modules/viewport.js +++ b/test/modules/viewport.js @@ -1075,7 +1075,7 @@ viewport.setRotation(400); assert.strictEqual(viewport.getRotation(true), 0, 'current rotation is not changed'); - assert.strictEqual(viewport.getRotation(false), 40, 'target rotation is set correctly'); + assert.strictEqual(viewport.getRotation(false), 400, 'target rotation is set correctly'); viewport.setRotation(200, true); assert.strictEqual(viewport.getRotation(true), 200, 'current rotation is set correctly');