constrained rotation to shortest path

This commit is contained in:
jonasengelmann 2022-06-29 19:47:26 +02:00
parent 1b27e59be8
commit 3cdd94e465
2 changed files with 11 additions and 2 deletions

View File

@ -917,7 +917,16 @@ $.Viewport.prototype = {
if (immediately) { if (immediately) {
this.degreesSpring.resetTo(degrees); this.degreesSpring.resetTo(degrees);
} else { } else {
this.degreesSpring.springTo(degrees); var from = $.euclideanModulo(this.degreesSpring.current.value, 360);
this.degreesSpring.resetTo(from);
var to = $.euclideanModulo(degrees, 360);
var diff = to - from;
if (diff > 180) {
to -= 360;
} else if (diff < -180) {
to += 360;
}
this.degreesSpring.springTo(to);
} }
this._setContentBounds( this._setContentBounds(

View File

@ -1075,7 +1075,7 @@
viewport.setRotation(400); viewport.setRotation(400);
assert.strictEqual(viewport.getRotation(true), 0, 'current rotation is not changed'); assert.strictEqual(viewport.getRotation(true), 0, 'current rotation is not changed');
assert.strictEqual(viewport.getRotation(false), 400, 'target rotation is set correctly'); assert.strictEqual(viewport.getRotation(false), 40, 'target rotation is set correctly');
viewport.setRotation(200, true); viewport.setRotation(200, true);
assert.strictEqual(viewport.getRotation(true), 200, 'current rotation is set correctly'); assert.strictEqual(viewport.getRotation(true), 200, 'current rotation is set correctly');