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 }
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 private:
78 ICoord _pt[2];
79 };
82 } // namespace NR
84 #endif /* !SEEN_NR_POINT_L_H */
86 /*
87 Local Variables:
88 mode:c++
89 c-file-style:"stroustrup"
90 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91 indent-tabs-mode:nil
92 fill-column:99
93 End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :