TerrainDisplay.Collision.Intersection.SqDistPointAABB C# (CSharp) Method

SqDistPointAABB() public static method

public static SqDistPointAABB ( System.Vector3 p, BoundingBox b ) : float
p System.Vector3
b BoundingBox
return float
        public static float SqDistPointAABB(Vector3 p, BoundingBox b)
        {
            var num = 0f;
            var x = p.X;
            if (x < b.Min.X)
            {
                num += (b.Min.X - x) * (b.Min.X - x);
            }
            if (x > b.Max.X)
            {
                num += (x - b.Max.X) * (x - b.Max.X);
            }
            x = p.Y;
            if (x < b.Min.Y)
            {
                num += (b.Min.Y - x) * (b.Min.Y - x);
            }
            if (x > b.Max.Y)
            {
                num += (x - b.Max.Y) * (x - b.Max.Y);
            }
            x = p.Z;
            if (x < b.Min.Z)
            {
                num += (b.Min.Z - x) * (b.Min.Z - x);
            }
            if (x > b.Max.Z)
            {
                num += (x - b.Max.Z) * (x - b.Max.Z);
            }
            return num;
        }