From 4571ce1b4cac2ab9bf2454ed06d0d787604d62fa Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 21 Mar 2024 20:23:44 +0000 Subject: Add helper constructors to Arc * Two angles, wraps logic ensuring b after a * Two vector directions * Centre and two endpoints, in at least 2 dimensions, uses .xy() --- lib/maths.cpp | 5 +++++ lib/maths.h | 28 +++++++++------------------- 2 files changed, 14 insertions(+), 19 deletions(-) (limited to 'lib') diff --git a/lib/maths.cpp b/lib/maths.cpp index bf17204..51e27fe 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -4,6 +4,11 @@ #include #include +Arc::Arc(const RelativePosition2D & dir0, const RelativePosition2D & dir1) : + Arc {vector_yaw(dir0), vector_yaw(dir1)} { } + +Arc::Arc(const Angle anga, const Angle angb) : pair {anga, (angb < anga) ? angb + two_pi : angb} { } + glm::mat4 flat_orientation(const Direction3D & diff) { diff --git a/lib/maths.h b/lib/maths.h index 20a397b..656fefd 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -8,11 +8,16 @@ #include #include -struct Arc : public std::pair { - using std::pair::pair; +struct Arc : public std::pair { + template + requires(Lc >= 2, Le >= 2) + Arc(const glm::vec & centre, const glm::vec & e0p, const glm::vec & e1p) : + Arc {RelativePosition2D {e0p.xy() - centre.xy()}, RelativePosition2D {e1p.xy() - centre.xy()}} + { + } - template - Arc(const glm::vec<3, T, Q> & centre3, const glm::vec<3, T, Q> & e0p, const glm::vec<3, T, Q> & e1p); + Arc(const RelativePosition2D & dir0, const RelativePosition2D & dir1); + Arc(const Angle angb, const Angle anga); auto operator[](bool i) const @@ -244,21 +249,6 @@ midpoint(const std::pair & v) return std::midpoint(v.first, v.second); } -template -Arc::Arc(const glm::vec<3, T, Q> & centre3, const glm::vec<3, T, Q> & e0p, const glm::vec<3, T, Q> & e1p) : - Arc([&]() -> Arc { - const auto diffa = e0p - centre3; - const auto diffb = e1p - centre3; - const auto anga = vector_yaw(diffa); - const auto angb = [&diffb, &anga]() { - const auto angb = vector_yaw(diffb); - return (angb < anga) ? angb + two_pi : angb; - }(); - return {anga, angb}; - }()) -{ -} - // Conversions template inline constexpr auto -- cgit v1.2.3