From: mental Date: Sat, 17 Mar 2007 06:51:35 +0000 (+0000) Subject: clean up rect mess a bit before start working on other stuff X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3e54f202d25d5b42a058f4b6e39f3958979b6766;p=inkscape.git clean up rect mess a bit before start working on other stuff --- diff --git a/src/display/sp-canvas.cpp b/src/display/sp-canvas.cpp index 559515e03..94eb984a3 100644 --- a/src/display/sp-canvas.cpp +++ b/src/display/sp-canvas.cpp @@ -751,8 +751,8 @@ sp_canvas_group_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i item->x2 = bounds->max()[NR::X]; item->y2 = bounds->max()[NR::Y]; } else { - item->x1 = item->x2 = corners.midpoint()[NR::X]; - item->y1 = item->y2 = corners.midpoint()[NR::Y]; + // FIXME ? + item->x1 = item->x2 = item->y1 = item->y2 = 0; } } diff --git a/src/libnr/nr-convex-hull.h b/src/libnr/nr-convex-hull.h index fef885f00..51dabcf07 100644 --- a/src/libnr/nr-convex-hull.h +++ b/src/libnr/nr-convex-hull.h @@ -17,39 +17,32 @@ namespace NR { class ConvexHull { public: - explicit ConvexHull(Point const &p) - : _initial(p) {} + ConvexHull() : _bounds() {} + explicit ConvexHull(Point const &p) : _bounds(Rect(p, p)) {} - Point midpoint() const { + Maybe midpoint() const { if (_bounds) { return _bounds->midpoint(); } else { - return _initial; + return Nothing(); } } void add(Point const &p) { if (_bounds) { _bounds->expandTo(p); - } else if ( p != _initial ) { - _bounds = Rect(_initial, p); + } else { + _bounds = Rect(p, p); } } - void add(Rect const &p) { + void add(Rect const &r) { // Note that this is a hack. when convexhull actually works // you will need to add all four points. - if (_bounds) { - _bounds = union_bounds(*_bounds, p); - } else { - _bounds = p; - _bounds->expandTo(_initial); - } + _bounds = union_bounds(_bounds, r); } void add(ConvexHull const &h) { if (h._bounds) { add(*h._bounds); - } else { - add(h._initial); } } @@ -58,8 +51,7 @@ public: } private: - Point _initial; - Maybe _bounds; + Maybe _bounds; }; } /* namespace NR */ diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp index d4ba14e1a..f3eb498af 100644 --- a/src/libnr/nr-rect.cpp +++ b/src/libnr/nr-rect.cpp @@ -245,13 +245,7 @@ namespace NR { Rect::Rect(const Point &p0, const Point &p1) : _min(std::min(p0[X], p1[X]), std::min(p0[Y], p1[Y])), _max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y])) -{ - if (0) { - if ( _min[X] == _max[X] || _min[Y] == _max[Y] ) { - throw EmptyRectangle(); - } - } -} +{} /** returns the four corners of the rectangle in the correct winding order */ Point Rect::corner(unsigned i) const { diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h index 6ae1e4e99..1062df955 100644 --- a/src/libnr/nr-rect.h +++ b/src/libnr/nr-rect.h @@ -28,16 +28,13 @@ namespace NR { struct Matrix; -class EmptyRectangle : public std::logic_error { -public: - EmptyRectangle() : logic_error("Attempt to create empty rectangle") {} -}; - /** A rectangle is always aligned to the X and Y axis. This means it * can be defined using only 4 coordinates, and determining * intersection is very efficient. The points inside a rectangle are - * min[dim] <= _pt[dim] <= max[dim]. Emptiness, in the sense of having - * a zero area, is not permitted. Infinities are, however. */ + * min[dim] <= _pt[dim] <= max[dim]. A rectangle may be empty, in the + * sense of having zero area, but it will always contain at least one + * point. Infinities are also permitted. + */ class Rect { public: Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {} @@ -56,6 +53,10 @@ public: /** returns the midpoint of this rect. */ Point midpoint() const; + bool isEmpty(double epsilon=1e-6) const { + return isEmpty(epsilon) || isEmpty(epsilon); + } + bool intersects(Rect const &r) const { return intersects(r) && intersects(r); } @@ -152,6 +153,11 @@ private: return _max[axis] - _min[axis]; } + template + bool isEmpty(double epsilon) const { + return extent() < epsilon; + } + template bool intersects(Rect const &r) const { return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis];