- boost::optional<Rect> intersection (Rect const &) const;
- Rect extend (Rect const &) const;
- Rect translate (Duple) const;
- Rect expand (Distance) const;
- bool contains (Duple) const;
- Rect fix () const;
+ boost::optional<Rect> intersection (Rect const & o) const throw () {
+ Rect i (std::max (x0, o.x0), std::max (y0, o.y0),
+ std::min (x1, o.x1), std::min (y1, o.y1));
+
+ if (i.x0 > i.x1 || i.y0 > i.y1) {
+ return boost::optional<Rect> ();
+ }
+
+ return boost::optional<Rect> (i);
+ }
+
+ Rect extend (Rect const & o) const throw () {
+ return Rect (std::min (x0, o.x0), std::min (y0, o.y0),
+ std::max (x1, o.x1), std::max (y1, o.y1));
+ }
+ Rect translate (Duple const& t) const throw () {
+ return Rect (canvas_safe_add (x0, t.x), canvas_safe_add (y0, t.y),
+ canvas_safe_add (x1, t.x),canvas_safe_add (y1, t.y));
+ }
+ Rect expand (Distance amount) const throw () {
+ return Rect (x0 - amount, y0 - amount,
+ canvas_safe_add (x1, amount),
+ canvas_safe_add (y1, amount));
+ }