summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-02-12 23:25:00 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-02-12 23:25:00 +0000
commit68a23b27925142fed3b1e53b2f17ad2c90878e21 (patch)
treeb73ee9841244a82bcfffed5eb1f3e77dad494bcd /game
parentCreate flat GeoData as 10m squares instead of one big square (diff)
downloadilt-68a23b27925142fed3b1e53b2f17ad2c90878e21.tar.bz2
ilt-68a23b27925142fed3b1e53b2f17ad2c90878e21.tar.xz
ilt-68a23b27925142fed3b1e53b2f17ad2c90878e21.zip
Add helpers for testing for triangle overlap/containedness
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp16
-rw-r--r--game/geoData.h2
2 files changed, 18 insertions, 0 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index 49cf892..ae43f3f 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -359,3 +359,19 @@ GeoData::update_vertex_normals_only()
this->set_normal(vh, glm::normalize(n));
}
}
+
+bool
+GeoData::triangleOverlapsTriangle(const Triangle<2> & a, const Triangle<2> & b)
+{
+ return triangleContainsPoint(a.x, b) || triangleContainsPoint(a.y, b) || triangleContainsPoint(a.z, b)
+ || triangleContainsPoint(b.x, a) || triangleContainsPoint(b.y, a) || triangleContainsPoint(b.z, a)
+ || linesCross(a.x, a.y, b.x, b.y) || linesCross(a.x, a.y, b.y, b.z) || linesCross(a.x, a.y, b.z, b.x)
+ || linesCross(a.y, a.z, b.x, b.y) || linesCross(a.y, a.z, b.y, b.z) || linesCross(a.y, a.z, b.z, b.x)
+ || linesCross(a.z, a.x, b.x, b.y) || linesCross(a.z, a.x, b.y, b.z) || linesCross(a.z, a.x, b.z, b.x);
+}
+
+bool
+GeoData::triangleContainsTriangle(const Triangle<2> & a, const Triangle<2> & b)
+{
+ return triangleContainsPoint(a.x, b) && triangleContainsPoint(a.y, b) && triangleContainsPoint(a.z, b);
+}
diff --git a/game/geoData.h b/game/geoData.h
index e234bfe..2fd3aa5 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -103,6 +103,8 @@ protected:
[[nodiscard]] static bool triangleContainsPoint(const GlobalPosition2D, const Triangle<2> &);
[[nodiscard]] bool triangleContainsPoint(const GlobalPosition2D, FaceHandle) const;
+ [[nodiscard]] static bool triangleOverlapsTriangle(const Triangle<2> &, const Triangle<2> &);
+ [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &);
[[nodiscard]] HalfedgeHandle findBoundaryStart() const;
void update_vertex_normals_only();