9#if __has_include("defs.h")
13#define _USE_MATH_DEFINES
41 static int tolerance ()
63 return {x + p.x, y + p.y};
65 Point<T>
operator- (
const Point<T>& p)
const
67 return {x - p.x, y - p.y};
69 Point<T> operator* (
double scalar)
const
71 return {x * scalar, y * scalar};
73 Point<T> operator/ (
double scalar)
const
75 return {x / scalar, y / scalar};
87 return x * p.x + y * p.y;
96 Point<T>& operator-= (
const Point<T>& other)
102 Point<T>& operator*= (
double scalar)
108 Point<T>& operator/= (
double scalar)
116 double magnitude ()
const
125 void rotate (
double angle);
132 return {p.x * scalar, p.y * scalar};
139 return p.magnitude ();
145std::ostream& operator<< (std::ostream& s,
const Point<T>& p)
147 s <<
'(' << p.x <<
',' << p.y <<
')';
182 double t = atan2 (P2.x - x, P2.y - y);
183 return (t > 0) ? t : 2 * M_PI + t;
198 return !(p == *
this);
205 return hypot (x - P2.x, y - P2.y);
217 if (P1 == *
this || P2 == *
this)
221 ((P1.x - x) * (P2.x - x) + (P1.y - y) * (P2.y - y)) / (distance (P1) * distance (P2));
222 return (cang <= -1) ? M_PI : (cang >= 1) ? 0. : acos (cang);
243 double x1 = x * (c = cos (angle)) - y * (s = sin (angle));
244 double y1 = x * s + y * c;
Generic 2D point.
Definition point.h:50
Point()
Default constructor.
Definition point.h:165
bool collinear(const Point< T > &a, const Point< T > &b) const
Return true if points a, this, b are collinear.
Definition point.h:234
int operator==(const Point< T > &p) const
Return TRUE if p and this are closer than tolerance.
Definition point.h:189
Point< T > operator-() const
unary minus operator
Definition point.h:79
double distance(const Point< T > &P2) const
Return distance between this and P2.
Definition point.h:203
Point(T a, T b)
Build a Point from a pair of T's.
Definition point.h:158
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:227
double azimuth(const Point< T > &P2) const
Return azimuth from North of line this-P2.
Definition point.h:176
double angle(const Point< T > &P1, const Point< T > &P2) const
Return inside angle P1-this-P2.
Definition point.h:215
int operator!=(const Point< T > &p) const
Return TRUE if p and this apart by more than tolerance.
Definition point.h:196
double abs(const Point< T > &p)
Alias for magnitude function.
Definition point.h:137