1 #ifndef SDK_MATRIX_3X2_H_
11 #define SDK_MATRIX_3X2_H_
13 #define _USE_MATH_DEFINES
26 template <
class _SDKMatrix3X2>
31 typedef _SDKMatrix3X2 SDKMatrix3X2;
32 typedef typename SDKMatrix3X2::coordinate_type coordinate_type;
42 const double s21,
const double s22,
43 const double s31,
const double s32) noexcept
45 this->_11 = coordinate_type(s11); this->_12 = coordinate_type(s12);
46 this->_21 = coordinate_type(s21); this->_22 = coordinate_type(s22);
47 this->_31 = coordinate_type(s31); this->_32 = coordinate_type(s32);
53 this->_11 = this->_22 = 1;
54 this->_12 = this->_21 = this->_31 = this->_32 = 0;
60 if (this->_11 != 1 || this->_22 != 1
61 || this->_12 != 0 || this->_21 != 0 || this->_31 != 0 || this->_32 != 0)
71 double angle_rad = (angle_deg / 180.0) *
kPI;
74 double s = sin(angle_rad);
75 double c = cos(angle_rad);
77 this->_11 = coordinate_type(c);
78 this->_12 = coordinate_type(s);
79 this->_21 = coordinate_type(-s);
80 this->_22 = coordinate_type(c);
81 this->_31 = coordinate_type(-center.x * (c - 1) + center.y * s);
82 this->_32 = coordinate_type(-center.y * (c - 1) - center.x * s);
90 this->_11 = 1; this->_12 = 0;
91 this->_21 = 0; this->_22 = 1;
92 this->_31 = x; this->_32 = y;
98 const _MyType&
Scale(
const float& scale_x,
const float& scale_y) noexcept
100 this->_11 = scale_x; this->_12 = 0.0;
101 this->_21 = 0.0; this->_22 = scale_y;
102 this->_31 = 0.0; this->_32 = 0.0;
111 static _MyType Multiply(
const SDKMatrix3X2& m1,
const SDKMatrix3X2& m2)
117 return _MyType(res._11, res._12, res._21, res._22, res._31, res._32);
120 _MyType& operator=(
const SDKMatrix3X2& m) noexcept
122 *
static_cast<SDKMatrix3X2*
>(
this) = m;
126 const SDKMatrix3X2& get() const noexcept
128 return *
static_cast<const SDKMatrix3X2*
>(
this);
137 res.x = this->_11 * point.x + this->_21 * point.y + this->_31;
138 res.y = this->_12 * point.x + this->_22 * point.y + this->_32;
145 res.x =
static_cast<float>(res_d.x);
146 res.y =
static_cast<float>(res_d.y);
150 SDKPointD2D point_d = {
static_cast<double>(point.x),
151 static_cast<double>(point.y) };
154 res.x = RoundToNearest<SDKInt32, double>(res_d.x);
155 res.y = RoundToNearest<SDKInt32, double>(res_d.y);
160 SDKPointD2D pt_nw = { rect.x, rect.y + rect.height };
161 SDKPointD2D pt_se = { rect.x + rect.width, rect.y };
163 rect.y + rect.height };
164 pt_sw = Transform(pt_sw);
165 pt_nw = Transform(pt_nw);
166 pt_se = Transform(pt_se);
167 pt_ne = Transform(pt_ne);
168 double min_x = min4dbl(pt_sw.x, pt_nw.x, pt_se.x, pt_ne.x);
169 double min_y = min4dbl(pt_sw.y, pt_nw.y, pt_se.y, pt_ne.y);
170 double max_x = max4dbl(pt_sw.x, pt_nw.x, pt_se.x, pt_ne.x);
171 double max_y = max4dbl(pt_sw.y, pt_nw.y, pt_se.y, pt_ne.y);
172 SDKRectD2D res = { min_x, min_y, max_x - min_x, max_y - min_y };
176 SDKRectD2D rect_d = { rect.x, rect.y, rect.width, rect.height };
178 SDKRectF2D res = {
static_cast<float>(res_d.x),
static_cast<float>(res_d.y),
179 static_cast<float>(res_d.width),
static_cast<float>(res_d.height) };
183 SDKRectD2D rect_d = {
static_cast<double>(rect.x),
184 static_cast<double>(rect.y),
185 static_cast<double>(rect.width),
186 static_cast<double>(rect.height) };
188 SDKRect2D res = { RoundToNearest<SDKInt32>(res_d.x),
189 RoundToNearest<SDKInt32>(res_d.y),
190 RoundToNearest<SDKUInt32>(res_d.width),
191 RoundToNearest<SDKUInt32>(res_d.height) };
197 typedef Matrix3X2T<SDKMatrix3X2> Matrix3X2, CMatrix3X2;
198 typedef Matrix3X2T<SDKMatrixD3X2> MatrixD3X2, CMatrixD3X2;
199 typedef Matrix3X2T<SDKMatrixF3X2> MatrixF3X2, CMatrixF3X2;
202 #endif // SDK_MATRIX_3X2_H_