From f9e6220bf8b17681cb2f395ab64851a72659a070 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 1 Dec 2024 16:56:14 +0000 Subject: Move GeoData::Triangle to global lib --- game/geoData.h | 89 ++++++---------------------------------------------------- 1 file changed, 8 insertions(+), 81 deletions(-) (limited to 'game') diff --git a/game/geoData.h b/game/geoData.h index dcc28e0..79924d3 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -4,6 +4,7 @@ #include "config/types.h" #include "ray.h" #include "surface.h" +#include "triangle.h" #include #include #include @@ -52,85 +53,7 @@ public: mutable FaceHandle _face {}; }; - template struct Triangle : public 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) - { - assert(std::distance(range.begin(), range.end()) == 3); - std::transform(range.begin(), range.end(), &base::operator[](0), [m](auto vh) { - return m->point(vh); - }); - } - - [[nodiscard]] Point - operator*(BaryPosition bari) const - { - return p(0) + (::difference(p(1), p(0)) * bari.x) + (::difference(p(2), p(0)) * 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) - { - return glm::length(crossProduct(::difference(p(1), p(0)), ::difference(p(2), p(0)))) / 2.F; - } - - [[nodiscard]] Normal3D - normal() const - requires(Dim == 3) - { - return crossProduct(::difference(p(1), p(0)), ::difference(p(2), p(0))); - } - - [[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 - [[nodiscard]] auto - angleAt(const GlobalPosition pos) const - requires(D <= Dim) - { - for (glm::length_t i {}; i < 3; ++i) { - if (GlobalPosition {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); - } - }; + template using Triangle = ::Triangle; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D) const; [[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const; @@ -178,9 +101,13 @@ public: protected: template [[nodiscard]] Triangle - triangle(FaceHandle f) const + triangle(FaceHandle face) const { - return {this, fv_range(f)}; + Triangle triangle; + std::ranges::transform(fv_range(face), triangle.begin(), [this](auto vertex) { + return point(vertex); + }); + return triangle; } [[nodiscard]] static bool triangleContainsPoint(const GlobalPosition2D, const Triangle<2> &); -- cgit v1.2.3