gepnt2d.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // DESCRIPTION:
  13. //
  14. // This file contains the class AcGePoint2d - A mathematical entity
  15. // used to represent a location in 2-space (implicitly) using
  16. // homogeneous co-ordinates.
  17. #ifndef AC_GEPNT2D_H
  18. #define AC_GEPNT2D_H
  19. #include "gevec2d.h"
  20. #pragma pack (push, 8)
  21. class AcGeMatrix2d;
  22. class AcGeVector2d;
  23. class AcGeLinearEnt2d;
  24. class AcGeLine2d;
  25. class
  26. GE_DLLEXPIMPORT
  27. AcGePoint2d
  28. {
  29. public:
  30. AcGePoint2d();
  31. AcGePoint2d(const AcGePoint2d& pnt);
  32. AcGePoint2d(double x, double y);
  33. // The origin, or (0, 0).
  34. //
  35. static const AcGePoint2d kOrigin;
  36. // Matrix multiplication.
  37. //
  38. friend
  39. GE_DLLEXPIMPORT
  40. AcGePoint2d operator * (const AcGeMatrix2d& mat, const AcGePoint2d& pnt);
  41. AcGePoint2d& setToProduct(const AcGeMatrix2d& mat, const AcGePoint2d& pnt);
  42. AcGePoint2d& transformBy (const AcGeMatrix2d& leftSide);
  43. AcGePoint2d& rotateBy (double angle, const AcGePoint2d& wrtPoint
  44. = AcGePoint2d::kOrigin);
  45. AcGePoint2d& mirror (const AcGeLine2d& line);
  46. AcGePoint2d& scaleBy (double scaleFactor, const AcGePoint2d& wrtPoint
  47. = AcGePoint2d::kOrigin);
  48. // Scale multiplication.
  49. //
  50. AcGePoint2d operator * (double) const;
  51. friend
  52. AcGePoint2d operator * (double, const AcGePoint2d& scl);
  53. AcGePoint2d& operator *= (double scl);
  54. AcGePoint2d operator / (double scl) const;
  55. AcGePoint2d& operator /= (double scl);
  56. // Translation by a vector.
  57. //
  58. AcGePoint2d operator + (const AcGeVector2d& vec) const;
  59. AcGePoint2d& operator += (const AcGeVector2d& vec);
  60. AcGePoint2d operator - (const AcGeVector2d& vec) const;
  61. AcGePoint2d& operator -= (const AcGeVector2d& vec);
  62. AcGePoint2d& setToSum (const AcGePoint2d& pnt, const AcGeVector2d& vec);
  63. // Get vector between two points.
  64. //
  65. AcGeVector2d operator - (const AcGePoint2d& pnt) const;
  66. AcGeVector2d asVector () const;
  67. // Distance to other geometric objects.
  68. //
  69. double distanceTo (const AcGePoint2d& pnt) const;
  70. // Tests for equivalence using the Euclidean norm.
  71. //
  72. bool operator == (const AcGePoint2d& pnt) const;
  73. bool operator != (const AcGePoint2d& pnt) const;
  74. bool isEqualTo (const AcGePoint2d& pnt,
  75. const AcGeTol& tol = AcGeContext::gTol) const;
  76. // For convenient access to the data.
  77. //
  78. double operator [] (unsigned int i) const;
  79. double& operator [] (unsigned int idx);
  80. AcGePoint2d& set (double x, double y);
  81. // The co-ordinates of the point.
  82. //
  83. double x, y;
  84. };
  85. // Creates a point at the origin.
  86. //
  87. inline
  88. AcGePoint2d::AcGePoint2d() : x(0.0), y(0.0)
  89. {
  90. }
  91. inline
  92. AcGePoint2d::AcGePoint2d(const AcGePoint2d& src) : x(src.x), y(src.y)
  93. {
  94. }
  95. // Creates a point intialized to ( xx, yy ).
  96. //
  97. inline
  98. AcGePoint2d::AcGePoint2d(double xx, double yy) : x(xx), y(yy)
  99. {
  100. }
  101. inline bool
  102. AcGePoint2d::operator == (const AcGePoint2d& p) const
  103. {
  104. return this->isEqualTo(p);
  105. }
  106. // This operator is the logical negation of the `==' operator.
  107. //
  108. inline bool
  109. AcGePoint2d::operator != (const AcGePoint2d& p) const
  110. {
  111. return !this->isEqualTo(p);
  112. }
  113. // Returns a point such that each of the coordinates of this point
  114. // have been multiplied by val.
  115. //
  116. inline AcGePoint2d
  117. AcGePoint2d::operator * (double val) const
  118. {
  119. return AcGePoint2d(x*val, y*val);
  120. }
  121. // Returns a point such that each of the coordinates of this point
  122. // have been multiplied by val.
  123. //
  124. inline AcGePoint2d
  125. operator * (double val, const AcGePoint2d& p)
  126. {
  127. return AcGePoint2d(p.x*val, p.y*val);
  128. }
  129. // This is equivalent to the statement `p = p * val;'
  130. // Each coordinate of this point is multiplied by val.
  131. //
  132. inline AcGePoint2d&
  133. AcGePoint2d::operator *= (double val)
  134. {
  135. x *= val;
  136. y *= val;
  137. return *this;
  138. }
  139. // Returns a point such that each of the coordinates of this point
  140. // have been divided by val.
  141. //
  142. inline AcGePoint2d
  143. AcGePoint2d::operator / (double val) const
  144. {
  145. return AcGePoint2d (x/val, y/val);
  146. }
  147. // This is equivalent to the statement `p = p / val;'
  148. // Each coordinate of this point is divided by val.
  149. //
  150. inline AcGePoint2d&
  151. AcGePoint2d::operator /= (double val)
  152. {
  153. x /= val;
  154. y /= val;
  155. return *this;
  156. }
  157. // Returns a point that is equivalent to the result of translating
  158. // this point by the vector `v'. (It yields the same result as if
  159. // the vector had been cast to a translation matrix and then
  160. // multiplied with the point.)
  161. //
  162. inline AcGePoint2d
  163. AcGePoint2d::operator + (const AcGeVector2d& v) const
  164. {
  165. return AcGePoint2d(x + v.x, y + v.y);
  166. }
  167. // This is equivalent to the statement `p = p + v;'
  168. //
  169. inline AcGePoint2d&
  170. AcGePoint2d::operator += (const AcGeVector2d& v)
  171. {
  172. x += v.x;
  173. y += v.y;
  174. return *this;
  175. }
  176. // This is equivalent to the statement `p + (-v);'
  177. //
  178. inline AcGePoint2d
  179. AcGePoint2d::operator - (const AcGeVector2d& v) const
  180. {
  181. return AcGePoint2d(x - v.x, y - v.y);
  182. }
  183. // This is equivalent to the statement `p = p - v;'
  184. //
  185. inline AcGePoint2d&
  186. AcGePoint2d::operator -= (const AcGeVector2d& v)
  187. {
  188. x -= v.x;
  189. y -= v.y;
  190. return *this;
  191. }
  192. // This operator returns a vector such that if `v = p1 - p0',
  193. // then, `v' is equivalent to the translation that takes
  194. // `p0' to `p1'. (This point is `p1').
  195. //
  196. inline AcGeVector2d
  197. AcGePoint2d::operator - (const AcGePoint2d& p) const
  198. {
  199. return AcGeVector2d(x - p.x, y - p.y);
  200. }
  201. // This operator returns the vector that would have resulted
  202. // from the operation `p1 - AcGePoint2d::kOrigin', which is
  203. // a common operation to perform.
  204. //
  205. inline AcGeVector2d
  206. AcGePoint2d::asVector() const
  207. {
  208. return AcGeVector2d(x, y);
  209. }
  210. // Sets the point to ( xx, yy ).
  211. //
  212. inline AcGePoint2d&
  213. AcGePoint2d::set(double xx, double yy)
  214. {
  215. x = xx;
  216. y = yy;
  217. return *this;
  218. }
  219. // Indexes the point as if it were an array. `x' is index `0',
  220. // `y' is index `1'.
  221. //
  222. inline double
  223. AcGePoint2d::operator [] (unsigned int i) const
  224. {
  225. return *(&x+i);
  226. }
  227. inline double&
  228. AcGePoint2d::operator [] (unsigned int i)
  229. {
  230. return *(&x+i);
  231. }
  232. #define ADSK_ACGEPOINT2D_DEFINED
  233. #include "acarrayhelper.h"
  234. #pragma pack (pop)
  235. #endif