|
5 | 5 | #define GEOMETRY_POINT_MATRIX_H |
6 | 6 |
|
7 | 7 | #include <array> |
8 | | -#include <numbers> |
9 | 8 |
|
10 | 9 | #include "geometry/Point2LL.h" |
11 | 10 |
|
12 | 11 |
|
13 | 12 | namespace cura |
14 | 13 | { |
15 | 14 |
|
| 15 | +class AngleDegrees; |
| 16 | +class AngleRadians; |
| 17 | + |
16 | 18 | class PointMatrix |
17 | 19 | { |
18 | 20 | public: |
19 | 21 | std::array<double, 4> matrix{ 1, 0, 0, 1 }; |
20 | 22 |
|
21 | 23 | PointMatrix() noexcept = default; |
22 | 24 |
|
23 | | - explicit PointMatrix(double rotation) |
24 | | - { |
25 | | - rotation = rotation / 180 * std::numbers::pi; |
26 | | - matrix.at(0) = std::cos(rotation); |
27 | | - matrix.at(1) = -std::sin(rotation); |
28 | | - matrix.at(2) = -matrix.at(1); |
29 | | - matrix.at(3) = matrix.at(0); |
30 | | - } |
31 | | - |
32 | | - explicit PointMatrix(const Point2LL& p) |
33 | | - { |
34 | | - matrix.at(0) = static_cast<double>(p.X); |
35 | | - matrix.at(1) = static_cast<double>(p.Y); |
36 | | - double f = std::sqrt((matrix.at(0) * matrix.at(0)) + (matrix.at(1) * matrix.at(1))); |
37 | | - matrix.at(0) /= f; |
38 | | - matrix.at(1) /= f; |
39 | | - matrix.at(2) = -matrix.at(1); |
40 | | - matrix.at(3) = matrix.at(0); |
41 | | - } |
42 | | - |
43 | | - static PointMatrix scale(double s) |
44 | | - { |
45 | | - PointMatrix ret; |
46 | | - ret.matrix.at(0) = s; |
47 | | - ret.matrix.at(3) = s; |
48 | | - return ret; |
49 | | - } |
50 | | - |
51 | | - [[nodiscard]] Point2LL apply(const Point2LL& p) const |
52 | | - { |
53 | | - const auto x = static_cast<double>(p.X); |
54 | | - const auto y = static_cast<double>(p.Y); |
55 | | - return { std::llrint(x * matrix.at(0) + y * matrix.at(1)), std::llrint(x * matrix.at(2) + y * matrix.at(3)) }; |
56 | | - } |
| 25 | + explicit PointMatrix(double rotation); |
| 26 | + |
| 27 | + explicit PointMatrix(const AngleDegrees& rotation); |
| 28 | + |
| 29 | + explicit PointMatrix(const AngleRadians& rotation); |
| 30 | + |
| 31 | + explicit PointMatrix(const Point2LL& p); |
| 32 | + |
| 33 | + static PointMatrix scale(double s); |
| 34 | + |
| 35 | + [[nodiscard]] Point2LL apply(const Point2LL& p) const; |
57 | 36 |
|
58 | 37 | /*! |
59 | 38 | * \warning only works on a rotation matrix! Output is incorrect for other types of matrix |
60 | 39 | */ |
61 | | - [[nodiscard]] Point2LL unapply(const Point2LL& p) const |
62 | | - { |
63 | | - const auto x = static_cast<double>(p.X); |
64 | | - const auto y = static_cast<double>(p.Y); |
65 | | - return { std::llrint(x * matrix.at(0) + y * matrix.at(2)), std::llrint(x * matrix.at(1) + y * matrix.at(3)) }; |
66 | | - } |
67 | | - |
68 | | - [[nodiscard]] PointMatrix inverse() const |
69 | | - { |
70 | | - PointMatrix ret; |
71 | | - double det = matrix.at(0) * matrix.at(3) - matrix.at(1) * matrix.at(2); |
72 | | - ret.matrix.at(0) = matrix.at(3) / det; |
73 | | - ret.matrix.at(1) = -matrix.at(1) / det; |
74 | | - ret.matrix.at(2) = -matrix.at(2) / det; |
75 | | - ret.matrix.at(3) = matrix.at(0) / det; |
76 | | - return ret; |
77 | | - } |
| 40 | + [[nodiscard]] Point2LL unapply(const Point2LL& p) const; |
| 41 | + |
| 42 | + [[nodiscard]] PointMatrix inverse() const; |
78 | 43 | }; |
79 | 44 |
|
80 | 45 | } // namespace cura |
|
0 commit comments