1 | // [Blend2D] |
2 | // 2D Vector Graphics Powered by a JIT Compiler. |
3 | // |
4 | // [License] |
5 | // Zlib - See LICENSE.md file in the package. |
6 | |
7 | #ifndef BLEND2D_BLMATRIX_P_H |
8 | #define BLEND2D_BLMATRIX_P_H |
9 | |
10 | #include "./blapi-internal_p.h" |
11 | #include "./blmath_p.h" |
12 | #include "./blmatrix.h" |
13 | |
14 | //! \cond INTERNAL |
15 | //! \addtogroup blend2d_internal |
16 | //! \{ |
17 | |
18 | // ============================================================================ |
19 | // [BLMatrix2D - Globals] |
20 | // ============================================================================ |
21 | |
22 | BL_HIDDEN extern const BLMatrix2D blMatrix2DIdentity; |
23 | |
24 | // ============================================================================ |
25 | // [BLMatrix2D - Utilities] |
26 | // ============================================================================ |
27 | |
28 | //! Returns a matrix rotation angle. |
29 | static BL_INLINE double blMatrix2DRotationAngle(const BLMatrix2D& m) noexcept { |
30 | return blAtan2(m.m00, m.m01); |
31 | } |
32 | |
33 | //! Returns an average scaling (by X and Y). |
34 | //! |
35 | //! Basically used to calculate the approximation scale when decomposing |
36 | //! curves into line segments. |
37 | static BL_INLINE double blMatrix2DAverageScaling(const BLMatrix2D& m) noexcept { |
38 | double x = m.m00 + m.m10; |
39 | double y = m.m01 + m.m11; |
40 | return blSqrt((blSquare(x) + blSquare(y)) * 0.5); |
41 | } |
42 | |
43 | //! Returns absolute scaling of `m`. |
44 | static BL_INLINE BLPoint blMatrix2DAbsoluteScaling(const BLMatrix2D& m) noexcept { |
45 | return BLPoint(blHypot(m.m00, m.m10), blHypot(m.m01, m.m11)); |
46 | } |
47 | |
48 | static BL_INLINE BLBox blMatrix2DMapBox(const BLMatrix2D& m, const BLBox& src) noexcept { |
49 | double x0a = src.x0 * m.m00; |
50 | double y0a = src.y0 * m.m10; |
51 | double x1a = src.x1 * m.m00; |
52 | double y1a = src.y1 * m.m10; |
53 | |
54 | double x0b = src.x0 * m.m01; |
55 | double y0b = src.y0 * m.m11; |
56 | double x1b = src.x1 * m.m01; |
57 | double y1b = src.y1 * m.m11; |
58 | |
59 | return BLBox(blMin(x0a, x1a) + blMin(y0a, y1a) + m.m20, |
60 | blMin(x0b, x1b) + blMin(y0b, y1b) + m.m21, |
61 | blMax(x0a, x1a) + blMax(y0a, y1a) + m.m20, |
62 | blMax(x0b, x1b) + blMax(y0b, y1b) + m.m21); |
63 | } |
64 | |
65 | static BL_INLINE void blMatrix2DMultiply(BLMatrix2D& dst, const BLMatrix2D& a, const BLMatrix2D& b) noexcept { |
66 | dst.reset(a.m00 * b.m00 + a.m01 * b.m10, |
67 | a.m00 * b.m01 + a.m01 * b.m11, |
68 | a.m10 * b.m00 + a.m11 * b.m10, |
69 | a.m10 * b.m01 + a.m11 * b.m11, |
70 | a.m20 * b.m00 + a.m21 * b.m10 + b.m20, |
71 | a.m20 * b.m01 + a.m21 * b.m11 + b.m21); |
72 | } |
73 | |
74 | //! \} |
75 | //! \endcond |
76 | |
77 | #endif // BLEND2D_BLMATRIX_P_H |
78 | |