diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-11-24 00:46:03 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-11-24 00:46:03 +0000 |
commit | eee7e7ae1e91e42561e1a2b5bec448f04c2b2298 (patch) | |
tree | 5daf587c8dcbf673c85d345a0b1839cba7f6fbc2 /game/geoData.h | |
parent | Pass setHeights options as a struct with defaults (diff) | |
download | ilt-eee7e7ae1e91e42561e1a2b5bec448f04c2b2298.tar.bz2 ilt-eee7e7ae1e91e42561e1a2b5bec448f04c2b2298.tar.xz ilt-eee7e7ae1e91e42561e1a2b5bec448f04c2b2298.zip |
Add Triangle::centroid
Diffstat (limited to 'game/geoData.h')
-rw-r--r-- | game/geoData.h | 13 |
1 files changed, 11 insertions, 2 deletions
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<glm::length_t Dim> struct Triangle : public glm::vec<3, glm::vec<Dim, GlobalDistance>> { - using base = glm::vec<3, glm::vec<Dim, GlobalDistance>>; + using Point = glm::vec<Dim, GlobalDistance>; + using base = glm::vec<3, Point>; using base::base; template<IterableCollection Range> Triangle(const GeoData * m, Range range) @@ -64,12 +65,20 @@ public: }); } - [[nodiscard]] glm::vec<Dim, GlobalDistance> + [[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]<glm::length_t... axis>(std::integer_sequence<glm::length_t, axis...>) { + return Point {(p(0)[axis] + p(1)[axis] + p(2)[axis]) / 3 ...}; + }(std::make_integer_sequence<glm::length_t, Dim>()); + } + [[nodiscard]] auto area() const requires(Dim == 3) |