diff options
| author | MenTaLguY <mental@rydia.net> | 2007-03-11 21:23:04 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2007-03-11 21:23:04 +0000 |
| commit | 4e432e5960cb8bc9feb6648087b54788c774d773 (patch) | |
| tree | f83b7730dfb4ff96d45fb96e83367ab3dc28e56f /src/libnr | |
| parent | Switch selection bounds and center to use NR::Maybe, addressing most of the (diff) | |
| download | inkscape-4e432e5960cb8bc9feb6648087b54788c774d773.tar.gz inkscape-4e432e5960cb8bc9feb6648087b54788c774d773.zip | |
Eliminate remaining sources of empty NR::Rects
(bzr r2605)
Diffstat (limited to 'src/libnr')
| -rw-r--r-- | src/libnr/nr-convex-hull.h | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/libnr/nr-convex-hull.h b/src/libnr/nr-convex-hull.h index 28cde376d..fef885f00 100644 --- a/src/libnr/nr-convex-hull.h +++ b/src/libnr/nr-convex-hull.h @@ -17,31 +17,49 @@ namespace NR { class ConvexHull { public: - explicit ConvexHull(Point const &p) : _bounds(p, p) {} + explicit ConvexHull(Point const &p) + : _initial(p) {} Point midpoint() const { - return _bounds.midpoint(); + if (_bounds) { + return _bounds->midpoint(); + } else { + return _initial; + } } void add(Point const &p) { - _bounds.expandTo(p); + if (_bounds) { + _bounds->expandTo(p); + } else if ( p != _initial ) { + _bounds = Rect(_initial, p); + } } void add(Rect const &p) { // Note that this is a hack. when convexhull actually works // you will need to add all four points. - _bounds.expandTo(p.min()); - _bounds.expandTo(p.max()); + if (_bounds) { + _bounds = union_bounds(*_bounds, p); + } else { + _bounds = p; + _bounds->expandTo(_initial); + } } void add(ConvexHull const &h) { - _bounds.expandTo(h._bounds); + if (h._bounds) { + add(*h._bounds); + } else { + add(h._initial); + } } - - Rect const &bounds() const { + + Maybe<Rect> const &bounds() const { return _bounds; } private: - Rect _bounds; + Point _initial; + Maybe<Rect> _bounds; }; } /* namespace NR */ |
