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];
100 // Transform X value from logical to device
101 inline double wxTransformMatrix::TransformX(double x
) const
103 // return (m_isIdentity ? x : (x * m_matrix[0][0] + y * m_matrix[1][0] + m_matrix[2][0]));
107 // Transform Y value from logical to device
108 inline double wxTransformMatrix::TransformY(double y
) const
110 // return (m_isIdentity ? y : (x * m_matrix[0][1] + y * m_matrix[1][1] + m_matrix[2][1]));
114 // Is the matrix the identity matrix?
115 // Perhaps there's some kind of optimization we can do to make this
116 // a faster operation. E.g. each operation (scale, translate etc.)
117 // checks whether it's still the identity matrix and sets a flag.
118 inline bool wxTransformMatrix::IsIdentity1(void) const
121 (m_matrix
[0][0] == 1.0 &&
122 m_matrix
[1][1] == 1.0 &&
123 m_matrix
[2][2] == 1.0 &&
124 m_matrix
[1][0] == 0.0 &&
125 m_matrix
[2][0] == 0.0 &&
126 m_matrix
[0][1] == 0.0 &&
127 m_matrix
[2][1] == 0.0 &&
128 m_matrix
[0][2] == 0.0 &&
129 m_matrix
[1][2] == 0.0) ;
132 // Calculates the determinant of a 2 x 2 matrix
133 inline double wxCalculateDet(double a11
, double a21
, double a12
, double a22
)
135 return a11
* a22
- a12
* a21
;