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/maths.h | |
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/maths.h')
-rw-r--r-- | lib/maths.h | 28 |
1 files changed, 9 insertions, 19 deletions
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 |