summaryrefslogtreecommitdiff
path: root/lib/maths.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-01-13 01:45:43 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-01-21 20:58:55 +0000
commit1aba027462a861f2c1155672792dbbe555d7dc0a (patch)
treef406c86cc0c610c05da63fc508d8963f0cb61ba4 /lib/maths.h
parentAdd default Q = glm::defaultp to maths functions (diff)
downloadilt-1aba027462a861f2c1155672792dbbe555d7dc0a.tar.bz2
ilt-1aba027462a861f2c1155672792dbbe555d7dc0a.tar.xz
ilt-1aba027462a861f2c1155672792dbbe555d7dc0a.zip
Add distance helperterrain-for-networks
Works with integer positions, first template param allows forcing to N dimensions
Diffstat (limited to 'lib/maths.h')
-rw-r--r--lib/maths.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/maths.h b/lib/maths.h
index 17ca795..3d4f440 100644
--- a/lib/maths.h
+++ b/lib/maths.h
@@ -111,6 +111,13 @@ difference(const glm::vec<D, T, Q> & globalA, const glm::vec<D, T, Q> & globalB)
return globalA - globalB;
}
+template<glm::length_t D, Arithmetic T, glm::qualifier Q = glm::defaultp>
+constexpr auto
+distance(const glm::vec<D, T, Q> & pointA, const glm::vec<D, T, Q> & pointB)
+{
+ return glm::length(difference(pointA, pointB));
+}
+
glm::mat4 flat_orientation(const Rotation3D & diff);
namespace {
@@ -498,7 +505,7 @@ operator"" _degrees(long double degrees)
// Late implementations due to dependencies
template<typename T, glm::qualifier Q>
constexpr ArcSegment<T, Q>::ArcSegment(PointType centre, PointType ep0, PointType ep1) :
- Arc {centre, ep0, ep1}, centre {centre}, ep0 {ep0}, ep1 {ep1}, radius {glm::length(difference(centre, ep0))}
+ Arc {centre, ep0, ep1}, centre {centre}, ep0 {ep0}, ep1 {ep1}, radius {::distance(centre, ep0)}
{
}