From 754ec66b42da46e5ff15021774eaad9710e1508e Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 10 Jul 2020 12:19:08 +0100 Subject: [PATCH] Point: Fix incorrect type conversions in operator* and operator/ --- modules/juce_graphics/geometry/juce_Point.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/juce_graphics/geometry/juce_Point.h b/modules/juce_graphics/geometry/juce_Point.h index abc5dc4a7a..dc89cf767a 100644 --- a/modules/juce_graphics/geometry/juce_Point.h +++ b/modules/juce_graphics/geometry/juce_Point.h @@ -120,12 +120,22 @@ public: Point& operator/= (Point other) noexcept { *this = *this / other; return *this; } /** Returns a point whose coordinates are multiplied by a given scalar value. */ - template - constexpr Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) ((FloatType) x * multiplier), (ValueType) ((FloatType) y * multiplier)); } + template + constexpr Point operator* (OtherType multiplier) const noexcept + { + using CommonType = typename std::common_type::type; + return Point ((ValueType) ((CommonType) x * (CommonType) multiplier), + (ValueType) ((CommonType) y * (CommonType) multiplier)); + } /** Returns a point whose coordinates are divided by a given scalar value. */ - template - constexpr Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) ((FloatType) x / divisor), (ValueType) ((FloatType) y / divisor)); } + template + constexpr Point operator/ (OtherType divisor) const noexcept + { + using CommonType = typename std::common_type::type; + return Point ((ValueType) ((CommonType) x / (CommonType) divisor), + (ValueType) ((CommonType) y / (CommonType) divisor)); + } /** Multiplies the point's coordinates by a scalar value. */ template