From 80529930ea3bc874c8da22c66343745ff6fdd45b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 24 Feb 2024 00:10:27 +0000 Subject: Simplify vector addition/subtraction with differnt types Automatically applies correct rounding with float to int operations, adjusts test expectations accordingly. --- lib/maths.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib/maths.h') 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()}; constexpr auto two_pi {glm::two_pi()}; +template +constexpr inline GlobalPosition +operator+(const GlobalPosition & g, const RelativePosition & r) +{ + return g + GlobalPosition(glm::round(r)); +} + +template +constexpr inline GlobalPosition +operator+(const GlobalPosition & g, const CalcPosition & r) +{ + return g + GlobalPosition(r); +} + +template +constexpr inline GlobalPosition +operator-(const GlobalPosition & g, const RelativePosition & r) +{ + return g - GlobalPosition(glm::round(r)); +} + +template +constexpr inline GlobalPosition +operator-(const GlobalPosition & g, const CalcPosition & r) +{ + return g - GlobalPosition(r); +} + glm::mat4 flat_orientation(const Rotation3D & diff); // C++ wrapper for C's sincosf, but with references, not pointers -- cgit v1.2.3