From eb5dea3d035c61327543d7ab527d897ef3768570 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Nov 2023 14:21:14 +0000 Subject: Fix and split linesCross Previous tested they crossed in a specific direction, which is wrong but useful. Adds linesCrossLtR for this use case. --- game/geoData.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/game/geoData.cpp b/game/geoData.cpp index f9c11bf..78f753f 100644 --- a/game/geoData.cpp +++ b/game/geoData.cpp @@ -128,12 +128,23 @@ namespace { [[nodiscard]] constexpr inline bool linesCross(const glm::vec2 a1, const glm::vec2 a2, const glm::vec2 b1, const glm::vec2 b2) + { + return (pointLeftOfLine(a2, b1, b2) == pointLeftOfLine(a1, b2, b1)) + && (pointLeftOfLine(b1, a1, a2) == pointLeftOfLine(b2, a2, a1)); + } + + static_assert(linesCross({1, 1}, {2, 2}, {1, 2}, {2, 1})); + static_assert(linesCross({2, 2}, {1, 1}, {1, 2}, {2, 1})); + + [[nodiscard]] constexpr inline bool + linesCrossLtR(const glm::vec2 a1, const glm::vec2 a2, const glm::vec2 b1, const glm::vec2 b2) { return pointLeftOfLine(a2, b1, b2) && pointLeftOfLine(a1, b2, b1) && pointLeftOfLine(b1, a1, a2) && pointLeftOfLine(b2, a2, a1); } - static_assert(linesCross({1, 1}, {2, 2}, {1, 2}, {2, 1})); + static_assert(linesCrossLtR({1, 1}, {2, 2}, {1, 2}, {2, 1})); + static_assert(!linesCrossLtR({2, 2}, {1, 1}, {1, 2}, {2, 1})); } OpenMesh::FaceHandle @@ -208,7 +219,7 @@ GeoData::walkUntil(const PointFace & from, const glm::vec2 to, const std::functi if (f.is_valid() && f != previousFace) { const auto e1 = point(to_vertex_handle(*next)); const auto e2 = point(to_vertex_handle(opposite_halfedge_handle(*next))); - if (linesCross(from.point, to, e1, e2)) { + if (linesCrossLtR(from.point, to, e1, e2)) { previousFace = f; break; } -- cgit v1.2.3