Ejemplo n.º 1
0
        public static Float2 Rotate(this Float2 v, float radians)
        {
            var ca = MathFast.Cos(radians);
            var sa = MathFast.Sin(radians);

            return(new Float2(ca * v.X - sa * v.Y, sa * v.X + ca * v.Y));
        }
Ejemplo n.º 2
0
        void SinTest()
        {
            Debug.Log(">>>>> sin tests >>>>>");
            const int T  = 10000;
            var       sw = new System.Diagnostics.Stopwatch();
            float     f;
            float     s = 1.345f;

            sw.Reset();
            sw.Start();
            for (int i = 0; i < T; i++)
            {
                f = Mathf.Sin(s);
            }
            sw.Stop();
            Debug.LogFormat("mathf.sin time on {0} iterations: {1}", T, sw.ElapsedTicks);

            sw.Reset();
            sw.Start();
            for (int i = 0; i < T; i++)
            {
                f = (float)System.Math.Sin(s);
            }
            sw.Stop();
            Debug.LogFormat("system.math.sin time on {0} iterations: {1}", T, sw.ElapsedTicks);

            // Warmup cache.
            f = MathFast.Sin(s);

            sw.Reset();
            sw.Start();
            for (int i = 0; i < T; i++)
            {
                f = MathFast.Sin(s);
            }
            sw.Stop();
            Debug.LogFormat("mathfast.sin time on {0} iterations: {1}", T, sw.ElapsedTicks);

            var rng = Service <Rng> .Get();

            for (int i = 0; i < 10; i++)
            {
                f = rng.GetFloat() * MathFast.PI_2;
                Debug.LogFormat("sin({0}) => {1} / {2}", f, Mathf.Sin(f), MathFast.Sin(f));
            }
        }