diff --git a/binaries/data/mods/public/globalscripts/vector.js b/binaries/data/mods/public/globalscripts/vector.js index 3a404135d4..5d10e4c5b5 100644 --- a/binaries/data/mods/public/globalscripts/vector.js +++ b/binaries/data/mods/public/globalscripts/vector.js @@ -77,7 +77,7 @@ Vector2D.prototype.rotate = function(angle) return this.set( this.x * cos + this.y * sin, - this.y * cos - this.x * sin); + -this.x * sin + this.y * cos); }; /** diff --git a/binaries/data/mods/public/simulation/components/tests/test_Vector.js b/binaries/data/mods/public/simulation/components/tests/test_Vector.js index 92f1f7876b..8ae3e6b715 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Vector.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Vector.js @@ -74,6 +74,21 @@ var brokenVector = { } } +// Test Vector2D rotation further +{ + let epsilon = 0.00000001; + + for (let i = 0; i <= 128; ++i) + { + let angle = i / 128 * Math.PI; + let vec1 = new Vector2D(Math.cos(angle), Math.sin(angle)); + let vec2 = new Vector2D(1, 0).rotate(-angle); + + TS_ASSERT_EQUALS_APPROX(vec1.x, vec2.x, epsilon); + TS_ASSERT_EQUALS_APPROX(vec1.y, vec2.y, epsilon); + } +} + // Test Vector2D rotation around a center { let epsilon = 0.00000001; diff --git a/binaries/data/tests/test_setup.js b/binaries/data/tests/test_setup.js index 94d1980b14..f4c0f78cfd 100644 --- a/binaries/data/tests/test_setup.js +++ b/binaries/data/tests/test_setup.js @@ -34,6 +34,9 @@ global.TS_ASSERT_EQUALS = function TS_ASSERT_EQUALS(x, y) global.TS_ASSERT_EQUALS_APPROX = function TS_ASSERT_EQUALS_APPROX(x, y, maxDifference) { + if (!Number.isInteger(maxDifference)) + fail("Test must pass a maximum difference!"); + if (Math.abs(x - y) > maxDifference) fail("Expected almost equal, got " + uneval(x) + " !== " + uneval(y)); }