OpenSim.Region.ScriptEngine.Shared.Api.LSL_Api.GroundIntersection2 C# (CSharp) Method

GroundIntersection2() private method

private GroundIntersection2 ( System.Vector3 rayStart, System.Vector3 rayEnd ) : ContactResult?
rayStart System.Vector3
rayEnd System.Vector3
return ContactResult?
        private ContactResult? GroundIntersection2(Vector3 rayStart, Vector3 rayEnd)
        {
            // get work copies
            float sx = rayStart.X;
            float ex = rayEnd.X;  
            float sy = rayStart.Y;
            float ey = rayEnd.Y;

            float dx = ex - sx;
            float dy = ey - sy;

            // region size info
            float rsx =  World.RegionInfo.RegionSizeX;
 
            float tmp;

            // region bounds
            if(sx < 0)
            {
                if(ex < 0) // totally outside
                    return null;
                if(dx <= 0) // out and going away
                    return null;
                else if(ex >= rsx)
                    ex = rsx - 0.001f;
                tmp = -sx / dx;
                sy += dy * dx;
                sx = 0;
            }
            else if(sx >= rsx) 
            {
                if(ex >= rsx)  // totally outside
                    return null;
                if(dx >= 0) // out and going away
                    return null;
                else if(ex < 0)
                    ex = 0;
                tmp = (rsx - sx) / dx;
                sy += dy * dx;
                sx = rsx - 0.001f;
            }

            float rsy =  World.RegionInfo.RegionSizeY;
            if(sy < 0)
            {
                if(dy <= 0) // out and going away
                    return null;
                else if(ey >= rsy)
                    ey = rsy - 0.001f;
                tmp = -sy / dy;
                sx += dy * dx;
                sy = 0;
            }
            else if(sy >= rsy) 
            {
                if(dy >= 0) // out and going away
                    return null;
                else if(ey < 0)
                    ey = 0;
                tmp = (rsy - sy) / dy;
                sx += dy * dx;
                sy = rsy - 0.001f;
            }

            if(sx < 0 || sx >= rsx)
                return null;

            float sz = rayStart.Z;
            float ez = rayEnd.Z;
            float dz = ez - sz;

            float dist = dx * dx + dy * dy + dz * dz;
            if(dist < 0.001)
                return null;
            dist = (float)Math.Sqrt(dist);
            tmp = 1.0f / dist;
            Vector3 rayn = new Vector3(dx * tmp, dy * tmp, dz * tmp);

            ContactResult? result = null;



            return result;
        }
LSL_Api