1 /* operator functions for NR::Point. */
2 #ifndef SEEN_NR_POINT_OPS_H
3 #define SEEN_NR_POINT_OPS_H
5 #include <libnr/nr-point.h>
7 namespace NR {
9 inline Point operator+(Point const &a, Point const &b)
10 {
11 Point ret;
12 for (int i = 0; i < 2; i++) {
13 ret[i] = a[i] + b[i];
14 }
15 return ret;
16 }
18 inline Point operator-(Point const &a, Point const &b)
19 {
20 Point ret;
21 for (int i = 0; i < 2; i++) {
22 ret[i] = a[i] - b[i];
23 }
24 return ret;
25 }
27 /** This is a rotation (sort of). */
28 inline Point operator^(Point const &a, Point const &b)
29 {
30 Point const ret(a[0] * b[0] - a[1] * b[1],
31 a[1] * b[0] + a[0] * b[1]);
32 return ret;
33 }
35 inline Point operator-(Point const &a)
36 {
37 Point ret;
38 for(unsigned i = 0; i < 2; i++) {
39 ret[i] = -a[i];
40 }
41 return ret;
42 }
44 inline Point operator*(double const s, Point const &b)
45 {
46 Point ret;
47 for(int i = 0; i < 2; i++) {
48 ret[i] = s * b[i];
49 }
50 return ret;
51 }
53 inline Point operator/(Point const &b, double const d)
54 {
55 Point ret;
56 for(int i = 0; i < 2; i++) {
57 ret[i] = b[i] / d;
58 }
59 return ret;
60 }
63 inline bool operator==(Point const &a, Point const &b)
64 {
65 return ( ( a[X] == b[X] ) && ( a[Y] == b[Y] ) );
66 }
68 inline bool operator!=(Point const &a, Point const &b)
69 {
70 return ( ( a[X] != b[X] ) || ( a[Y] != b[Y] ) );
71 }
74 } /* namespace NR */
77 #endif /* !SEEN_NR_POINT_OPS_H */
79 /*
80 Local Variables:
81 mode:c++
82 c-file-style:"stroustrup"
83 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
84 indent-tabs-mode:nil
85 fill-column:99
86 End:
87 */
88 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :