summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9bf2929)
raw | patch | inline | side by side (parent: 9bf2929)
author | mental <mental@users.sourceforge.net> | |
Sat, 17 Mar 2007 06:51:35 +0000 (06:51 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sat, 17 Mar 2007 06:51:35 +0000 (06:51 +0000) |
src/display/sp-canvas.cpp | patch | blob | history | |
src/libnr/nr-convex-hull.h | patch | blob | history | |
src/libnr/nr-rect.cpp | patch | blob | history | |
src/libnr/nr-rect.h | patch | blob | history |
index 559515e037773df3ad107cae6b2996a378f40b38..94eb984a3bff552f06eec18db17c7ae3dbb02948 100644 (file)
@@ -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;
}
}
index fef885f005ac862afc3c72672804667b7a80183d..51dabcf07f1300a8c91bf336d9156eddbc94e7ff 100644 (file)
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);
}
}
}
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 d4ba14e1aabb309affe52c70ff2ed705fb6eef56..f3eb498af26c50e809fe8aef56f07bacd1913366 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
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 6ae1e4e9948bbb18a409d1e85a7b9ae7d090023a..1062df955b132d9142a60f6f14eecb18ab5595e9 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
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()) {}
/** 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);
}
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];