private static DistancePointToLineSegment ( Vector2 point, Vector2 a, Vector2 b ) : float | ||
point | Vector2 | |
a | Vector2 | |
b | Vector2 | |
return | float |
private static float DistancePointToLineSegment(Vector2 point, Vector2 a, Vector2 b)
{
Vector2 vector = b - a;
float sqrMagnitude = vector.sqrMagnitude;
if (sqrMagnitude == 0f)
{
Vector2 vector2 = point - a;
return vector2.magnitude;
}
float num3 = Vector2.Dot(point - a, b - a) / sqrMagnitude;
if (num3 < 0f)
{
Vector2 vector3 = point - a;
return vector3.magnitude;
}
if (num3 > 1f)
{
Vector2 vector4 = point - b;
return vector4.magnitude;
}
Vector2 vector5 = a + ((Vector2) (num3 * (b - a)));
Vector2 vector6 = point - vector5;
return vector6.magnitude;
}
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); }