From 4e432e5960cb8bc9feb6648087b54788c774d773 Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Sun, 11 Mar 2007 21:23:04 +0000 Subject: Eliminate remaining sources of empty NR::Rects (bzr r2605) --- src/libnr/nr-convex-hull.h | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/libnr') 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 const &bounds() const { return _bounds; } private: - Rect _bounds; + Point _initial; + Maybe _bounds; }; } /* namespace NR */ -- cgit v1.2.3