diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:37 +0000 |
commit | a90a5cba08fdf6c0ceb95101c275108a152a3aed (patch) | |
tree | 532507288f3defd7f4dcf1af49698bcb76034855 /gfx/2d/BasePoint.h | |
parent | Adding debian version 126.0.1-1. (diff) | |
download | firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.tar.xz firefox-a90a5cba08fdf6c0ceb95101c275108a152a3aed.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/2d/BasePoint.h')
-rw-r--r-- | gfx/2d/BasePoint.h | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/gfx/2d/BasePoint.h b/gfx/2d/BasePoint.h index 7f5dd7e1e3..b7b0adbabd 100644 --- a/gfx/2d/BasePoint.h +++ b/gfx/2d/BasePoint.h @@ -12,10 +12,37 @@ #include <type_traits> #include "mozilla/Attributes.h" #include "mozilla/FloatingPoint.h" +#include "Coord.h" namespace mozilla { namespace gfx { +template <class T, typename EnableT = void> +struct FloatType; + +template <typename T> +struct FloatType<T, typename std::enable_if_t<std::is_integral_v<T>>> { + using type = float; +}; + +template <typename T> +struct FloatType<T, typename std::enable_if_t<std::is_floating_point_v<T>>> { + using type = T; +}; + +template <typename Units, typename Rep> +struct FloatType<IntCoordTyped<Units, Rep>> { + using type = CoordTyped<Units, float>; +}; + +template <typename Units, typename Rep> +struct FloatType<CoordTyped<Units, Rep>> { + using type = CoordTyped<Units, Rep>; +}; + +template <typename T> +using FloatType_t = typename FloatType<T>::type; + /** * Do not use this class directly. Subclass it, pass that subclass as the * Sub parameter, and only use that subclass. This allows methods to safely @@ -82,9 +109,8 @@ struct BasePoint { return x.value * aPoint.x.value + y.value * aPoint.y.value; } - // FIXME: Maybe Length() should return a float Coord event for integer Points? - Coord Length() const { - return static_cast<decltype(x.value)>(hypot(x.value, y.value)); + FloatType_t<Coord> Length() const { + return FloatType_t<Coord>(hypot(x.value, y.value)); } T LengthSquare() const { return x.value * x.value + y.value * y.value; } |