]>
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 void wxAffineMatrix2D::Translate(wxDouble dx
, wxDouble dy
)
115 // add the scale to this matrix
116 // | xScale 0 0 | | m_11 m_12 0 |
117 // | 0 yScale 0 | x | m_21 m_22 0 |
118 // | 0 0 1 | | m_tx m_ty 1 |
119 void wxAffineMatrix2D::Scale(wxDouble xScale
, wxDouble yScale
)
127 // add the rotation to this matrix (counter clockwise, radians)
128 // | cos -sin 0 | | m_11 m_12 0 |
129 // | sin cos 0 | x | m_21 m_22 0 |
130 // | 0 0 1 | | m_tx m_ty 1 |
131 void wxAffineMatrix2D::Rotate(wxDouble ccRadians
)
133 wxDouble c
= cos(ccRadians
);
134 wxDouble s
= sin(ccRadians
);
136 wxDouble e11
= c
*m_11
- s
*m_21
;
137 wxDouble e12
= c
*m_12
- s
*m_22
;
138 m_21
= s
*m_11
+ c
*m_21
;
139 m_22
= s
*m_12
+ c
*m_22
;
145 // apply the transforms
148 // applies that matrix to the point
150 // | src.m_x src._my 1 | x | m_21 m_22 0 |
153 wxAffineMatrix2D::DoTransformPoint(const wxPoint2DDouble
& src
) const
158 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
+ m_tx
,
159 src
.m_y
* m_12
+ src
.m_y
* m_22
+ m_ty
);
162 // applies the matrix except for translations
164 // | src.m_x src._my 0 | x | m_21 m_22 0 |
167 wxAffineMatrix2D::DoTransformDistance(const wxPoint2DDouble
& src
) const
172 return wxPoint2DDouble(src
.m_x
* m_11
+ src
.m_y
* m_21
,
173 src
.m_y
* m_12
+ src
.m_y
* m_22
);
176 bool wxAffineMatrix2D::IsIdentity() const
178 return m_11
== 1 && m_12
== 0 &&
179 m_21
== 0 && m_22
== 1 &&
180 m_tx
== 0 && m_ty
== 0;
183 #endif // wxUSE_GEOMETRY