summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2007-03-17 06:51:35 +0000
committermental <mental@users.sourceforge.net>2007-03-17 06:51:35 +0000
commit4132345ba756f54ede51dfb00f4819bb0a939d0d (patch)
tree9539073cbc4fd5c6f2deb66323d15311447bd7ca /src
parentmove creating style after the signals are set up, so that style does not miss... (diff)
downloadinkscape-4132345ba756f54ede51dfb00f4819bb0a939d0d.tar.gz
inkscape-4132345ba756f54ede51dfb00f4819bb0a939d0d.zip
clean up rect mess a bit before start working on other stuff
(bzr r2678)
Diffstat (limited to 'src')
-rw-r--r--src/display/sp-canvas.cpp4
-rw-r--r--src/libnr/nr-convex-hull.h26
-rw-r--r--src/libnr/nr-rect.cpp8
-rw-r--r--src/libnr/nr-rect.h20
4 files changed, 25 insertions, 33 deletions
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<Point> 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<Rect> _bounds;
+ Maybe<Rect> _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<X>(epsilon) || isEmpty<Y>(epsilon);
+ }
+
bool intersects(Rect const &r) const {
return intersects<X>(r) && intersects<Y>(r);
}
@@ -152,6 +153,11 @@ private:
return _max[axis] - _min[axis];
}
+ template <NR::Dim2 axis>
+ bool isEmpty(double epsilon) const {
+ return extent<axis>() < epsilon;
+ }
+
template <Dim2 axis>
bool intersects(Rect const &r) const {
return _max[axis] >= r._min[axis] && _min[axis] <= r._max[axis];