9#if __has_include("defs.h")
42 static int tolerance ()
67 return {x + p.x, y + p.y};
71 return {x - p.x, y - p.y};
73 Point<T> operator* (
double scalar)
const
75 return {x * scalar, y * scalar};
77 Point<T> operator/ (
double scalar)
const
79 return {x / scalar, y / scalar};
91 return x * p.x + y * p.y;
106 Point<T>& operator*= (
double scalar)
112 Point<T>& operator/= (
double scalar)
120 double magnitude ()
const
129 void rotate (
double angle);
136 return {p.x * scalar, p.y * scalar};
143 return p.magnitude ();
149std::ostream& operator<< (std::ostream& s,
const Point<T>& p)
151 s <<
'(' << p.x <<
',' << p.y <<
')';
185 double t = atan2 (P2.x - x, P2.y - y);
186 return (t > 0) ? t : 2 * M_PI + t;
194 return distance (p) < point_traits<T>::tolerance ();
201 return !(p == *
this);
208 return hypot (x - P2.x, y - P2.y);
218 if (P1 == *
this || P2 == *
this)
222 ((P1.x - x) * (P2.x - x) + (P1.y - y) * (P2.y - y)) / (
distance (P1) *
distance (P2));
223 return (cang <= -1) ? M_PI : (cang >= 1) ? 0. : acos (cang);
230 return (a.x - x) * (b.y - y) - (a.y - y) * (b.x - x) > point_traits<T>::tolerance ();
237 return ::abs ((a.x - x) * (b.y - y) - (a.y - y) * (b.x - x)) <= point_traits<T>::tolerance ();
241void Point<T>::rotate (
double angle)
243 auto [s, c] =
sincos (angle);
244 double x1 = x * c - y * s;
245 double y1 = x * s + y * c;
Generic 2D point.
Definition point.h:51
Point()
Default constructor.
Definition point.h:169
bool collinear(const Point< T > &a, const Point< T > &b) const
Return true if points a, this, b are collinear.
Definition point.h:235
int operator==(const Point< T > &p) const
Return TRUE if p and this are closer than tolerance.
Definition point.h:192
Point< T > operator-() const
unary minus operator
Definition point.h:83
double distance(const Point< T > &P2) const
Return distance between this and P2.
Definition point.h:206
Point(T a, T b)
Build a Point from a pair of T's.
Definition point.h:162
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:228
double azimuth(const Point< T > &P2) const
Return azimuth from North of line this-P2.
Definition point.h:179
double angle(const Point< T > &P1, const Point< T > &P2) const
Return inside angle P1-this-P2.
Definition point.h:216
int operator!=(const Point< T > &p) const
Return TRUE if p and this apart by more than tolerance.
Definition point.h:199
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:265
double abs(const Point< T > &p)
Alias for magnitude function.
Definition point.h:141
Point< double > dpoint
Specialization of Point using double as underlining type.
Definition point.h:156
Provides default tolerance value for Point class.
Definition point.h:31