geometry.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: geometry.h
  3. // Purpose: interface of geometry classes
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. enum wxOutCode
  8. {
  9. wxInside = 0x00 ,
  10. wxOutLeft = 0x01 ,
  11. wxOutRight = 0x02 ,
  12. wxOutTop = 0x08 ,
  13. wxOutBottom = 0x04
  14. };
  15. class wxPoint2DInt
  16. {
  17. public :
  18. wxPoint2DInt();
  19. wxPoint2DInt( wxInt32 x , wxInt32 y );
  20. wxPoint2DInt( const wxPoint2DInt &pt );
  21. wxPoint2DInt( const wxPoint &pt );
  22. // noops for this class, just return the coords
  23. void GetFloor( wxInt32 *x , wxInt32 *y ) const;
  24. void GetRounded( wxInt32 *x , wxInt32 *y ) const;
  25. wxDouble GetVectorLength() const;
  26. wxDouble GetVectorAngle() const;
  27. void SetVectorLength( wxDouble length );
  28. void SetVectorAngle( wxDouble degrees );
  29. void SetPolarCoordinates( wxInt32 angle , wxInt32 length );
  30. // set the vector length to 1.0, preserving the angle
  31. void Normalize();
  32. wxDouble GetDistance( const wxPoint2DInt &pt ) const;
  33. wxDouble GetDistanceSquare( const wxPoint2DInt &pt ) const;
  34. wxInt32 GetDotProduct( const wxPoint2DInt &vec ) const;
  35. wxInt32 GetCrossProduct( const wxPoint2DInt &vec ) const;
  36. // the reflection of this point
  37. wxPoint2DInt operator-();
  38. wxPoint2DInt& operator=(const wxPoint2DInt& pt);
  39. wxPoint2DInt& operator+=(const wxPoint2DInt& pt);
  40. wxPoint2DInt& operator-=(const wxPoint2DInt& pt);
  41. wxPoint2DInt& operator*=(const wxPoint2DInt& pt);
  42. wxPoint2DInt& operator*=(wxDouble n);
  43. wxPoint2DInt& operator*=(wxInt32 n);
  44. wxPoint2DInt& operator/=(const wxPoint2DInt& pt);
  45. wxPoint2DInt& operator/=(wxDouble n);
  46. wxPoint2DInt& operator/=(wxInt32 n);
  47. operator wxPoint() const;
  48. bool operator==(const wxPoint2DInt& pt) const;
  49. bool operator!=(const wxPoint2DInt& pt) const;
  50. wxInt32 m_x;
  51. wxInt32 m_y;
  52. };
  53. wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
  54. wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
  55. wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
  56. wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
  57. wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
  58. wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
  59. wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
  60. wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
  61. wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
  62. wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
  63. // wxPoint2Ds represent a point or a vector in a 2d coordinate system
  64. class wxPoint2DDouble
  65. {
  66. public :
  67. wxPoint2DDouble();
  68. wxPoint2DDouble( wxDouble x , wxDouble y );
  69. wxPoint2DDouble( const wxPoint2DDouble &pt );
  70. wxPoint2DDouble( const wxPoint2DInt &pt );
  71. wxPoint2DDouble( const wxPoint &pt );
  72. // two different conversions to integers, floor and rounding
  73. void GetFloor( wxInt32 *x , wxInt32 *y ) const;
  74. void GetRounded( wxInt32 *x , wxInt32 *y ) const;
  75. wxDouble GetVectorLength() const;
  76. wxDouble GetVectorAngle() const ;
  77. void SetVectorLength( wxDouble length );
  78. void SetVectorAngle( wxDouble degrees );
  79. void SetPolarCoordinates( wxDouble angle , wxDouble length );
  80. // set the vector length to 1.0, preserving the angle
  81. void Normalize();
  82. wxDouble GetDistance( const wxPoint2DDouble &pt ) const;
  83. wxDouble GetDistanceSquare( const wxPoint2DDouble &pt ) const;
  84. wxDouble GetDotProduct( const wxPoint2DDouble &vec ) const;
  85. wxDouble GetCrossProduct( const wxPoint2DDouble &vec ) const;
  86. // the reflection of this point
  87. wxPoint2DDouble operator-();
  88. wxPoint2DDouble& operator=(const wxPoint2DDouble& pt);
  89. wxPoint2DDouble& operator+=(const wxPoint2DDouble& pt);
  90. wxPoint2DDouble& operator-=(const wxPoint2DDouble& pt);
  91. wxPoint2DDouble& operator*=(const wxPoint2DDouble& pt);
  92. wxPoint2DDouble& operator*=(wxDouble n);
  93. wxPoint2DDouble& operator*=(wxInt32 n);
  94. wxPoint2DDouble& operator/=(const wxPoint2DDouble& pt);
  95. wxPoint2DDouble& operator/=(wxDouble n);
  96. wxPoint2DDouble& operator/=(wxInt32 n);
  97. bool operator==(const wxPoint2DDouble& pt) const;
  98. bool operator!=(const wxPoint2DDouble& pt) const;
  99. wxDouble m_x;
  100. wxDouble m_y;
  101. };
  102. wxPoint2DDouble operator+(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
  103. wxPoint2DDouble operator-(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
  104. wxPoint2DDouble operator*(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
  105. wxPoint2DDouble operator*(wxDouble n , const wxPoint2DDouble& pt);
  106. wxPoint2DDouble operator*(wxInt32 n , const wxPoint2DDouble& pt);
  107. wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxDouble n);
  108. wxPoint2DDouble operator*(const wxPoint2DDouble& pt , wxInt32 n);
  109. wxPoint2DDouble operator/(const wxPoint2DDouble& pt1 , const wxPoint2DDouble& pt2);
  110. wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxDouble n);
  111. wxPoint2DDouble operator/(const wxPoint2DDouble& pt , wxInt32 n);
  112. // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
  113. // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
  114. // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
  115. class wxRect2DDouble
  116. {
  117. public:
  118. wxRect2DDouble();
  119. wxRect2DDouble(wxDouble x, wxDouble y, wxDouble w, wxDouble h);
  120. // single attribute accessors
  121. wxPoint2DDouble GetPosition() const;
  122. wxSize GetSize() const;
  123. // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
  124. // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
  125. wxDouble GetLeft() const;
  126. void SetLeft( wxDouble n );
  127. void MoveLeftTo( wxDouble n );
  128. wxDouble GetTop() const;
  129. void SetTop( wxDouble n );
  130. void MoveTopTo( wxDouble n );
  131. wxDouble GetBottom() const;
  132. void SetBottom( wxDouble n );
  133. void MoveBottomTo( wxDouble n );
  134. wxDouble GetRight() const;
  135. void SetRight( wxDouble n );
  136. void MoveRightTo( wxDouble n );
  137. wxPoint2DDouble GetLeftTop() const;
  138. void SetLeftTop( const wxPoint2DDouble &pt );
  139. void MoveLeftTopTo( const wxPoint2DDouble &pt );
  140. wxPoint2DDouble GetLeftBottom() const;
  141. void SetLeftBottom( const wxPoint2DDouble &pt );
  142. void MoveLeftBottomTo( const wxPoint2DDouble &pt );
  143. wxPoint2DDouble GetRightTop() const;
  144. void SetRightTop( const wxPoint2DDouble &pt );
  145. void MoveRightTopTo( const wxPoint2DDouble &pt );
  146. wxPoint2DDouble GetRightBottom() const;
  147. void SetRightBottom( const wxPoint2DDouble &pt );
  148. void MoveRightBottomTo( const wxPoint2DDouble &pt );
  149. wxPoint2DDouble GetCentre() const;
  150. void SetCentre( const wxPoint2DDouble &pt );
  151. void MoveCentreTo( const wxPoint2DDouble &pt );
  152. wxOutCode GetOutCode( const wxPoint2DDouble &pt ) const;
  153. wxOutCode GetOutcode(const wxPoint2DDouble &pt) const;
  154. bool Contains( const wxPoint2DDouble &pt ) const;
  155. bool Contains( const wxRect2DDouble &rect ) const;
  156. bool IsEmpty() const;
  157. bool HaveEqualSize( const wxRect2DDouble &rect ) const;
  158. void Inset( wxDouble x , wxDouble y );
  159. void Inset( wxDouble left , wxDouble top ,wxDouble right , wxDouble bottom );
  160. void Offset( const wxPoint2DDouble &pt );
  161. void ConstrainTo( const wxRect2DDouble &rect );
  162. wxPoint2DDouble Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
  163. static void Intersect( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
  164. void Intersect( const wxRect2DDouble &otherRect );
  165. wxRect2DDouble CreateIntersection( const wxRect2DDouble &otherRect ) const;
  166. bool Intersects( const wxRect2DDouble &rect ) const;
  167. static void Union( const wxRect2DDouble &src1 , const wxRect2DDouble &src2 , wxRect2DDouble *dest );
  168. void Union( const wxRect2DDouble &otherRect );
  169. void Union( const wxPoint2DDouble &pt );
  170. wxRect2DDouble CreateUnion( const wxRect2DDouble &otherRect ) const;
  171. void Scale( wxDouble f );
  172. void Scale( wxInt32 num , wxInt32 denum );
  173. wxRect2DDouble& operator = (const wxRect2DDouble& rect);
  174. bool operator == (const wxRect2DDouble& rect) const;
  175. bool operator != (const wxRect2DDouble& rect) const;
  176. wxDouble m_x;
  177. wxDouble m_y;
  178. wxDouble m_width;
  179. wxDouble m_height;
  180. };
  181. // wxRect2Ds are a axis-aligned rectangles, each side of the rect is parallel to the x- or m_y- axis. The rectangle is either defined by the
  182. // top left and bottom right corner, or by the top left corner and size. A point is contained within the rectangle if
  183. // left <= x < right and top <= m_y < bottom , thus it is a half open interval.
  184. class wxRect2DInt
  185. {
  186. public:
  187. wxRect2DInt();
  188. wxRect2DInt( const wxRect& r );
  189. wxRect2DInt(wxInt32 x, wxInt32 y, wxInt32 w, wxInt32 h);
  190. wxRect2DInt(const wxPoint2DInt& topLeft, const wxPoint2DInt& bottomRight);
  191. wxRect2DInt(const wxPoint2DInt& pos, const wxSize& size);
  192. wxRect2DInt(const wxRect2DInt& rect);
  193. // single attribute accessors
  194. wxPoint2DInt GetPosition() const;
  195. wxSize GetSize() const;
  196. // for the edge and corner accessors there are two setters counterparts, the Set.. functions keep the other corners at their
  197. // position whenever sensible, the Move.. functions keep the size of the rect and move the other corners appropriately
  198. wxInt32 GetLeft() const;
  199. void SetLeft( wxInt32 n );
  200. void MoveLeftTo( wxInt32 n );
  201. wxInt32 GetTop() const;
  202. void SetTop( wxInt32 n );
  203. void MoveTopTo( wxInt32 n );
  204. wxInt32 GetBottom() const;
  205. void SetBottom( wxInt32 n );
  206. void MoveBottomTo( wxInt32 n );
  207. wxInt32 GetRight() const;
  208. void SetRight( wxInt32 n );
  209. void MoveRightTo( wxInt32 n );
  210. wxPoint2DInt GetLeftTop() const;
  211. void SetLeftTop( const wxPoint2DInt &pt ) ;
  212. void MoveLeftTopTo( const wxPoint2DInt &pt ) ;
  213. wxPoint2DInt GetLeftBottom() const ;
  214. void SetLeftBottom( const wxPoint2DInt &pt ) ;
  215. void MoveLeftBottomTo( const wxPoint2DInt &pt ) ;
  216. wxPoint2DInt GetRightTop() const ;
  217. void SetRightTop( const wxPoint2DInt &pt ) ;
  218. void MoveRightTopTo( const wxPoint2DInt &pt ) ;
  219. wxPoint2DInt GetRightBottom() const ;
  220. void SetRightBottom( const wxPoint2DInt &pt ) ;
  221. void MoveRightBottomTo( const wxPoint2DInt &pt ) ;
  222. wxPoint2DInt GetCentre() const ;
  223. void SetCentre( const wxPoint2DInt &pt ) ;
  224. void MoveCentreTo( const wxPoint2DInt &pt ) ;
  225. wxOutCode GetOutCode( const wxPoint2DInt &pt ) const;
  226. wxOutCode GetOutcode( const wxPoint2DInt &pt ) const;
  227. bool Contains( const wxPoint2DInt &pt ) const;
  228. bool Contains( const wxRect2DInt &rect ) const;
  229. bool IsEmpty() const;
  230. bool HaveEqualSize( const wxRect2DInt &rect ) const;
  231. void Inset( wxInt32 x , wxInt32 y );
  232. void Inset( wxInt32 left , wxInt32 top ,wxInt32 right , wxInt32 bottom );
  233. void Offset( const wxPoint2DInt &pt );
  234. void ConstrainTo( const wxRect2DInt &rect );
  235. wxPoint2DInt Interpolate( wxInt32 widthfactor , wxInt32 heightfactor );
  236. static void Intersect( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
  237. void Intersect( const wxRect2DInt &otherRect );
  238. wxRect2DInt CreateIntersection( const wxRect2DInt &otherRect ) const;
  239. bool Intersects( const wxRect2DInt &rect ) const;
  240. static void Union( const wxRect2DInt &src1 , const wxRect2DInt &src2 , wxRect2DInt *dest );
  241. void Union( const wxRect2DInt &otherRect );
  242. void Union( const wxPoint2DInt &pt );
  243. wxRect2DInt CreateUnion( const wxRect2DInt &otherRect ) const;
  244. void Scale( wxInt32 f );
  245. void Scale( wxInt32 num , wxInt32 denum );
  246. wxRect2DInt& operator = (const wxRect2DInt& rect);
  247. bool operator == (const wxRect2DInt& rect) const;
  248. bool operator != (const wxRect2DInt& rect) const;
  249. wxInt32 m_x;
  250. wxInt32 m_y;
  251. wxInt32 m_width;
  252. wxInt32 m_height;
  253. };
  254. class wxTransform2D
  255. {
  256. public :
  257. virtual ~wxTransform2D();
  258. virtual void Transform( wxPoint2DInt* pt )const = 0;
  259. virtual void Transform( wxRect2DInt* r ) const;
  260. virtual wxPoint2DInt Transform( const wxPoint2DInt &pt ) const;
  261. virtual wxRect2DInt Transform( const wxRect2DInt &r ) const ;
  262. virtual void InverseTransform( wxPoint2DInt* pt ) const = 0;
  263. virtual void InverseTransform( wxRect2DInt* r ) const ;
  264. virtual wxPoint2DInt InverseTransform( const wxPoint2DInt &pt ) const ;
  265. virtual wxRect2DInt InverseTransform( const wxRect2DInt &r ) const ;
  266. };