]>
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: wxWidgets licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #include "wx/affinematrix2d.h"
19 // sets the matrix to the respective values
20 void wxAffineMatrix2D::Set(const wxMatrix2D
&mat2D
, const wxPoint2DDouble
&tr
)
30 // gets the component valuess of the matrix
31 void wxAffineMatrix2D::Get(wxMatrix2D
*mat2D
, wxPoint2DDouble
*tr
) const
45 // concatenates the matrix
46 // | t.m_11 t.m_12 0 | | m_11 m_12 0 |
47 // | t.m_21 t.m_22 0 | x | m_21 m_22 0 |
48 // | t.m_tx t.m_ty 1 | | m_tx m_ty 1 |
49 void wxAffineMatrix2D::Concat(const wxAffineMatrix2DBase
&t
)
55 m_tx
+= tr
.m_x
*m_11
+ tr
.m_y
*m_21
;
56 m_ty
+= tr
.m_x
*m_12
+ tr
.m_y
*m_22
;
57 wxDouble e11
= mat
.m_11
*m_11
+ mat
.m_12
*m_21
;
58 wxDouble e12
= mat
.m_11
*m_12
+ mat
.m_12
*m_22
;
59 wxDouble e21
= mat
.m_21
*m_11
+ mat
.m_22
*m_21
;
60 m_22
= mat
.m_21
*m_12
+ mat
.m_22
*m_22
;
66 // makes this its inverse matrix.
71 bool wxAffineMatrix2D::Invert()
73 const wxDouble det
= m_11
*m_22
- m_12
*m_21
;
78 wxDouble ex
= (m_21
*m_ty
- m_22
*m_tx
) / det
;
79 m_ty
= (-m_11
*m_ty
+ m_12
*m_tx
) / det
;
81 wxDouble e11
= m_22
/ det
;
90 // returns true if the elements of the transformation matrix are equal
91 bool wxAffineMatrix2D::IsEqual(const wxAffineMatrix2DBase
& t
) const
97 return m_11
== mat
.m_11
&& m_12
== mat
.m_12
&&
98 m_21
== mat
.m_21
&& m_22
== mat
.m_22
&&
99 m_tx
== tr
.m_x
&& m_ty
== tr
.m_y
;
106 // add the translation to this matrix
107 void wxAffineMatrix2D::Translate(wxDouble dx
, wxDouble dy
)
113 // add the scale to this matrix
114 // | xScale 0 0 | | m_11 m_12 0 |
115 // | 0 yScale 0 | x | m_21 m_22 0 |
116 // | 0 0 1 | | m_tx m_ty 1 |
117 void wxAffineMatrix2D::Scale(wxDouble xScale
, wxDouble yScale
)
125 // add the rotation to this matrix (counter clockwise, radians)
126 // | cos -sin 0 | | m_11 m_12 0 |
127 // | sin cos 0 | x | m_21 m_22 0 |
128 // | 0 0 1 | | m_tx m_ty 1 |
129 void wxAffineMatrix2D::Rotate(wxDouble ccRadians
)
131 wxDouble c
= cos(ccRadians
);
132 wxDouble s
= sin(ccRadians
);
134 wxDouble e11
= c
*m_11
- s
*m_21
;
135 wxDouble e12
= c
*m_12
- s
*m_22
;
136 m_21
= s
*m_11
+ c
*m_21
;
137 m_22
= s
*m_12
+ c
*m_22
;
143 // apply the transforms
146 // applies that matrix to the point
148 // | src.m_x src._my 1 | x | m_21 m_22 0 |
151 wxAffineMatrix2D::DoTransformPoint(const wxPoint2DDouble
& src
) const
156 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
+ m_tx
,
157 src
.m_y
* m_12
+ src
.m_y
* m_22
+ m_ty
);
160 // applies the matrix except for translations
162 // | src.m_x src._my 0 | x | m_21 m_22 0 |
165 wxAffineMatrix2D::DoTransformDistance(const wxPoint2DDouble
& src
) const
170 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
,
171 src
.m_y
* m_12
+ src
.m_y
* m_22
);
174 bool wxAffineMatrix2D::IsIdentity() const
176 return m_11
== 1 && m_12
== 0 &&
177 m_21
== 0 && m_22
== 1 &&
178 m_tx
== 0 && m_ty
== 0;