affinematrix2dbase.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: affinematrix2dbase.h
  3. // Purpose: wxMatrix2D documentation
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxMatrix2D
  9. A simple container for 2x2 matrix.
  10. This simple structure is used with wxAffineMatrix2D.
  11. @library{wxcore}
  12. @category{misc}
  13. @since 2.9.2
  14. */
  15. struct wxMatrix2D
  16. {
  17. /**
  18. Default constructor.
  19. Initializes the matrix elements to the identity.
  20. */
  21. wxMatrix2D(wxDouble v11 = 1,
  22. wxDouble v12 = 0,
  23. wxDouble v21 = 0,
  24. wxDouble v22 = 1);
  25. /// The matrix elements in the usual mathematical notation.
  26. wxDouble m_11, m_12, m_21, m_22;
  27. };
  28. /**
  29. @class wxAffineMatrix2DBase
  30. A 2x3 matrix representing an affine 2D transformation.
  31. This is an abstract base class implemented by wxAffineMatrix2D only so far,
  32. but in the future we also plan to derive wxGraphicsMatrix from it.
  33. @library{wxcore}
  34. @category{misc}
  35. @since 2.9.2
  36. */
  37. class wxAffineMatrix2DBase
  38. {
  39. public:
  40. /**
  41. Default constructor.
  42. The matrix elements are initialize to the identity matrix.
  43. */
  44. wxAffineMatrix2DBase();
  45. virtual ~wxAffineMatrix2DBase();
  46. /**
  47. Set all elements of this matrix.
  48. @param mat2D
  49. The rotational components of the matrix (upper 2 x 2).
  50. @param tr
  51. The translational components of the matrix.
  52. */
  53. virtual void Set(const wxMatrix2D& mat2D, const wxPoint2DDouble& tr) = 0;
  54. /**
  55. Get the component values of the matrix.
  56. @param mat2D
  57. The rotational components of the matrix (upper 2 x 2), must be
  58. non-@NULL.
  59. @param tr
  60. The translational components of the matrix, may be @NULL.
  61. */
  62. virtual void Get(wxMatrix2D* mat2D, wxPoint2DDouble* tr) const = 0;
  63. /**
  64. Concatenate this matrix with another one.
  65. The parameter matrix is the multiplicand.
  66. @param t
  67. The multiplicand.
  68. @code
  69. // | t.m_11 t.m_12 0 | | m_11 m_12 0 |
  70. // matrix' = | t.m_21 t.m_22 0 | x | m_21 m_22 0 |
  71. // | t.m_tx t.m_ty 1 | | m_tx m_ty 1 |
  72. @endcode
  73. */
  74. virtual void Concat(const wxAffineMatrix2DBase& t) = 0;
  75. /**
  76. Invert this matrix.
  77. If the matrix is not invertible, i.e. if its determinant is 0, returns
  78. false and doesn't modify it.
  79. @code
  80. // | m_11 m_12 0 |
  81. // Invert | m_21 m_22 0 |
  82. // | m_tx m_ty 1 |
  83. @endcode
  84. */
  85. virtual bool Invert() = 0;
  86. /**
  87. Check if this is the identity matrix.
  88. */
  89. virtual bool IsIdentity() const = 0;
  90. //@{
  91. /**
  92. Check that this matrix is identical with @a t.
  93. @param t
  94. The matrix compared with this.
  95. */
  96. virtual bool IsEqual(const wxAffineMatrix2DBase& t) const = 0;
  97. bool operator==(const wxAffineMatrix2DBase& t) const;
  98. //@}
  99. /**
  100. Check that this matrix differs from @a t.
  101. @param t
  102. The matrix compared with this.
  103. */
  104. bool operator!=(const wxAffineMatrix2DBase& t) const;
  105. /**
  106. Add the translation to this matrix.
  107. @param dx
  108. The translation in x direction.
  109. @param dy
  110. The translation in y direction.
  111. */
  112. virtual void Translate(wxDouble dx, wxDouble dy) = 0;
  113. /**
  114. Add scaling to this matrix.
  115. @param xScale
  116. Scaling in x direction.
  117. @param yScale
  118. Scaling in y direction.
  119. */
  120. virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;
  121. /**
  122. Add clockwise rotation to this matrix.
  123. @param cRadians
  124. Rotation angle in radians, clockwise.
  125. */
  126. virtual void Rotate(wxDouble cRadians) = 0;
  127. /**
  128. Add mirroring to this matrix.
  129. @param direction
  130. The direction(s) used for mirroring. One of wxHORIZONTAL,
  131. wxVERTICAL or their combination wxBOTH.
  132. */
  133. void Mirror(int direction = wxHORIZONTAL);
  134. /**
  135. Applies this matrix to the point.
  136. @param p
  137. The point receiving the transformations.
  138. @return The point with the transformations applied.
  139. */
  140. wxPoint2DDouble TransformPoint(const wxPoint2DDouble& p) const;
  141. void TransformPoint(wxDouble* x, wxDouble* y) const;
  142. /**
  143. Applies the linear part of this matrix, i.e.\ without translation.
  144. @param p
  145. The source receiving the transformations.
  146. @return The source with the transformations applied.
  147. */
  148. wxPoint2DDouble TransformDistance(const wxPoint2DDouble& p) const;
  149. void TransformDistance(wxDouble* dx, wxDouble* dy) const;
  150. };