affinematrix2dbase.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/affinematrix2dbase.h
  3. // Purpose: Common interface for 2D transformation matrices.
  4. // Author: Catalin Raceanu
  5. // Created: 2011-04-06
  6. // Copyright: (c) wxWidgets team
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_AFFINEMATRIX2DBASE_H_
  10. #define _WX_AFFINEMATRIX2DBASE_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_GEOMETRY
  13. #include "wx/geometry.h"
  14. struct wxMatrix2D
  15. {
  16. wxMatrix2D(wxDouble v11 = 1,
  17. wxDouble v12 = 0,
  18. wxDouble v21 = 0,
  19. wxDouble v22 = 1)
  20. {
  21. m_11 = v11; m_12 = v12;
  22. m_21 = v21; m_22 = v22;
  23. }
  24. wxDouble m_11, m_12, m_21, m_22;
  25. };
  26. // A 2x3 matrix representing an affine 2D transformation.
  27. //
  28. // This is an abstract base class implemented by wxAffineMatrix2D only so far,
  29. // but in the future we also plan to derive wxGraphicsMatrix from it (it should
  30. // also be documented then as currently only wxAffineMatrix2D itself is).
  31. class WXDLLIMPEXP_CORE wxAffineMatrix2DBase
  32. {
  33. public:
  34. wxAffineMatrix2DBase() {}
  35. virtual ~wxAffineMatrix2DBase() {}
  36. // sets the matrix to the respective values
  37. virtual void Set(const wxMatrix2D& mat2D, const wxPoint2DDouble& tr) = 0;
  38. // gets the component valuess of the matrix
  39. virtual void Get(wxMatrix2D* mat2D, wxPoint2DDouble* tr) const = 0;
  40. // concatenates the matrix
  41. virtual void Concat(const wxAffineMatrix2DBase& t) = 0;
  42. // makes this the inverse matrix
  43. virtual bool Invert() = 0;
  44. // return true if this is the identity matrix
  45. virtual bool IsIdentity() const = 0;
  46. // returns true if the elements of the transformation matrix are equal ?
  47. virtual bool IsEqual(const wxAffineMatrix2DBase& t) const = 0;
  48. bool operator==(const wxAffineMatrix2DBase& t) const { return IsEqual(t); }
  49. bool operator!=(const wxAffineMatrix2DBase& t) const { return !IsEqual(t); }
  50. //
  51. // transformations
  52. //
  53. // add the translation to this matrix
  54. virtual void Translate(wxDouble dx, wxDouble dy) = 0;
  55. // add the scale to this matrix
  56. virtual void Scale(wxDouble xScale, wxDouble yScale) = 0;
  57. // add the rotation to this matrix (counter clockwise, radians)
  58. virtual void Rotate(wxDouble ccRadians) = 0;
  59. // add mirroring to this matrix
  60. void Mirror(int direction = wxHORIZONTAL)
  61. {
  62. wxDouble x = (direction & wxHORIZONTAL) ? -1 : 1;
  63. wxDouble y = (direction & wxVERTICAL) ? -1 : 1;
  64. Scale(x, y);
  65. }
  66. // applies that matrix to the point
  67. wxPoint2DDouble TransformPoint(const wxPoint2DDouble& src) const
  68. {
  69. return DoTransformPoint(src);
  70. }
  71. void TransformPoint(wxDouble* x, wxDouble* y) const
  72. {
  73. wxCHECK_RET( x && y, "Can't be NULL" );
  74. const wxPoint2DDouble dst = DoTransformPoint(wxPoint2DDouble(*x, *y));
  75. *x = dst.m_x;
  76. *y = dst.m_y;
  77. }
  78. // applies the matrix except for translations
  79. wxPoint2DDouble TransformDistance(const wxPoint2DDouble& src) const
  80. {
  81. return DoTransformDistance(src);
  82. }
  83. void TransformDistance(wxDouble* dx, wxDouble* dy) const
  84. {
  85. wxCHECK_RET( dx && dy, "Can't be NULL" );
  86. const wxPoint2DDouble
  87. dst = DoTransformDistance(wxPoint2DDouble(*dx, *dy));
  88. *dx = dst.m_x;
  89. *dy = dst.m_y;
  90. }
  91. protected:
  92. virtual
  93. wxPoint2DDouble DoTransformPoint(const wxPoint2DDouble& p) const = 0;
  94. virtual
  95. wxPoint2DDouble DoTransformDistance(const wxPoint2DDouble& p) const = 0;
  96. };
  97. #endif // wxUSE_GEOMETRY
  98. #endif // _WX_AFFINEMATRIX2DBASE_H_