예제 #1
0
 public void GcMathCos()
 {
     Assert.IsTrue(GcMath.AlmostSame(GcMath.Cos(0f), 1f), $"{GcMath.Cos(0f):e}");
     //Assert.IsTrue(GcMath.AlmostSame(GcMath.Cos(90f), 0f), $"{GcMath.Cos(90f):e}");
     Assert.IsTrue(GcMath.AlmostSame(GcMath.Cos(180f), -1f), $"{GcMath.Cos(180f):e}");
     //Assert.IsTrue(GcMath.AlmostSame(GcMath.Cos(270f), 0f), $"{GcMath.Cos(270f):e}");
 }
예제 #2
0
        public void GcMathAlmostSame()
        {
            for (var i = 0; i < 100; i++)
            {
                var v1 = UnityEngine.Random.Range(float.MinValue, float.MaxValue - 1);
                var v2 = v1 + math.EPSILON;
                var v3 = v1 - math.EPSILON;
                Assert.IsTrue(GcMath.AlmostSame(v1, v2));
                Assert.IsTrue(GcMath.AlmostSame(v1, v3));
            }
            for (var i = 0; i < 100; i++)
            {
                var v1 = new float2(UnityEngine.Random.Range(float.MinValue, float.MaxValue - 1), UnityEngine.Random.Range(float.MinValue, float.MaxValue - 1));
                var v2 = v1 + new float2(math.EPSILON, math.EPSILON);
                var v3 = v1 + new float2(math.EPSILON, -math.EPSILON);
                var v4 = v1 + new float2(-math.EPSILON, -math.EPSILON);
                Assert.IsTrue(GcMath.AlmostSame(v1, v2));
                Assert.IsTrue(GcMath.AlmostSame(v1, v3));
                Assert.IsTrue(GcMath.AlmostSame(v1, v4));
            }

            Assert.IsTrue(GcMath.AlmostSame(float.PositiveInfinity, float.PositiveInfinity));
            Assert.IsTrue(GcMath.AlmostSame(float.NegativeInfinity, float.NegativeInfinity));
            Assert.IsFalse(GcMath.AlmostSame(0, float.PositiveInfinity));
            Assert.IsFalse(GcMath.AlmostSame(0, float.NegativeInfinity));
            Assert.IsFalse(GcMath.AlmostSame(float.PositiveInfinity, float.NegativeInfinity));
            Assert.IsFalse(GcMath.AlmostSame(float.NaN, float.NaN));
        }
예제 #3
0
        public void GcMathAtan2()
        {
            for (var i = 0; i < 100; i++)
            {
                var x = UnityEngine.Random.value;
                var y = UnityEngine.Random.value;

                var a1 = GcMath.Atan2(new float2(x, y));
                var a2 = math.degrees(math.atan2(y, x));
                Assert.IsTrue(GcMath.AlmostSame(a1, a2), $"{a1:e} != {a2:e}");
            }
        }