DistancePointToLineSegment() private static method

private static DistancePointToLineSegment ( Vector2 point, Vector2 a, Vector2 b ) : float
point Vector2
a Vector2
b Vector2
return float
Exemplo n.º 1
0
        private static float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos)
        {
            bool flag = false;
            int  num  = 4;

            for (int i = 0; i < 5; i++)
            {
                Vector3 vector  = screenPoints[i % 4];
                Vector3 vector2 = screenPoints[num % 4];
                if (vector.y > mousePos.y != vector2.y > mousePos.y && mousePos.x < (vector2.x - vector.x) * (mousePos.y - vector.y) / (vector2.y - vector.y) + vector.x)
                {
                    flag = !flag;
                }
                num = i;
            }
            if (!flag)
            {
                float num2 = -1f;
                for (int j = 0; j < 4; j++)
                {
                    Vector3 v    = screenPoints[j];
                    Vector3 v2   = screenPoints[(j + 1) % 4];
                    float   num3 = RectTool.DistancePointToLineSegment(mousePos, v, v2);
                    if (num3 < num2 || num2 < 0f)
                    {
                        num2 = num3;
                    }
                }
                return(num2);
            }
            return(0f);
        }
Exemplo n.º 2
0
        private static float DistanceToRectangle(Vector2[] screenPoints, Vector2 mousePos)
        {
            bool flag = false;
            int  num1 = 4;

            for (int index = 0; index < 5; ++index)
            {
                Vector3 screenPoint1 = (Vector3)screenPoints[index % 4];
                Vector3 screenPoint2 = (Vector3)screenPoints[num1 % 4];
                if ((double)screenPoint1.y > (double)mousePos.y != (double)screenPoint2.y > (double)mousePos.y && (double)mousePos.x < ((double)screenPoint2.x - (double)screenPoint1.x) * ((double)mousePos.y - (double)screenPoint1.y) / ((double)screenPoint2.y - (double)screenPoint1.y) + (double)screenPoint1.x)
                {
                    flag = !flag;
                }
                num1 = index;
            }
            if (flag)
            {
                return(0.0f);
            }
            float num2 = -1f;

            for (int index = 0; index < 4; ++index)
            {
                Vector3 screenPoint1 = (Vector3)screenPoints[index];
                Vector3 screenPoint2 = (Vector3)screenPoints[(index + 1) % 4];
                float   lineSegment  = RectTool.DistancePointToLineSegment(mousePos, (Vector2)screenPoint1, (Vector2)screenPoint2);
                if ((double)lineSegment < (double)num2 || (double)num2 < 0.0)
                {
                    num2 = lineSegment;
                }
            }
            return(num2);
        }