diff options
author | Noel <noel.grandin@collabora.co.uk> | 2020-12-22 15:42:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-01-02 15:26:38 +0100 |
commit | 11e52fe2979b0947814a49b9c17ec373795cbf8e (patch) | |
tree | 48268579f052b7fdfcc2c334fffe8c91d29cb234 /include/tools | |
parent | 610ceb05025c9c7a9a34dddcb0dac506b8eab441 (diff) |
introduce Degree100 strong_int type
Change-Id: I78f837a1340be0ca5c49097f543a481b7b43a632
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108367
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/tools')
-rw-r--r-- | include/tools/degree.hxx | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/include/tools/degree.hxx b/include/tools/degree.hxx index 27bdffaa5de1..47dc7a8d98a7 100644 --- a/include/tools/degree.hxx +++ b/include/tools/degree.hxx @@ -10,6 +10,7 @@ #include <sal/types.h> #include <o3tl/strong_int.hxx> +#include <cstdlib> #include <math.h> /** tenths of a Degree, normally rotation */ @@ -18,10 +19,27 @@ typedef o3tl::strong_int<sal_Int16, struct Degree10Tag> Degree10; /** custom literal */ constexpr Degree10 operator""_deg10(unsigned long long n) { return Degree10{ n }; } +/** hundredths of a Degree, normally rotation */ +typedef o3tl::strong_int<sal_Int32, struct Degree100Tag> Degree100; + +// Android has trouble calling the correct overload of std::abs +#ifdef ANDROID +inline Degree100 abs(Degree100 x) { return Degree100(std::abs(static_cast<int>(x.get()))); } +#else +inline Degree100 abs(Degree100 x) { return Degree100(std::abs(x.get())); } +#endif + +/** custom literal */ +constexpr Degree100 operator""_deg100(unsigned long long n) { return Degree100{ n }; } + /** conversion functions */ -inline sal_Int32 toDegree100(Degree10 x) { return x.get() * 10; } -inline double toRadians(Degree10 x) { return x.get() * M_PI / 1800.0; } +inline Degree100 toDegree100(Degree10 x) { return Degree100(x.get() * 10); } +inline double toRadians(Degree10 x) { return x.get() * (M_PI / 1800.0); } inline double toDegrees(Degree10 x) { return x.get() / 10.0; } +inline Degree10 toDegree10(Degree100 x) { return Degree10((x.get() + 5) / 10); } +inline double toRadians(Degree100 x) { return x.get() * (M_PI / 18000.0); } +inline double toDegrees(Degree100 x) { return x.get() / 100.0; } + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |