@@ -14,7 +14,7 @@ namespace pretty_poly {
14
14
15
15
// 3x3 matrix for coordinate transformations
16
16
struct mat3_t {
17
- float v00, v10, v20, v01, v11, v21, v02, v12, v22 = 0 .0f ;
17
+ float v00 = 0 . 0f , v10 = 0 . 0f , v20 = 0 . 0f , v01 = 0 . 0f , v11 = 0 . 0f , v21 = 0 . 0f , v02 = 0 . 0f , v12 = 0 . 0f , v22 = 0 .0f ;
18
18
mat3_t () = default ;
19
19
mat3_t (const mat3_t &m) = default ;
20
20
inline mat3_t & operator *= (const mat3_t &m) {
@@ -43,6 +43,29 @@ namespace pretty_poly {
43
43
mat3_t r = mat3_t::identity (); r.v00 = x; r.v11 = y; return r;}
44
44
};
45
45
46
+ // 2x2 matrix for rotations and scales
47
+ struct mat2_t {
48
+ float v00 = 0 .0f , v10 = 0 .0f , v01 = 0 .0f , v11 = 0 .0f ;
49
+ mat2_t () = default ;
50
+ mat2_t (const mat2_t &m) = default ;
51
+ inline mat2_t & operator *= (const mat2_t &m) {
52
+ float r00 = this ->v00 * m.v00 + this ->v01 * m.v10 ;
53
+ float r01 = this ->v00 * m.v01 + this ->v01 * m.v11 ;
54
+ float r10 = this ->v10 * m.v00 + this ->v11 * m.v10 ;
55
+ float r11 = this ->v10 * m.v01 + this ->v11 * m.v11 ;
56
+ this ->v00 = r00; this ->v01 = r01;
57
+ this ->v10 = r10; this ->v11 = r11;
58
+ return *this ;
59
+ }
60
+
61
+ static mat2_t identity () {mat2_t m; m.v00 = m.v11 = 1 .0f ; return m;}
62
+ static mat2_t rotation (float a) {
63
+ float c = cosf (a), s = sinf (a); mat2_t r;
64
+ r.v00 = c; r.v01 = -s; r.v10 = s; r.v11 = c; return r;}
65
+ static mat2_t scale (float x, float y) {
66
+ mat2_t r; r.v00 = x; r.v11 = y; return r;}
67
+ };
68
+
46
69
// point type for contour points
47
70
template <typename T = int >
48
71
struct __attribute__ ((packed)) point_t {
@@ -52,6 +75,7 @@ namespace pretty_poly {
52
75
inline point_t & operator -= (const point_t &a) {x -= a.x ; y -= a.y ; return *this ;}
53
76
inline point_t & operator += (const point_t &a) {x += a.x ; y += a.y ; return *this ;}
54
77
inline point_t & operator *= (const float a) {x *= a; y *= a; return *this ;}
78
+ inline point_t & operator *= (const mat2_t &a) {this ->transform (a); return *this ;}
55
79
inline point_t & operator *= (const mat3_t &a) {this ->transform (a); return *this ;}
56
80
inline point_t & operator /= (const float a) {x /= a; y /= a; return *this ;}
57
81
inline point_t & operator /= (const point_t &a) {x /= a.x ; y /= a.y ; return *this ;}
@@ -60,6 +84,11 @@ namespace pretty_poly {
60
84
this ->x = (m.v00 * tx + m.v01 * ty + m.v02 );
61
85
this ->y = (m.v10 * tx + m.v11 * ty + m.v12 );
62
86
}
87
+ void transform (const mat2_t &m) {
88
+ float tx = x, ty = y;
89
+ this ->x = (m.v00 * tx + m.v01 * ty);
90
+ this ->y = (m.v10 * tx + m.v11 * ty);
91
+ }
63
92
64
93
};
65
94
@@ -78,7 +107,7 @@ namespace pretty_poly {
78
107
int x, y, w, h;
79
108
rect_t () : x(0 ), y(0 ), w(0 ), h(0 ) {}
80
109
rect_t (int x, int y, int w, int h) : x(x), y(y), w(w), h(h) {}
81
- bool empty () const {return this ->w == 0 && this ->h == 0 ;}
110
+ bool empty () const {return this ->w == 0 || this ->h == 0 ;}
82
111
rect_t intersection (const rect_t &c) {
83
112
return rect_t (std::max (this ->x , c.x ), std::max (this ->y , c.y ),
84
113
std::max (0 , std::min (this ->x + this ->w , c.x + c.w ) - std::max (this ->x , c.x )),
0 commit comments