Added Vec2 Angle and AngleBetween methods and tests!
@@ -58,12 +58,57 @@ class DocVec : ITest
return visible && dotPerpendicular && dotInvisible;
}
+ static bool TestAngles()
+ {
+ /// :CodeSample: Vec2.Angle
+ Vec2 point = new Vec2(1, 0);
+ float angle0 = point.Angle();
+
+ point = new Vec2(0, 1);
+ float angle90 = point.Angle();
+
+ point = new Vec2(-1, 0);
+ float angle180 = point.Angle();
+
+ point = new Vec2(0, -1);
+ float angle270 = point.Angle();
+ /// :End:
+
+ point = new Vec2(2.75f, 2.75f);
+ float angle45 = point.Angle();
+
+ Log.Info($"Angles 0 == {angle0}, Angles 45 == {angle45}, 90 == {angle90}, 180 == {angle180}, 270 == {angle270}");
+ return angle0 == 0 && angle90 == 90 && angle180 == 180 && angle270 == 270;
+ }
+
+ static bool TestAngleBetween()
+ {
+ /// :CodeSample: Vec2.AngleBetween
+ Vec2 directionA = new Vec2( 1, 1);
+ Vec2 directionB = new Vec2(-1, 1);
+ float angle90 = Vec2.AngleBetween(directionA, directionB);
+
+ directionA = new Vec2(1, 1);
+ directionB = new Vec2(0,-2);
+ float angleNegative135 = Vec2.AngleBetween(directionA, directionB);
+ /// :End:
+
+ directionA = new Vec2(1, 1);
+ directionB = new Vec2(0, 1);
+ float angle45 = Vec2.AngleBetween(directionA, directionB);
+
+ Log.Info($"AngleBetween 45 == {angle45}, 90 == {angle90}, -135 == {angleNegative135}");
+ return angle45 == 45 && angle90 == 90 && angleNegative135 == -135;
+ }
+
public void Initialize()
{
Tests.Test(TestDistance);
Tests.Test(TestDistanceSq);
Tests.Test(TestLerp);
Tests.Test(TestDot);
+ Tests.Test(TestAngles);
+ Tests.Test(TestAngleBetween);
}
public void Shutdown(){}
