]>
git.saurik.com Git - wxWidgets.git/blob - src/common/affinematrix2d.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: affinematrix2d.cpp
3 // Purpose: implementation of wxAffineMatrix2D
4 // Author: Based on wxTransformMatrix by Chris Breeze, Julian Smart
6 // Copyright: (c) wxWidgets team
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
18 #include "wx/affinematrix2d.h"
21 // sets the matrix to the respective values
22 void wxAffineMatrix2D::Set(const wxMatrix2D
&mat2D
, const wxPoint2DDouble
&tr
)
32 // gets the component valuess of the matrix
33 void wxAffineMatrix2D::Get(wxMatrix2D
*mat2D
, wxPoint2DDouble
*tr
) const
47 // concatenates the matrix
48 // | t.m_11 t.m_12 0 | | m_11 m_12 0 |
49 // | t.m_21 t.m_22 0 | x | m_21 m_22 0 |
50 // | t.m_tx t.m_ty 1 | | m_tx m_ty 1 |
51 void wxAffineMatrix2D::Concat(const wxAffineMatrix2DBase
&t
)
57 m_tx
+= tr
.m_x
*m_11
+ tr
.m_y
*m_21
;
58 m_ty
+= tr
.m_x
*m_12
+ tr
.m_y
*m_22
;
59 wxDouble e11
= mat
.m_11
*m_11
+ mat
.m_12
*m_21
;
60 wxDouble e12
= mat
.m_11
*m_12
+ mat
.m_12
*m_22
;
61 wxDouble e21
= mat
.m_21
*m_11
+ mat
.m_22
*m_21
;
62 m_22
= mat
.m_21
*m_12
+ mat
.m_22
*m_22
;
68 // makes this its inverse matrix.
73 bool wxAffineMatrix2D::Invert()
75 const wxDouble det
= m_11
*m_22
- m_12
*m_21
;
80 wxDouble ex
= (m_21
*m_ty
- m_22
*m_tx
) / det
;
81 m_ty
= (-m_11
*m_ty
+ m_12
*m_tx
) / det
;
83 wxDouble e11
= m_22
/ det
;
92 // returns true if the elements of the transformation matrix are equal
93 bool wxAffineMatrix2D::IsEqual(const wxAffineMatrix2DBase
& t
) const
99 return m_11
== mat
.m_11
&& m_12
== mat
.m_12
&&
100 m_21
== mat
.m_21
&& m_22
== mat
.m_22
&&
101 m_tx
== tr
.m_x
&& m_ty
== tr
.m_y
;
108 // add the translation to this matrix
109 // | 1 0 0 | | m_11 m_12 0 |
110 // | 0 1 0 | x | m_21 m_22 0 |
111 // | dx dy 1 | | m_tx m_ty 1 |
112 void wxAffineMatrix2D::Translate(wxDouble dx
, wxDouble dy
)
114 m_tx
+= m_11
* dx
+ m_21
* dy
;
115 m_ty
+= m_12
* dx
+ m_22
* dy
;
118 // add the scale to this matrix
119 // | xScale 0 0 | | m_11 m_12 0 |
120 // | 0 yScale 0 | x | m_21 m_22 0 |
121 // | 0 0 1 | | m_tx m_ty 1 |
122 void wxAffineMatrix2D::Scale(wxDouble xScale
, wxDouble yScale
)
130 // add the rotation to this matrix (clockwise, radians)
131 // | cos sin 0 | | m_11 m_12 0 |
132 // | -sin cos 0 | x | m_21 m_22 0 |
133 // | 0 0 1 | | m_tx m_ty 1 |
134 void wxAffineMatrix2D::Rotate(wxDouble cRadians
)
136 wxDouble c
= cos(cRadians
);
137 wxDouble s
= sin(cRadians
);
139 wxDouble e11
= c
*m_11
+ s
*m_21
;
140 wxDouble e12
= c
*m_12
+ s
*m_22
;
141 m_21
= c
*m_21
- s
*m_11
;
142 m_22
= c
*m_22
- s
*m_12
;
148 // apply the transforms
151 // applies that matrix to the point
153 // | src.m_x src._my 1 | x | m_21 m_22 0 |
156 wxAffineMatrix2D::DoTransformPoint(const wxPoint2DDouble
& src
) const
161 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
+ m_tx
,
162 src
.m_x
* m_12
+ src
.m_y
* m_22
+ m_ty
);
165 // applies the matrix except for translations
167 // | src.m_x src._my 0 | x | m_21 m_22 0 |
170 wxAffineMatrix2D::DoTransformDistance(const wxPoint2DDouble
& src
) const
175 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
,
176 src
.m_x
* m_12
+ src
.m_y
* m_22
);
179 bool wxAffineMatrix2D::IsIdentity() const
181 return m_11
== 1 && m_12
== 0 &&
182 m_21
== 0 && m_22
== 1 &&
183 m_tx
== 0 && m_ty
== 0;
186 #endif // wxUSE_GEOMETRY