1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Point: Fix incorrect type conversions in operator* and operator/

This commit is contained in:
reuk 2020-07-10 12:19:08 +01:00
parent 03bdbb5364
commit 754ec66b42
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11

View file

@ -120,12 +120,22 @@ public:
Point& operator/= (Point<OtherType> other) noexcept { *this = *this / other; return *this; }
/** Returns a point whose coordinates are multiplied by a given scalar value. */
template <typename FloatType>
constexpr Point operator* (FloatType multiplier) const noexcept { return Point ((ValueType) ((FloatType) x * multiplier), (ValueType) ((FloatType) y * multiplier)); }
template <typename OtherType>
constexpr Point operator* (OtherType multiplier) const noexcept
{
using CommonType = typename std::common_type<ValueType, OtherType>::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 <typename FloatType>
constexpr Point operator/ (FloatType divisor) const noexcept { return Point ((ValueType) ((FloatType) x / divisor), (ValueType) ((FloatType) y / divisor)); }
template <typename OtherType>
constexpr Point operator/ (OtherType divisor) const noexcept
{
using CommonType = typename std::common_type<ValueType, OtherType>::type;
return Point ((ValueType) ((CommonType) x / (CommonType) divisor),
(ValueType) ((CommonType) y / (CommonType) divisor));
}
/** Multiplies the point's coordinates by a scalar value. */
template <typename FloatType>