/src/libreoffice/include/tools/degree.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | #pragma once |
10 | | |
11 | | #include <sal/config.h> |
12 | | |
13 | | #include <basegfx/numeric/ftools.hxx> |
14 | | #include <sal/types.h> |
15 | | #include <o3tl/strong_int.hxx> |
16 | | #include <o3tl/unit_conversion.hxx> |
17 | | #include <cstdlib> |
18 | | #include <numeric> |
19 | | |
20 | | template <int N> struct FractionTag; |
21 | | // 1/Nth fraction of a degree |
22 | | template <typename I, int N> using Degree = o3tl::strong_int<I, FractionTag<N>>; |
23 | | |
24 | | template <typename I, int N> char (&NofDegree(Degree<I, N>))[N]; // helper |
25 | | // Nof<DegreeN> gives compile-time constant N, needed in templates |
26 | | template <class D> constexpr int Nof = sizeof(NofDegree(std::declval<D>())); |
27 | | |
28 | | /** tenths of a Degree, normally rotation */ |
29 | | typedef Degree<sal_Int16, 10> Degree10; |
30 | | |
31 | | /** custom literal */ |
32 | 128M | constexpr Degree10 operator""_deg10(unsigned long long n) { return Degree10{ n }; } |
33 | | |
34 | | /** hundredths of a Degree, normally rotation */ |
35 | | typedef Degree<sal_Int32, 100> Degree100; |
36 | | |
37 | | // Android has trouble calling the correct overload of std::abs |
38 | | #ifdef ANDROID |
39 | | inline Degree100 abs(Degree100 x) { return Degree100(std::abs(static_cast<int>(x.get()))); } |
40 | | #else |
41 | 0 | inline Degree100 abs(Degree100 x) { return Degree100(std::abs(x.get())); } |
42 | | #endif |
43 | | |
44 | | /** custom literal */ |
45 | 11.4M | constexpr Degree100 operator""_deg100(unsigned long long n) { return Degree100{ n }; } |
46 | | |
47 | | /** conversion functions */ |
48 | | |
49 | | template <class To, typename IofFrom, int NofFrom> inline To to(Degree<IofFrom, NofFrom> x) |
50 | 20.2k | { |
51 | 20.2k | constexpr sal_Int64 m = Nof<To> / std::gcd(Nof<To>, NofFrom); |
52 | 20.2k | constexpr sal_Int64 d = NofFrom / std::gcd(Nof<To>, NofFrom); |
53 | 20.2k | return To{ o3tl::convert(x.get(), m, d) }; |
54 | 20.2k | } o3tl::strong_int<short, FractionTag<10> > to<o3tl::strong_int<short, FractionTag<10> >, int, 100>(o3tl::strong_int<int, FractionTag<100> >) Line | Count | Source | 50 | 20.2k | { | 51 | 20.2k | constexpr sal_Int64 m = Nof<To> / std::gcd(Nof<To>, NofFrom); | 52 | 20.2k | constexpr sal_Int64 d = NofFrom / std::gcd(Nof<To>, NofFrom); | 53 | 20.2k | return To{ o3tl::convert(x.get(), m, d) }; | 54 | 20.2k | } |
Unexecuted instantiation: o3tl::strong_int<int, FractionTag<100> > to<o3tl::strong_int<int, FractionTag<100> >, short, 10>(o3tl::strong_int<short, FractionTag<10> >) |
55 | | |
56 | 17.2M | template <class D> inline double toRadians(D x) { return basegfx::deg2rad<Nof<D>>(x.get()); }double toRadians<o3tl::strong_int<short, FractionTag<10> > >(o3tl::strong_int<short, FractionTag<10> >) Line | Count | Source | 56 | 16.9M | template <class D> inline double toRadians(D x) { return basegfx::deg2rad<Nof<D>>(x.get()); } |
double toRadians<o3tl::strong_int<int, FractionTag<100> > >(o3tl::strong_int<int, FractionTag<100> >) Line | Count | Source | 56 | 302k | template <class D> inline double toRadians(D x) { return basegfx::deg2rad<Nof<D>>(x.get()); } |
|
57 | 13.1k | template <class D> inline double toDegrees(D x) { return x.get() / static_cast<double>(Nof<D>); }Unexecuted instantiation: double toDegrees<o3tl::strong_int<short, FractionTag<10> > >(o3tl::strong_int<short, FractionTag<10> >) double toDegrees<o3tl::strong_int<int, FractionTag<100> > >(o3tl::strong_int<int, FractionTag<100> >) Line | Count | Source | 57 | 13.1k | template <class D> inline double toDegrees(D x) { return x.get() / static_cast<double>(Nof<D>); } |
|
58 | | |
59 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |