Index: binaries/data/mods/public/simulation/components/Formation.js =================================================================== --- binaries/data/mods/public/simulation/components/Formation.js +++ binaries/data/mods/public/simulation/components/Formation.js @@ -523,7 +523,7 @@ // When we are out of world or the angle difference is big, trigger repositioning. // Do this before setting up the position, because then we will always be in world. - if (!cmpPosition.IsInWorld() || !this.AreAnglesSimilar(newRotation, oldRotation)) + if (!cmpPosition.IsInWorld() || !this.DoesAngleDifferenceAllowTurning(newRotation, oldRotation)) this.offsets = undefined; this.SetupPositionAndHandleRotation(avgpos.x, avgpos.y, newRotation, true); @@ -885,12 +885,12 @@ }; /** - * Returns true if the two given angles (in radians) + * Returns true if the difference between two given angles (in radians) * are smaller than the maximum turning angle of the formation and therfore allow * the formation turn without reassigning positions. */ -Formation.prototype.AreAnglesSimilar = function(a1, a2) +Formation.prototype.DoesAngleDifferenceAllowTurning = function(a1, a2) { const d = Math.abs(a1 - a2) % (2 * Math.PI); return d < this.maxTurningAngle || d > 2 * Math.PI - this.maxTurningAngle; Index: binaries/data/mods/public/simulation/components/tests/test_Formation.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Formation.js +++ binaries/data/mods/public/simulation/components/tests/test_Formation.js @@ -31,10 +31,10 @@ for (let i = 0; i < 179; i++) testingAngles.push(i * Math.PI / 180); -TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, x))); -TS_ASSERT(testingAngles.every(x => !cmpFormation.AreAnglesSimilar(0, -x))); +TS_ASSERT(testingAngles.every(x => !cmpFormation.DoesAngleDifferenceAllowTurning(0, x))); +TS_ASSERT(testingAngles.every(x => !cmpFormation.DoesAngleDifferenceAllowTurning(0, -x))); cmpFormation.maxTurningAngle = Math.PI; -TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, x))); -TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, -x))); +TS_ASSERT(testingAngles.every(x => cmpFormation.DoesAngleDifferenceAllowTurning(0, x))); +TS_ASSERT(testingAngles.every(x => cmpFormation.DoesAngleDifferenceAllowTurning(0, -x)));