diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-02-09 15:18:35 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2025-02-09 15:18:35 +0000 |
commit | ecbb621171af0f20751bbc590453d00a7bd38320 (patch) | |
tree | 69717a9eb7fc452d2d95b977d6ff413258e7dcb4 /lib/triangle.h | |
parent | Initial commit setting terrain during network construction (diff) | |
download | ilt-ecbb621171af0f20751bbc590453d00a7bd38320.tar.bz2 ilt-ecbb621171af0f20751bbc590453d00a7bd38320.tar.xz ilt-ecbb621171af0f20751bbc590453d00a7bd38320.zip |
Move lots of geoData helpers into lib
Diffstat (limited to 'lib/triangle.h')
-rw-r--r-- | lib/triangle.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/triangle.h b/lib/triangle.h index e430653..abd697c 100644 --- a/lib/triangle.h +++ b/lib/triangle.h @@ -65,6 +65,12 @@ struct Triangle : public glm::vec<3, glm::vec<Dim, T, Q>> { } [[nodiscard]] constexpr auto + calcSideDifference(glm::length_t side) const + { + return calcDifference(p(side), p(0)); + } + + [[nodiscard]] constexpr auto angle(glm::length_t corner) const { return Arc {P(corner), P(corner + 2), P(corner + 1)}.length(); @@ -126,4 +132,25 @@ struct Triangle : public glm::vec<3, glm::vec<Dim, T, Q>> { { return begin() + 3; } + + [[nodiscard]] + constexpr auto + positionOnPlane(const glm::vec<2, T, Q> coord2d) const + requires(Dim == 3) + { + const auto edgeCrossProduct = crossProduct(calcSideDifference(1), calcSideDifference(2)); + return coord2d + || static_cast<T>( + ((edgeCrossProduct.x * p(0).x) + (edgeCrossProduct.y * p(0).y) + (edgeCrossProduct.z * p(0).z) + - (edgeCrossProduct.x * coord2d.x) - (edgeCrossProduct.y * coord2d.y)) + / edgeCrossProduct.z); + } + + [[nodiscard]] + constexpr bool + containsPoint(const GlobalPosition2D coord) const + { + return pointLeftOfOrOnLine(coord, p(0), p(1)) && pointLeftOfOrOnLine(coord, p(1), p(2)) + && pointLeftOfOrOnLine(coord, p(2), p(0)); + } }; |