diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-12-15 14:38:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-12-15 14:38:00 +0000 |
commit | 39985f36e807126b2c7b9ec6096bda3922903a54 (patch) | |
tree | 6f7f69bccb02ac49b722c8b0981b08e928ea2678 /lib | |
parent | vector difference works with floating point (diff) | |
download | ilt-39985f36e807126b2c7b9ec6096bda3922903a54.tar.bz2 ilt-39985f36e807126b2c7b9ec6096bda3922903a54.tar.xz ilt-39985f36e807126b2c7b9ec6096bda3922903a54.zip |
2D triangle area support
Diffstat (limited to 'lib')
-rw-r--r-- | lib/triangle.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/triangle.h b/lib/triangle.h index 812bfab..5787094 100644 --- a/lib/triangle.h +++ b/lib/triangle.h @@ -31,6 +31,13 @@ struct Triangle : public glm::vec<3, glm::vec<Dim, T, Q>> { return glm::length(crossProduct(sideDifference(1), sideDifference(2))) / T {2}; } + [[nodiscard]] constexpr auto + area() const + requires(Dim == 2) + { + return std::abs((sideDifference(1).x * sideDifference(2).y) - (sideDifference(2).x * sideDifference(1).y)) / 2; + } + [[nodiscard]] constexpr Normal3D normal() const requires(Dim == 3) |