public void TestAngleFromVector2() { Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(Vector2.right), 0f)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(Vector2.up), CPMath.PI * 0.5f)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(Vector2.left), CPMath.PI)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(Vector2.down), -CPMath.PI * 0.5f)); float angle1 = 0.132f; Vector2 vec1 = CPMath.AngleToVector2(angle1); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(vec1), angle1)); float angle2 = 2.834f; Vector2 vec2 = CPMath.AngleToVector2(angle2); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(vec2), angle2)); float angle3 = 4.324f; Vector2 vec3 = CPMath.AngleToVector2(angle3); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(vec3), angle3 - CPMath.TAU)); float angle4 = 6.123f; Vector2 vec4 = CPMath.AngleToVector2(angle4); Assert.IsTrue(TestUtils.Approx(CPMath.AngleFromVector2(vec4), angle4 - CPMath.TAU)); }
public void TestAngleToVector2() { Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(0f), Vector2.right)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(CPMath.PI * 0.5f), Vector2.up)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(CPMath.PI), Vector2.left)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(CPMath.PI * 1.5f), Vector2.down)); Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(CPMath.PI * 2f), Vector2.right)); Vector2 vec1 = new Vector2(3f, 9f); float angle1 = CPMath.AngleFromVector2(vec1); Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(angle1), vec1.normalized)); Vector2 vec2 = new Vector2(-2.34f, 9.8f); float angle2 = CPMath.AngleFromVector2(vec2) - CPMath.TAU; Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(angle2), vec2.normalized)); Vector2 vec3 = new Vector2(-2f, -100f); float angle3 = CPMath.AngleFromVector2(vec3) + 2f * CPMath.TAU; Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(angle3), vec3.normalized)); Vector2 vec4 = new Vector2(3.45f, -9f); float angle4 = CPMath.AngleFromVector2(vec4) - 3f * CPMath.TAU; Assert.IsTrue(TestUtils.Approx(CPMath.AngleToVector2(angle4), vec4.normalized)); }