~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/libnr/nr-point.h

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef SEEN_NR_POINT_H
 
2
#define SEEN_NR_POINT_H
 
3
 
 
4
/** \file
 
5
 * Cartesian point class.
 
6
 */
 
7
 
 
8
//#include <math.h>
 
9
//#include <stdexcept>
 
10
#include <iostream>
 
11
//#include <iomanip>
 
12
 
 
13
#include <libnr/nr-coord.h>
 
14
#include <libnr/nr-dim2.h>
 
15
#include <libnr/nr-forward.h>
 
16
 
 
17
//#include "round.h"
 
18
#include "decimal-round.h"
 
19
 
 
20
#include <2geom/point.h>
 
21
 
 
22
namespace NR {
 
23
 
 
24
/// Cartesian point.
 
25
class Point {
 
26
public:
 
27
    inline Point()
 
28
    { _pt[X] = _pt[Y] = 0; }
 
29
 
 
30
    inline Point(Coord x, Coord y) {
 
31
        _pt[X] = x;
 
32
        _pt[Y] = y;
 
33
    }
 
34
 
 
35
    inline Point(Point const &p) {
 
36
        for (unsigned i = 0; i < 2; ++i) {
 
37
            _pt[i] = p._pt[i];
 
38
        }
 
39
    }
 
40
 
 
41
    inline Point(Geom::Point const &p) {
 
42
        _pt[X] = p[Geom::X];
 
43
        _pt[Y] = p[Geom::Y];
 
44
    }
 
45
 
 
46
    inline Point &operator=(Point const &p) {
 
47
        for (unsigned i = 0; i < 2; ++i) {
 
48
            _pt[i] = p._pt[i];
 
49
        }
 
50
        return *this;
 
51
    }
 
52
 
 
53
    inline Coord operator[](unsigned i) const {
 
54
        return _pt[i];
 
55
    }
 
56
 
 
57
    inline Coord &operator[](unsigned i) {
 
58
        return _pt[i];
 
59
    }
 
60
 
 
61
    Coord operator[](Dim2 d) const throw() { return _pt[d]; }
 
62
    Coord &operator[](Dim2 d) throw() { return _pt[d]; }
 
63
 
 
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.)
 
67
    **/
 
68
    Point ccw() const {
 
69
        return Point(_pt[Y], -_pt[X]);
 
70
    }
 
71
 
 
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.)
 
75
    **/
 
76
    Point cw() const {
 
77
        return Point(-_pt[Y], _pt[X]);
 
78
    }
 
79
 
 
80
    /**
 
81
        \brief A function to lower the precision of the point
 
82
        \param  places  The number of decimal places that should be in
 
83
                        the final number.
 
84
    */
 
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));
 
88
        return;
 
89
    }
 
90
 
 
91
    void normalize();
 
92
 
 
93
    inline Point &operator+=(Point const &o) {
 
94
        for ( unsigned i = 0 ; i < 2 ; ++i ) {
 
95
            _pt[i] += o._pt[i];
 
96
        }
 
97
        return *this;
 
98
    }
 
99
  
 
100
    inline Point &operator-=(Point const &o) {
 
101
        for ( unsigned i = 0 ; i < 2 ; ++i ) {
 
102
            _pt[i] -= o._pt[i];
 
103
        }
 
104
        return *this;
 
105
    }
 
106
  
 
107
    inline Point &operator/=(double const s) {
 
108
        for ( unsigned i = 0 ; i < 2 ; ++i ) {
 
109
            _pt[i] /= s;
 
110
        }
 
111
        return *this;
 
112
    }
 
113
 
 
114
    inline Point &operator*=(double const s) {
 
115
        for ( unsigned i = 0 ; i < 2 ; ++i ) {
 
116
            _pt[i] *= s;
 
117
        }
 
118
        return *this;
 
119
    }
 
120
 
 
121
    Point &operator*=(Matrix const &m);
 
122
 
 
123
    inline int operator == (const Point &in_pnt) {
 
124
        return ((_pt[X] == in_pnt[X]) && (_pt[Y] == in_pnt[Y]));
 
125
    }
 
126
 
 
127
    friend inline std::ostream &operator<< (std::ostream &out_file, const NR::Point &in_pnt);
 
128
 
 
129
    inline operator Geom::Point() const { return Geom::Point(_pt[X], _pt[Y]); }
 
130
 
 
131
private:
 
132
    Coord _pt[2];
 
133
};
 
134
 
 
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];
 
139
    return out_file;
 
140
}
 
141
 
 
142
} /* namespace NR */
 
143
 
 
144
#endif /* !SEEN_NR_POINT_H */
 
145
 
 
146
/*
 
147
  Local Variables:
 
148
  mode:c++
 
149
  c-file-style:"stroustrup"
 
150
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
151
  indent-tabs-mode:nil
 
152
  fill-column:99
 
153
  End:
 
154
*/
 
155
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :