123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- //
- //////////////////////////////////////////////////////////////////////////////
- //
- // Copyright 2015 Autodesk, Inc. All rights reserved.
- //
- // Use of this software is subject to the terms of the Autodesk license
- // agreement provided at the time of installation or download, or which
- // otherwise accompanies this software in either electronic or hard copy form.
- //
- //////////////////////////////////////////////////////////////////////////////
- //
- // DESCRIPTION:
- //
- // This file contains the class AcGePoint2d - A mathematical entity
- // used to represent a location in 2-space (implicitly) using
- // homogeneous co-ordinates.
- #ifndef AC_GEPNT2D_H
- #define AC_GEPNT2D_H
- #include "gevec2d.h"
- #pragma pack (push, 8)
- class AcGeMatrix2d;
- class AcGeVector2d;
- class AcGeLinearEnt2d;
- class AcGeLine2d;
- class
- GE_DLLEXPIMPORT
- AcGePoint2d
- {
- public:
- AcGePoint2d();
- AcGePoint2d(const AcGePoint2d& pnt);
- AcGePoint2d(double x, double y);
- // The origin, or (0, 0).
- //
- static const AcGePoint2d kOrigin;
- // Matrix multiplication.
- //
- friend
- GE_DLLEXPIMPORT
- AcGePoint2d operator * (const AcGeMatrix2d& mat, const AcGePoint2d& pnt);
- AcGePoint2d& setToProduct(const AcGeMatrix2d& mat, const AcGePoint2d& pnt);
- AcGePoint2d& transformBy (const AcGeMatrix2d& leftSide);
- AcGePoint2d& rotateBy (double angle, const AcGePoint2d& wrtPoint
- = AcGePoint2d::kOrigin);
- AcGePoint2d& mirror (const AcGeLine2d& line);
- AcGePoint2d& scaleBy (double scaleFactor, const AcGePoint2d& wrtPoint
- = AcGePoint2d::kOrigin);
- // Scale multiplication.
- //
- AcGePoint2d operator * (double) const;
- friend
- AcGePoint2d operator * (double, const AcGePoint2d& scl);
- AcGePoint2d& operator *= (double scl);
- AcGePoint2d operator / (double scl) const;
- AcGePoint2d& operator /= (double scl);
- // Translation by a vector.
- //
- AcGePoint2d operator + (const AcGeVector2d& vec) const;
- AcGePoint2d& operator += (const AcGeVector2d& vec);
- AcGePoint2d operator - (const AcGeVector2d& vec) const;
- AcGePoint2d& operator -= (const AcGeVector2d& vec);
- AcGePoint2d& setToSum (const AcGePoint2d& pnt, const AcGeVector2d& vec);
- // Get vector between two points.
- //
- AcGeVector2d operator - (const AcGePoint2d& pnt) const;
- AcGeVector2d asVector () const;
- // Distance to other geometric objects.
- //
- double distanceTo (const AcGePoint2d& pnt) const;
- // Tests for equivalence using the Euclidean norm.
- //
- bool operator == (const AcGePoint2d& pnt) const;
- bool operator != (const AcGePoint2d& pnt) const;
- bool isEqualTo (const AcGePoint2d& pnt,
- const AcGeTol& tol = AcGeContext::gTol) const;
- // For convenient access to the data.
- //
- double operator [] (unsigned int i) const;
- double& operator [] (unsigned int idx);
- AcGePoint2d& set (double x, double y);
- // The co-ordinates of the point.
- //
- double x, y;
- };
- // Creates a point at the origin.
- //
- inline
- AcGePoint2d::AcGePoint2d() : x(0.0), y(0.0)
- {
- }
- inline
- AcGePoint2d::AcGePoint2d(const AcGePoint2d& src) : x(src.x), y(src.y)
- {
- }
- // Creates a point intialized to ( xx, yy ).
- //
- inline
- AcGePoint2d::AcGePoint2d(double xx, double yy) : x(xx), y(yy)
- {
- }
- inline bool
- AcGePoint2d::operator == (const AcGePoint2d& p) const
- {
- return this->isEqualTo(p);
- }
- // This operator is the logical negation of the `==' operator.
- //
- inline bool
- AcGePoint2d::operator != (const AcGePoint2d& p) const
- {
- return !this->isEqualTo(p);
- }
- // Returns a point such that each of the coordinates of this point
- // have been multiplied by val.
- //
- inline AcGePoint2d
- AcGePoint2d::operator * (double val) const
- {
- return AcGePoint2d(x*val, y*val);
- }
- // Returns a point such that each of the coordinates of this point
- // have been multiplied by val.
- //
- inline AcGePoint2d
- operator * (double val, const AcGePoint2d& p)
- {
- return AcGePoint2d(p.x*val, p.y*val);
- }
- // This is equivalent to the statement `p = p * val;'
- // Each coordinate of this point is multiplied by val.
- //
- inline AcGePoint2d&
- AcGePoint2d::operator *= (double val)
- {
- x *= val;
- y *= val;
- return *this;
- }
- // Returns a point such that each of the coordinates of this point
- // have been divided by val.
- //
- inline AcGePoint2d
- AcGePoint2d::operator / (double val) const
- {
- return AcGePoint2d (x/val, y/val);
- }
- // This is equivalent to the statement `p = p / val;'
- // Each coordinate of this point is divided by val.
- //
- inline AcGePoint2d&
- AcGePoint2d::operator /= (double val)
- {
- x /= val;
- y /= val;
- return *this;
- }
- // Returns a point that is equivalent to the result of translating
- // this point by the vector `v'. (It yields the same result as if
- // the vector had been cast to a translation matrix and then
- // multiplied with the point.)
- //
- inline AcGePoint2d
- AcGePoint2d::operator + (const AcGeVector2d& v) const
- {
- return AcGePoint2d(x + v.x, y + v.y);
- }
- // This is equivalent to the statement `p = p + v;'
- //
- inline AcGePoint2d&
- AcGePoint2d::operator += (const AcGeVector2d& v)
- {
- x += v.x;
- y += v.y;
- return *this;
- }
- // This is equivalent to the statement `p + (-v);'
- //
- inline AcGePoint2d
- AcGePoint2d::operator - (const AcGeVector2d& v) const
- {
- return AcGePoint2d(x - v.x, y - v.y);
- }
- // This is equivalent to the statement `p = p - v;'
- //
- inline AcGePoint2d&
- AcGePoint2d::operator -= (const AcGeVector2d& v)
- {
- x -= v.x;
- y -= v.y;
- return *this;
- }
- // This operator returns a vector such that if `v = p1 - p0',
- // then, `v' is equivalent to the translation that takes
- // `p0' to `p1'. (This point is `p1').
- //
- inline AcGeVector2d
- AcGePoint2d::operator - (const AcGePoint2d& p) const
- {
- return AcGeVector2d(x - p.x, y - p.y);
- }
- // This operator returns the vector that would have resulted
- // from the operation `p1 - AcGePoint2d::kOrigin', which is
- // a common operation to perform.
- //
- inline AcGeVector2d
- AcGePoint2d::asVector() const
- {
- return AcGeVector2d(x, y);
- }
- // Sets the point to ( xx, yy ).
- //
- inline AcGePoint2d&
- AcGePoint2d::set(double xx, double yy)
- {
- x = xx;
- y = yy;
- return *this;
- }
- // Indexes the point as if it were an array. `x' is index `0',
- // `y' is index `1'.
- //
- inline double
- AcGePoint2d::operator [] (unsigned int i) const
- {
- return *(&x+i);
- }
- inline double&
- AcGePoint2d::operator [] (unsigned int i)
- {
- return *(&x+i);
- }
- #define ADSK_ACGEPOINT2D_DEFINED
- #include "acarrayhelper.h"
- #pragma pack (pop)
- #endif
|