Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            for (var i = 0; i < 100; i++)
            {
                var num = i / 10f;

                var a = MathF.Sqrt(num);
                var b = MathHelpres.FastSqrt(num);

                Console.WriteLine($"{num}: {a} vs {b}");
            }

            for (var i = 0; i < 100; i++)
            {
                var num = i / 10.0;

                var a = Math.Sqrt(num);
                var b = MathHelpres.FastSqrt(num);

                Console.WriteLine($"{num}: {a} vs {b}");
            }

            //BenchmarkRunner.Run<Md5_Sha256>();
            BenchmarkRunner.Run <Sqrt_FastSqrt>();

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public override bool GetIntersection(Ray ray, double maxDistance, out Hit hit, out double distance)
        {
            hit = new Hit();

            var delta = ray.Origin - Position;

            var a = Dot(ray.Direction, ray.Direction);
            var b = 2 * Dot(ray.Direction, delta);
            var c = Dot(delta, delta) - Radius * Radius;

            double dt = b * b - 4 * a * c;

            if (dt < 0)
            {
                distance = 0;
                return(false);
            }
            else
            {
                double D = (-b - MathHelpres.FastSqrt(dt)) / (a * 2);
                if (D < 0)
                {
                    distance = 0;
                    return(false);
                }

                var position = ray.Origin + ray.Direction * (float)D;
                var dist     = Distance(position, ray.Origin);

                if (dist > maxDistance)
                {
                    distance = dist;
                    return(false);
                }

                hit.Position  = position;
                hit.Normal    = CalcNormal(hit.Position);
                hit.HitObject = this;
                distance      = dist;

                return(hit.IsHitting);
            }
        }
Ejemplo n.º 3
0
 public double FastSqrt64() => MathHelpres.FastSqrt(_double);
Ejemplo n.º 4
0
 public float FastSqrt32() => MathHelpres.FastSqrt(_single);