ClosestPoint returns a point in the rectangle closest to the given point.
(p Point)
| 486 | |
| 487 | // ClosestPoint returns a point in the rectangle closest to the given point. |
| 488 | func (r Rect) ClosestPoint(p Point) Point { |
| 489 | if r.X0 <= p.X && p.X <= r.X1 { |
| 490 | if r.Y0 <= p.Y && p.Y <= r.Y1 { |
| 491 | // inside |
| 492 | return p |
| 493 | } else if r.Y1 < p.Y { |
| 494 | return Point{p.X, r.Y1} |
| 495 | } else { |
| 496 | return Point{p.X, r.Y0} |
| 497 | } |
| 498 | } else if r.X1 < p.X { |
| 499 | if r.Y0 <= p.Y && p.Y <= r.Y1 { |
| 500 | return Point{r.X1, p.Y} |
| 501 | } else if r.Y1 < p.Y { |
| 502 | return Point{r.X1, r.Y1} |
| 503 | } else { |
| 504 | return Point{r.X1, r.Y0} |
| 505 | } |
| 506 | } else { |
| 507 | if r.Y0 <= p.Y && p.Y <= r.Y1 { |
| 508 | return Point{r.X0, p.Y} |
| 509 | } else if r.Y1 < p.Y { |
| 510 | return Point{r.X0, r.Y1} |
| 511 | } else { |
| 512 | return Point{r.X0, r.Y0} |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | // DistanceToPoint returns the distance between the rectangle and a point. |
| 518 | func (r Rect) DistanceToPoint(p Point) float64 { |
nothing calls this directly
no outgoing calls
no test coverage detected