diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-03-21 20:23:44 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-03-21 20:23:44 +0000 |
commit | 4571ce1b4cac2ab9bf2454ed06d0d787604d62fa (patch) | |
tree | 5120afcca84de35d0097cecae62d0b211518ed60 /lib | |
parent | Make arc_length a member function (diff) | |
download | ilt-4571ce1b4cac2ab9bf2454ed06d0d787604d62fa.tar.bz2 ilt-4571ce1b4cac2ab9bf2454ed06d0d787604d62fa.tar.xz ilt-4571ce1b4cac2ab9bf2454ed06d0d787604d62fa.zip |
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()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/maths.cpp | 5 | ||||
-rw-r--r-- | lib/maths.h | 28 |
2 files changed, 14 insertions, 19 deletions
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 <glm/gtx/rotate_vector.hpp> #include <glm/gtx/transform.hpp> +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 <stdexcept> #include <utility> -struct Arc : public std::pair<float, float> { - using std::pair<float, float>::pair; +struct Arc : public std::pair<Angle, Angle> { + template<glm::length_t Lc, glm::length_t Le, typename T, glm::qualifier Q> + requires(Lc >= 2, Le >= 2) + Arc(const glm::vec<Lc, T, Q> & centre, const glm::vec<Le, T, Q> & e0p, const glm::vec<Le, T, Q> & e1p) : + Arc {RelativePosition2D {e0p.xy() - centre.xy()}, RelativePosition2D {e1p.xy() - centre.xy()}} + { + } - template<typename T, glm::qualifier Q> - 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<T, T> & v) return std::midpoint(v.first, v.second); } -template<typename T, glm::qualifier Q> -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<typename T> inline constexpr auto |