Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / libnr / nr-point-l.h
1 #ifndef SEEN_NR_POINT_L_H
2 #define SEEN_NR_POINT_L_H
4 #include <stdexcept>
5 #include <libnr/nr-i-coord.h>
6 #include <libnr/nr-point.h>
8 struct NRPointL {
9     NR::ICoord x, y;
10 };
12 namespace NR {
14 class IPoint {
15 public:
16     IPoint()
17     { }
19     IPoint(ICoord x, ICoord y) {
20         _pt[X] = x;
21         _pt[Y] = y;
22     }
24     IPoint(NRPointL const &p) {
25         _pt[X] = p.x;
26         _pt[Y] = p.y;
27     }
29     IPoint(IPoint const &p) {
30         for (unsigned i = 0; i < 2; ++i) {
31             _pt[i] = p._pt[i];
32         }
33     }
35     IPoint &operator=(IPoint const &p) {
36         for (unsigned i = 0; i < 2; ++i) {
37             _pt[i] = p._pt[i];
38         }
39         return *this;
40     }
42     operator Point() {
43         return Point(_pt[X], _pt[Y]);
44     }
46     ICoord operator[](unsigned i) const throw(std::out_of_range) {
47         if ( i > Y ) {
48             throw std::out_of_range("index out of range");
49         }
50         return _pt[i];
51     }
53     ICoord &operator[](unsigned i) throw(std::out_of_range) {
54         if ( i > Y ) {
55             throw std::out_of_range("index out of range");
56         }
57         return _pt[i];
58     }
60     ICoord operator[](Dim2 d) const throw() { return _pt[d]; }
61     ICoord &operator[](Dim2 d) throw() { return _pt[d]; }
63     IPoint &operator+=(IPoint const &o) {
64         for ( unsigned i = 0 ; i < 2 ; ++i ) {
65             _pt[i] += o._pt[i];
66         }
67         return *this;
68     }
69   
70     IPoint &operator-=(IPoint const &o) {
71         for ( unsigned i = 0 ; i < 2 ; ++i ) {
72             _pt[i] -= o._pt[i];
73         }
74         return *this;
75     }
77     bool operator==(IPoint const &other) const {
78         return _pt[X] == other[X] && _pt[Y] == other[Y];
79     }
81     bool operator!=(IPoint const &other) const {
82         return _pt[X] != other[X] || _pt[Y] != other[Y];
83     }
85 private:
86     ICoord _pt[2];
87 };
90 }  // namespace NR
92 #endif /* !SEEN_NR_POINT_L_H */
94 /*
95   Local Variables:
96   mode:c++
97   c-file-style:"stroustrup"
98   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
99   indent-tabs-mode:nil
100   fill-column:99
101   End:
102 */
103 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :