MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / computeSignedDistance

Method computeSignedDistance

CesiumGeometry/src/Rectangle.cpp:30–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30double
31Rectangle::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
49std::optional<Rectangle>
50Rectangle::computeIntersection(const Rectangle& other) const noexcept {

Calls

no outgoing calls

Tested by

no test coverage detected