| 28 | } |
| 29 | |
| 30 | double |
| 31 | Rectangle::computeSignedDistance(const glm::dvec2& position) const noexcept { |
| 32 | const glm::dvec2 bottomLeftDistance = |
| 33 | glm::dvec2(minimumX, minimumY) - position; |
| 34 | const glm::dvec2 topRightDistance = position - glm::dvec2(maximumX, maximumY); |
| 35 | const glm::dvec2 maxDistance = glm::max(bottomLeftDistance, topRightDistance); |
| 36 | |
| 37 | if (maxDistance.x <= 0.0 && maxDistance.y <= 0.0) { |
| 38 | // Inside, report closest edge. |
| 39 | return glm::max(maxDistance.x, maxDistance.y); |
| 40 | } |
| 41 | if (maxDistance.x > 0.0 && maxDistance.y > 0.0) { |
| 42 | // Outside in both directions, closest point is a corner |
| 43 | return glm::length(maxDistance); |
| 44 | } |
| 45 | // Outside in one direction, report the distance in that direction. |
| 46 | return glm::max(maxDistance.x, maxDistance.y); |
| 47 | } |
| 48 | |
| 49 | std::optional<Rectangle> |
| 50 | Rectangle::computeIntersection(const Rectangle& other) const noexcept { |
no outgoing calls
no test coverage detected