1 #ifndef SEEN_Geom_POINT_H
2 #define SEEN_Geom_POINT_H
15 enum Dim2 { X=0, Y=1 };
25 { _pt[X] = _pt[Y] = 0; }
28 _pt[X] = x; _pt[Y] = y;
32 for (
unsigned i = 0; i < 2; ++i)
37 for (
unsigned i = 0; i < 2; ++i)
42 inline Coord operator[](
unsigned i)
const {
return _pt[i]; }
43 inline Coord &operator[](
unsigned i) {
return _pt[i]; }
45 Coord operator[](Dim2 d)
const throw() {
return _pt[d]; }
46 Coord &operator[](Dim2 d)
throw() {
return _pt[d]; }
49 return Point(radius * std::cos(angle), radius * std::sin(angle));
52 inline Coord length()
const {
return hypot(_pt[0], _pt[1]); }
59 return Point(_pt[Y], -_pt[X]);
67 return Point(-_pt[Y], _pt[X]);
75 inline void round (
int places = 0) {
84 return Point(_pt[X] + o._pt[X], _pt[Y] + o._pt[Y]);
86 inline Point operator-(Point
const &o)
const {
87 return Point(_pt[X] - o._pt[X], _pt[Y] - o._pt[Y]);
89 inline Point &operator+=(Point
const &o) {
90 for (
unsigned i = 0 ; i < 2 ; ++i ) {
95 inline Point &operator-=(Point
const &o) {
96 for (
unsigned i = 0 ; i < 2 ; ++i ) {
102 inline Point operator-()
const {
103 return Point(-_pt[X], -_pt[Y]);
105 inline Point operator*(
double const s)
const {
106 return Point(_pt[X] * s, _pt[Y] * s);
108 inline Point operator/(
double const s)
const {
110 return Point(_pt[X] / s, _pt[Y] / s);
112 inline Point &operator*=(
double const s) {
113 for (
unsigned i = 0 ; i < 2 ; ++i ) _pt[i] *= s;
116 inline Point &operator/=(
double const s) {
118 for (
unsigned i = 0 ; i < 2 ; ++i ) _pt[i] /= s;
122 Point &operator*=(Matrix
const &m);
124 inline int operator == (
const Point &in_pnt) {
125 return ((_pt[X] == in_pnt[X]) && (_pt[Y] == in_pnt[Y]));
131 inline Point operator*(
double const s, Point
const &p) {
return p * s; }
135 inline std::ostream &operator<< (std::ostream &out_file,
const Geom::Point &in_pnt) {
136 out_file <<
"X: " << in_pnt[X] <<
" Y: " << in_pnt[Y];
142 Point const ret(a[0] * b[0] - a[1] * b[1],
143 a[1] * b[0] + a[0] * b[1]);
148 inline bool operator==(Point
const &a, Point
const &b) {
149 return (a[X] == b[X]) && (a[Y] == b[Y]);
151 inline bool operator!=(Point
const &a, Point
const &b) {
152 return (a[X] != b[X]) || (a[Y] != b[Y]);
157 return ( ( a[Y] < b[Y] ) ||
158 (( a[Y] == b[Y] ) && ( a[X] < b[X] )));
169 double LInfty(Point
const &p);
171 bool is_unit_vector(Point
const &p);
173 extern double atan2(Point
const p);
178 inline bool are_near(Point
const &a, Point
const &b,
double const eps=EPSILON) {
179 return ( are_near(a[X],b[X],eps) && are_near(a[Y],b[Y],eps) );
195 inline Point lerp(
double const t,
Point const a,
Point const b) {
return (a * (1 - t) + b * t); }
200 inline Coord dot(
Point const &a,
Point const &b) {
return a[0] * b[0] + a[1] * b[1]; }
210 Point abs(Point
const &b);
212 Point operator*(Point
const &v, Matrix
const &m);
214 Point operator/(Point
const &p, Matrix
const &m);
double decimal_round(double const x, int const places)
Definition: utils.h:73
Point ccw() const
Definition: point.h:58
double Coord
Definition: coord.h:45
Point unit_vector(Point const &a)
Definition: point.cpp:123
Coord angle_between(Point const a, Point const b)
Definition: point.cpp:108
bool operator<=(Point const &a, Point const &b)
Definition: point.h:156
void normalize()
Definition: point.cpp:20
friend std::ostream & operator<<(std::ostream &out_file, const Geom::Point &in_pnt)
Definition: point.h:135
Coord LInfty(Point const &p)
Definition: point.cpp:73
Coord distance(Point const &a, Point const &b)
Definition: point.h:205
void round(int places=0)
A function to lower the precision of the point.
Definition: point.h:75
Point operator^(Point const &a, Point const &b)
Definition: point.h:141
Cartesian point.
Definition: point.h:20
Coord L2sq(Point const &p)
Definition: point.h:167
Coord distanceSq(Point const &a, Point const &b)
Definition: point.h:208
bool is_zero(Point const &p)
Definition: point.cpp:86
Point cw() const
Definition: point.h:66
Coord L1(Point const &p)
Definition: point.cpp:64