| 1574 | namespace |
| 1575 | { |
| 1576 | void FindMinMaxDistance2s(Vec2f p, const Bounds2& bbox, float* minD2, float* maxD2) |
| 1577 | { |
| 1578 | const Vec2f& p0 = bbox.mMin; |
| 1579 | const Vec2f& p1 = bbox.mMax; |
| 1580 | |
| 1581 | // Find the nearest point to p inside the bbox |
| 1582 | // This can be a bbox vertex, a point on an edge or face, or p itself if it's inside the box |
| 1583 | float minX = Clamp(p.x, p0.x, p1.x); |
| 1584 | float minY = Clamp(p.y, p0.y, p1.y); |
| 1585 | |
| 1586 | // Find the farthest point from p inside the bbox |
| 1587 | // This is always a bbox vertex. |
| 1588 | Vec2f d0(abs(p - p0)); |
| 1589 | Vec2f d1(abs(p - p1)); |
| 1590 | |
| 1591 | float maxX = d0.x > d1.x ? p0.x : p1.x; // select the coordinate we're farthest from |
| 1592 | float maxY = d0.y > d1.y ? p0.y : p1.y; |
| 1593 | |
| 1594 | // return len2 |
| 1595 | *minD2 = sqr(p.x - minX) + sqr(p.y - minY); |
| 1596 | *maxD2 = sqr(p.x - maxX) + sqr(p.y - maxY); |
| 1597 | } |
| 1598 | |
| 1599 | void FindMinMaxDistance2s(Vec2f p, const Spline2& spline, float* minD2, float* maxD2) |
| 1600 | { |
no test coverage detected