summaryrefslogtreecommitdiff
path: root/game/geoData.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-04-01 20:08:56 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-04-01 20:08:56 +0100
commitd384c5dc548cf6d6a0cce0db744fc3b168d7be96 (patch)
tree9a12744e28a2eb957c2f3c071fd72fc738e350c1 /game/geoData.h
parentReplace face 4-way split (diff)
downloadilt-d384c5dc548cf6d6a0cce0db744fc3b168d7be96.tar.bz2
ilt-d384c5dc548cf6d6a0cce0db744fc3b168d7be96.tar.xz
ilt-d384c5dc548cf6d6a0cce0db744fc3b168d7be96.zip
Add lots of simple triangle property helpers
Diffstat (limited to 'game/geoData.h')
-rw-r--r--game/geoData.h70
1 files changed, 68 insertions, 2 deletions
diff --git a/game/geoData.h b/game/geoData.h
index 6dacd9a..03bc159 100644
--- a/game/geoData.h
+++ b/game/geoData.h
@@ -61,11 +61,69 @@ public:
});
}
+ [[nodiscard]]
glm::vec<Dim, GlobalDistance>
operator*(BaryPosition bari) const
{
- const auto & t {*this};
- return t[0] + (RelativePosition<Dim>(t[1] - t[0]) * bari.x) + (RelativePosition<Dim>(t[2] - t[0]) * bari.y);
+ return p(0) + (difference(p(0), p(1)) * bari.x) + (difference(p(0), p(2)) * bari.y);
+ }
+
+ [[nodiscard]]
+ auto
+ area() const
+ requires(Dim == 3)
+ {
+ return glm::length(crossProduct(difference(p(0), p(1)), difference(p(0), p(2)))) / 2.F;
+ }
+
+ [[nodiscard]]
+ Normal3D
+ normal() const
+ requires(Dim == 3)
+ {
+ return crossProduct(difference(p(0), p(1)), difference(p(0), p(2)));
+ }
+
+ [[nodiscard]]
+ Normal3D
+ nnormal() const
+ requires(Dim == 3)
+ {
+ return glm::normalize(normal());
+ }
+
+ [[nodiscard]]
+ auto
+ angle(glm::length_t c) const
+ {
+ return Arc {P(c), P(c + 2), P(c + 1)}.length();
+ }
+
+ template<glm::length_t D = Dim>
+ [[nodiscard]]
+ auto
+ angleAt(const GlobalPosition<D> pos) const
+ requires(D <= Dim)
+ {
+ for (glm::length_t i {}; i < 3; ++i) {
+ if (GlobalPosition<D> {p(i)} == pos) {
+ return angle(i);
+ }
+ }
+ return 0.F;
+ }
+
+ [[nodiscard]]
+ inline auto
+ p(const glm::length_t i) const
+ {
+ return base::operator[](i);
+ }
+
+ [[nodiscard]] inline auto
+ P(const glm::length_t i) const
+ {
+ return base::operator[](i % 3);
}
};
@@ -110,6 +168,14 @@ protected:
[[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &);
[[nodiscard]] HalfedgeHandle findBoundaryStart() const;
[[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const;
+
+ template<glm::length_t D>
+ [[nodiscard]] static RelativePosition<D>
+ difference(const GlobalPosition<D> a, const GlobalPosition<D> b)
+ {
+ return b - a;
+ }
+
[[nodiscard]] RelativeDistance length(const HalfedgeHandle) const;
[[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const;