point.h revision a4030d5ca449e7e384bc699cd249ee704faaeab0
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen * \brief Defines a Cartesian 2D Point class.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti/// Cartesian 2D point.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti /// The default constructor creates an Point(0,0) DO NOT RELY ON THIS, BEST NOT TO USE THIS CONSTRUCTOR
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for (unsigned i = 0; i < 2; ++i)
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen for (unsigned i = 0; i < 2; ++i)
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti inline Coord operator[](unsigned i) const { return _pt[i]; }
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen inline Coord &operator[](unsigned i) { return _pt[i]; }
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen Coord operator[](Dim2 d) const throw() { return _pt[d]; }
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen Coord &operator[](Dim2 d) throw() { return _pt[d]; }
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen static inline Point polar(Coord angle, Coord radius) {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return Point(radius * std::cos(angle), radius * std::sin(angle));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen inline Coord length() const { return hypot(_pt[0], _pt[1]); }
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen /** Return a point like this point but rotated -90 degrees.
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti (If the y axis grows downwards and the x axis grows to the
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen right, then this is 90 degrees counter-clockwise.)
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen /** Return a point like this point but rotated +90 degrees.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen (If the y axis grows downwards and the x axis grows to the
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen right, then this is 90 degrees clockwise.)
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen \brief A function to lower the precision of the point
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen \param places The number of decimal places that should be in
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen the final number.
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen _pt[X] = (Coord)(decimal_round((double)_pt[X], places));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen _pt[Y] = (Coord)(decimal_round((double)_pt[Y], places));
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen inline bool isFinite() const {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen for ( unsigned i = 0 ; i < 2 ; ++i ) {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen inline Point operator+(Point const &o) const {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return Point(_pt[X] + o._pt[X], _pt[Y] + o._pt[Y]);
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen inline Point operator-(Point const &o) const {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen return Point(_pt[X] - o._pt[X], _pt[Y] - o._pt[Y]);
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen for ( unsigned i = 0 ; i < 2 ; ++i ) {
d37634d73670180f99a3e0ea583621373d90ec4fJohan Engelen for ( unsigned i = 0 ; i < 2 ; ++i ) {
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti //TODO: s == 0?
6e16a663ee96cd1329e48518138efb415046d9f6mcecchetti for ( unsigned i = 0 ; i < 2 ; ++i ) _pt[i] *= s;
a4030d5ca449e7e384bc699cd249ee704faaeab0Chris Morgan //TODO: s == 0?
return *this;
return out_file;
return ret;
/** This is a lexicographical ordering for points. It is remarkably useful for sweepline algorithms*/
/** Defined as dot(a, b.cw()). */
Point constrain_angle(Point const &A, Point const &B, unsigned int n = 4, Geom::Point const &dir = Geom::Point(1,0));