1
#ifndef SEEN_NR_POINT_H
2
#define SEEN_NR_POINT_H
5
* Cartesian point class.
13
#include <libnr/nr-coord.h>
14
#include <libnr/nr-dim2.h>
15
#include <libnr/nr-forward.h>
18
#include "decimal-round.h"
20
#include <2geom/point.h>
28
{ _pt[X] = _pt[Y] = 0; }
30
inline Point(Coord x, Coord y) {
35
inline Point(Point const &p) {
36
for (unsigned i = 0; i < 2; ++i) {
41
inline Point(Geom::Point const &p) {
46
inline Point &operator=(Point const &p) {
47
for (unsigned i = 0; i < 2; ++i) {
53
inline Coord operator[](unsigned i) const {
57
inline Coord &operator[](unsigned i) {
61
Coord operator[](Dim2 d) const throw() { return _pt[d]; }
62
Coord &operator[](Dim2 d) throw() { return _pt[d]; }
64
/** Return a point like this point but rotated -90 degrees.
65
(If the y axis grows downwards and the x axis grows to the
66
right, then this is 90 degrees counter-clockwise.)
69
return Point(_pt[Y], -_pt[X]);
72
/** Return a point like this point but rotated +90 degrees.
73
(If the y axis grows downwards and the x axis grows to the
74
right, then this is 90 degrees clockwise.)
77
return Point(-_pt[Y], _pt[X]);
81
\brief A function to lower the precision of the point
82
\param places The number of decimal places that should be in
85
inline void round (int places = 0) {
86
_pt[X] = (Coord)(Inkscape::decimal_round((double)_pt[X], places));
87
_pt[Y] = (Coord)(Inkscape::decimal_round((double)_pt[Y], places));
93
inline Point &operator+=(Point const &o) {
94
for ( unsigned i = 0 ; i < 2 ; ++i ) {
100
inline Point &operator-=(Point const &o) {
101
for ( unsigned i = 0 ; i < 2 ; ++i ) {
107
inline Point &operator/=(double const s) {
108
for ( unsigned i = 0 ; i < 2 ; ++i ) {
114
inline Point &operator*=(double const s) {
115
for ( unsigned i = 0 ; i < 2 ; ++i ) {
121
Point &operator*=(Matrix const &m);
123
inline int operator == (const Point &in_pnt) {
124
return ((_pt[X] == in_pnt[X]) && (_pt[Y] == in_pnt[Y]));
127
friend inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt);
129
inline operator Geom::Point() const { return Geom::Point(_pt[X], _pt[Y]); }
135
/** A function to print out the Point. It just prints out the coords
136
on the given output stream */
137
inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt) {
138
out_file << "X: " << in_pnt[X] << " Y: " << in_pnt[Y];
144
#endif /* !SEEN_NR_POINT_H */
149
c-file-style:"stroustrup"
150
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
155
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :