From eee7e7ae1e91e42561e1a2b5bec448f04c2b2298 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 24 Nov 2024 00:46:03 +0000 Subject: Add Triangle::centroid --- game/geoData.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 51bb28b..c28dd14 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -53,7 +53,8 @@ public: }; template struct Triangle : public glm::vec<3, glm::vec> { - using base = glm::vec<3, glm::vec>; + using Point = glm::vec; + using base = glm::vec<3, Point>; using base::base; template Triangle(const GeoData * m, Range range) @@ -64,12 +65,20 @@ public: }); } - [[nodiscard]] glm::vec + [[nodiscard]] Point operator*(BaryPosition bari) const { return p(0) + (difference(p(0), p(1)) * bari.x) + (difference(p(0), p(2)) * bari.y); } + [[nodiscard]] Point + centroid() const + { + return [this](std::integer_sequence) { + return Point {(p(0)[axis] + p(1)[axis] + p(2)[axis]) / 3 ...}; + }(std::make_integer_sequence()); + } + [[nodiscard]] auto area() const requires(Dim == 3) -- cgit v1.2.3