Index: ps/trunk/binaries/data/mods/public/simulation/components/Formation.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/Formation.js +++ ps/trunk/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: ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Formation.js =================================================================== --- ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Formation.js +++ ps/trunk/binaries/data/mods/public/simulation/components/tests/test_Formation.js @@ -0,0 +1,40 @@ +Engine.LoadComponentScript("interfaces/Timer.js"); +Engine.LoadComponentScript("interfaces/Formation.js"); +Engine.LoadComponentScript("Formation.js"); + +const entity_id = 5; + +AddMock(SYSTEM_ENTITY, IID_Timer, { + "SetInterval": () => {}, + "SetTimeout": () => {}, +}); + +const formationTemplate = { + "RequiredMemberCount": 2, + "DisabledTooltip": "", + "SpeedMultiplier": 1, + "FormationShape": "square", + "MaxTurningAngle": 0, + "SortingClasses": "Hero Champion Cavalry Melee Ranged", + "SortingOrder": "fillToTheCenter", + "ShiftRows": false, + "UnitSeparationWidthMultiplier": 1, + "UnitSeparationDepthMultiplier": 1, + "WidthDepthRatio": 1, + "Sloppiness": 0 +}; + +const cmpFormation = ConstructComponent(entity_id, "Formation", formationTemplate); + +const testingAngles = []; + +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))); + +cmpFormation.maxTurningAngle = Math.PI; + +TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, x))); +TS_ASSERT(testingAngles.every(x => cmpFormation.AreAnglesSimilar(0, -x)));