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 @@ -892,7 +892,7 @@ Formation.prototype.AreAnglesSimilar = function(a1, a2) { - const d = Math.abs(a1 - a2) % 2 * Math.PI; + 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 @@ -0,0 +1,32 @@ +Engine.LoadComponentScript("interfaces/Formation.js"); +Engine.LoadComponentScript("Formation.js"); + +const entity_id = 5; + +const formation_template = { + "maxTurningAngle": Math.PI/2 +}; + +function setEntityUp() +{ + let cmpFormation = ConstructComponent(entity_id, "Formation", formation_template); + return cmpFormation; +} + +var cmpFormation = setEntityUp(); + +let angle1 = Math.PI/2; +let angle2 = - angle1; +TS_ASSERT_EQUALS(cmpFormation.AreAnglesSimilar(angle1, angle2), false); + +angle1 = Math.PI/5; +angle2 = - angle1; +TS_ASSERT_EQUALS(cmpFormation.AreAnglesSimilar(angle1, angle2), true); + +angle1 = 10 * Math.PI/2; +angle2 = - angle1; +TS_ASSERT_EQUALS(cmpFormation.AreAnglesSimilar(angle1, angle2), false); + +angle1 = 10 * Math.PI/5; +angle2 = - angle1; +TS_ASSERT_EQUALS(cmpFormation.AreAnglesSimilar(angle1, angle2), true);