1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTransformMatrix class. NOT YET USED
4 // Author: Chris Breeze, Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "matrix.h"
19 #include "wx/object.h"
21 // A simple 3x3 matrix. This may be replaced by a more general matrix
24 // Note: this is intended to be used in wxDC at some point to replace
25 // the current system of scaling/translation. It is not yet used.
27 class WXDLLEXPORT wxTransformMatrix
: public wxObject
30 wxTransformMatrix(void);
31 wxTransformMatrix(const wxTransformMatrix
& mat
);
33 double GetValue(int row
, int col
) const;
34 void SetValue(int row
, int col
, double value
);
36 void operator = (const wxTransformMatrix
& mat
);
37 bool operator == (const wxTransformMatrix
& mat
);
38 bool operator != (const wxTransformMatrix
& mat
);
40 double& operator()(int row
, int col
);
41 double operator()(int row
, int col
) const;
46 // Make into identity matrix
49 // Is the matrix the identity matrix?
50 // Only returns a flag, which is set whenever an operation
52 inline bool IsIdentity(void) const { return m_isIdentity
; };
54 // This does an actual check.
55 inline bool IsIdentity1(void) const ;
58 bool Scale(double scale
);
61 bool Translate(double x
, double y
);
64 bool Rotate(double angle
);
66 // Transform X value from logical to device
67 inline double TransformX(double x
) const;
69 // Transform Y value from logical to device
70 inline double TransformY(double y
) const;
72 // Transform a point from logical to device coordinates
73 bool TransformPoint(double x
, double y
, double& tx
, double& ty
) const;
75 // Transform a point from device to logical coordinates.
78 // wxTransformMatrix mat = dc.GetTransformation();
80 // mat.InverseTransformPoint(x, y, x1, y1);
82 // dc.LogicalToDevice(x, y, x1, y1);
83 // The latter is slightly less efficient if we're doing several
84 // conversions, since the matrix is inverted several times.
86 // N.B. 'this' matrix is the inverse at this point
88 bool InverseTransformPoint(double x
, double y
, double& tx
, double& ty
) const;
91 double m_matrix
[3][3];
102 The code is wrong and doesn't compile. Chris Breeze als reported, that
103 some functions of wxTransformMatrix cannot work because it is not
104 known if he matrix has been inverted. Be careful when using it.
106 // Transform X value from logical to device
107 inline double wxTransformMatrix::TransformX(double x) const
109 return (m_isIdentity ? x : (x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0]));
112 // Transform Y value from logical to device
113 inline double wxTransformMatrix::TransformY(double y) const
115 return (m_isIdentity ? y : (x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1]));
119 // Is the matrix the identity matrix?
120 // Perhaps there's some kind of optimization we can do to make this
121 // a faster operation. E.g. each operation (scale, translate etc.)
122 // checks whether it's still the identity matrix and sets a flag.
123 inline bool wxTransformMatrix::IsIdentity1(void) const
126 (m_matrix
[0][0] == 1.0 &&
127 m_matrix
[1][1] == 1.0 &&
128 m_matrix
[2][2] == 1.0 &&
129 m_matrix
[1][0] == 0.0 &&
130 m_matrix
[2][0] == 0.0 &&
131 m_matrix
[0][1] == 0.0 &&
132 m_matrix
[2][1] == 0.0 &&
133 m_matrix
[0][2] == 0.0 &&
134 m_matrix
[1][2] == 0.0) ;
137 // Calculates the determinant of a 2 x 2 matrix
138 inline double wxCalculateDet(double a11
, double a21
, double a12
, double a22
)
140 return a11
* a22
- a12
* a21
;