summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 14:21:14 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-05 14:21:14 +0000
commiteb5dea3d035c61327543d7ab527d897ef3768570 (patch)
tree15add79eb14e68c895729487d24583bd4f2b1b0a /game
parentAdd methods to walk the boundary of the terrain mesh (diff)
downloadilt-eb5dea3d035c61327543d7ab527d897ef3768570.tar.bz2
ilt-eb5dea3d035c61327543d7ab527d897ef3768570.tar.xz
ilt-eb5dea3d035c61327543d7ab527d897ef3768570.zip
Fix and split linesCross
Previous tested they crossed in a specific direction, which is wrong but useful. Adds linesCrossLtR for this use case.
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp15
1 files 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
@@ -129,11 +129,22 @@ 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;
}