From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- include/tools/degree.hxx | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/tools/degree.hxx (limited to 'include/tools/degree.hxx') diff --git a/include/tools/degree.hxx b/include/tools/degree.hxx new file mode 100644 index 000000000..560f9b115 --- /dev/null +++ b/include/tools/degree.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#pragma once + +#include + +#include +#include +#include +#include +#include +#include +#include + +template struct FractionTag; +// 1/Nth fraction of a degree +template using Degree = o3tl::strong_int>; + +template char (&NofDegree(Degree))[N]; // helper +// Nof gives compile-time constant N, needed in templates +template constexpr int Nof = sizeof(NofDegree(std::declval())); + +/** tenths of a Degree, normally rotation */ +typedef Degree Degree10; + +/** custom literal */ +constexpr Degree10 operator""_deg10(unsigned long long n) { return Degree10{ n }; } + +/** hundredths of a Degree, normally rotation */ +typedef Degree Degree100; + +// Android has trouble calling the correct overload of std::abs +#ifdef ANDROID +inline Degree100 abs(Degree100 x) { return Degree100(std::abs(static_cast(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 */ + +template inline To to(Degree x) +{ + constexpr sal_Int64 m = Nof / std::gcd(Nof, NofFrom); + constexpr sal_Int64 d = NofFrom / std::gcd(Nof, NofFrom); + return To{ o3tl::convert(x.get(), m, d) }; +} + +template inline double toRadians(D x) { return basegfx::deg2rad>(x.get()); } +template inline double toDegrees(D x) { return x.get() / static_cast(Nof); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3