diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-02-24 00:10:27 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-02-24 00:10:27 +0000 |
commit | 80529930ea3bc874c8da22c66343745ff6fdd45b (patch) | |
tree | 6441b090f24cf33638c5257e6b9eea4f14929503 /lib | |
parent | Merge branch 'glcontainer-fix' (diff) | |
download | ilt-80529930ea3bc874c8da22c66343745ff6fdd45b.tar.bz2 ilt-80529930ea3bc874c8da22c66343745ff6fdd45b.tar.xz ilt-80529930ea3bc874c8da22c66343745ff6fdd45b.zip |
Simplify vector addition/subtraction with differnt types
Automatically applies correct rounding with float to int operations, adjusts test
expectations accordingly.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/maths.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h index a867c39..5886326 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -32,6 +32,34 @@ constexpr auto quarter_pi {half_pi / 2}; constexpr auto pi {glm::pi<float>()}; constexpr auto two_pi {glm::two_pi<float>()}; +template<glm::length_t D> +constexpr inline GlobalPosition<D> +operator+(const GlobalPosition<D> & g, const RelativePosition<D> & r) +{ + return g + GlobalPosition<D>(glm::round(r)); +} + +template<glm::length_t D> +constexpr inline GlobalPosition<D> +operator+(const GlobalPosition<D> & g, const CalcPosition<D> & r) +{ + return g + GlobalPosition<D>(r); +} + +template<glm::length_t D> +constexpr inline GlobalPosition<D> +operator-(const GlobalPosition<D> & g, const RelativePosition<D> & r) +{ + return g - GlobalPosition<D>(glm::round(r)); +} + +template<glm::length_t D> +constexpr inline GlobalPosition<D> +operator-(const GlobalPosition<D> & g, const CalcPosition<D> & r) +{ + return g - GlobalPosition<D>(r); +} + glm::mat4 flat_orientation(const Rotation3D & diff); // C++ wrapper for C's sincosf, but with references, not pointers |