Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DistanceToBox(pt: TPoint; bx: TBox): Extended;
- var
- p: TPoint;
- begin
- if not ((pt.X >= bx.X1) and (pt.X <= bx.X2) and (pt.Y >= bx.Y1) and (pt.Y <= bx.Y2)) then
- begin
- p := Point(Max((bx.X1 - pt.X), (pt.X - bx.X2)), Max((bx.Y1 - pt.Y), (pt.Y - bx.Y2)));
- if (p.X < 0) then
- p.X := 0;
- if (p.Y < 0) then
- p.Y := 0;
- Result := Sqrt(Sqr(pt.X - p.X) + Sqr(pt.Y - p.Y));
- end else
- Result := 0.0;
- end;
Advertisement
Add Comment
Please, Sign In to add comment