4 #include "canvas/types.h"
7 using namespace ArdourCanvas;
9 Coord const ArdourCanvas::COORD_MAX = DBL_MAX;
10 /* XXX: empirically arrived at */
11 Coord const ArdourCanvas::CAIRO_MAX = 65536;
14 safe_add (Coord a, Coord b)
16 if (((COORD_MAX - a) <= b) || ((COORD_MAX - b) <= a)) {
24 Duple::translate (Duple t) const
28 d.x = safe_add (x, t.x);
29 d.y = safe_add (y, t.y);
35 Rect::intersection (Rect const & o) const
39 i.x0 = max (x0, o.x0);
40 i.y0 = max (y0, o.y0);
41 i.x1 = min (x1, o.x1);
42 i.y1 = min (y1, o.y1);
44 if (i.x0 > i.x1 || i.y0 > i.y1) {
45 return boost::optional<Rect> ();
48 return boost::optional<Rect> (i);
52 Rect::translate (Duple t) const
56 r.x0 = safe_add (x0, t.x);
57 r.y0 = safe_add (y0, t.y);
58 r.x1 = safe_add (x1, t.x);
59 r.y1 = safe_add (y1, t.y);
64 Rect::extend (Rect const & o) const
67 r.x0 = min (x0, o.x0);
68 r.y0 = min (y0, o.y0);
69 r.x1 = max (x1, o.x1);
70 r.y1 = max (y1, o.y1);
75 Rect::expand (Distance amount) const
80 r.x1 = safe_add (x1, amount);
81 r.y1 = safe_add (y1, amount);
86 Rect::contains (Duple point) const
88 return point.x >= x0 && point.x <= x1 && point.y >= y0 && point.y <= y1;
105 ArdourCanvas::operator- (Duple const & o)
107 return Duple (-o.x, -o.y);
111 ArdourCanvas::operator+ (Duple const & a, Duple const & b)
113 return Duple (safe_add (a.x, b.x), safe_add (a.y, b.y));
117 ArdourCanvas::operator- (Duple const & a, Duple const & b)
119 return Duple (a.x - b.x, a.y - b.y);
123 ArdourCanvas::operator/ (Duple const & a, double b)
125 return Duple (a.x / b, a.y / b);
129 ArdourCanvas::operator<< (ostream & s, Duple const & r)
131 s << "(" << r.x << ", " << r.y << ")";
136 ArdourCanvas::operator<< (ostream & s, Rect const & r)
138 s << "[(" << r.x0 << ", " << r.y0 << "), (" << r.x1 << ", " << r.y1 << ") " << r.width() << " x " << r.height() << "]";