10#if __has_include("defs.h")
43 static int tolerance ()
80 return x * p.x + y * p.y;
101 Point<T>& operator/= (
double scalar)
109 double magnitude ()
const
118 void rotate (
double angle);
125 return {p.x * scalar, p.y * scalar};
132 return p.magnitude ();
138std::ostream& operator<< (std::ostream& s,
const Point<T>& p)
140 s <<
'(' << p.x <<
',' << p.y <<
')';
167 return {x + p.x, y + p.y};
174 return {x - p.x, y - p.y};
181 return {x * scalar, y * scalar};
188 return {x / scalar, y / scalar};
203 double t = atan2 (P2.x - x, P2.y - y);
204 return (t > 0) ? t : 2 *
M_PI + t;
212 return distance (p) < point_traits<T>::tolerance ();
219 return !(p == *
this);
226 return hypot (x - P2.x, y - P2.y);
236 if (P1 == *
this || P2 == *
this)
240 ((P1.x - x) * (P2.x - x) + (P1.y - y) * (P2.y - y)) / (
distance (P1) *
distance (P2));
241 return (cang <= -1) ?
M_PI : (cang >= 1) ? 0. : acos (cang);
248 return (a.x - x) * (b.y - y) - (a.y - y) * (b.x - x) > point_traits<T>::tolerance ();
255 return ::abs ((a.x - x) * (b.y - y) - (a.y - y) * (b.x - x)) <= point_traits<T>::tolerance ();
259void Point<T>::rotate (
double angle)
261 auto [s, c] =
sincos (angle);
262 double x1 = x * c - y * s;
263 double y1 = x * s + y * c;
Generic 2D point.
Definition point.h:52
Point< T > operator+(const Point< T > &p) const
Vector addition.
Definition point.h:165
Point< T > operator*(double scalar) const
Scalar multiplication.
Definition point.h:179
Point()
Default constructor.
Definition point.h:158
bool collinear(const Point< T > &a, const Point< T > &b) const
Return true if points a, this, b are collinear.
Definition point.h:253
int operator==(const Point< T > &p) const
Return TRUE if p and this are closer than tolerance.
Definition point.h:210
Point< T > operator-() const
unary minus operator
Definition point.h:72
double distance(const Point< T > &P2) const
Return distance between this and P2.
Definition point.h:224
Point< T > operator/(double scalar) const
Scalar division.
Definition point.h:186
Point(T a, T b)
Build a Point from a pair of values.
Definition point.h:151
bool leftof(const Point< T > &a, const Point< T > &b) const
Return true if this is left of the line (a,b)
Definition point.h:246
double azimuth(const Point< T > &P2) const
Return azimuth from North of line this-P2.
Definition point.h:197
double angle(const Point< T > &P1, const Point< T > &P2) const
Return inside angle P1-this-P2.
Definition point.h:234
int operator!=(const Point< T > &p) const
Return TRUE if p and this apart by more than tolerance.
Definition point.h:217
Conversion functions and frequently used constants.
std::pair< T, T > sincos(T val)
A handy template to get sin and cos in a single function call.
Definition convert.h:267
#define M_PI
Older name for std::numbers::pi
Definition convert.h:20
double abs(const Point< T > &p)
Alias for magnitude function.
Definition point.h:130
Point< double > dpoint
Specialization of Point using double as underlining type.
Definition point.h:145
Provides default tolerance value for Point class.
Definition point.h:32