diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index 4ae5642ae795015a614ba9ca1346f11386439d66..46aff13f4fa938212f39df8654abeaacd1cdcaf5 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
/** 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
/** 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, however, is defined
- * as having zero area, meaning an empty rectangle may still contain
- * points. Infinities are also permitted. */
+ * 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()) {}
class Rect {
public:
Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {}
/** returns the midpoint of this rect. */
Point midpoint() const;
/** returns the midpoint of this rect. */
Point midpoint() const;
- /** does this rectangle have zero area? */
- bool isEmpty() const {
- return isEmpty<X>() || isEmpty<Y>();
+ /** True iff either width or height is less than \a epsilon. */
+ bool isEmpty(double epsilon=1e-6) const {
+ return isEmpty<X>(epsilon) || isEmpty<Y>(epsilon);
}
bool intersects(Rect const &r) const {
}
bool intersects(Rect const &r) const {
_max[NR::Y] += by;
}
_max[NR::Y] += by;
}
+ void growBy (gdouble by);
+
/** Scales the rect by s, with origin at 0, 0 */
inline Rect operator*(double const s) const {
return Rect(s * min(), s * max());
/** Scales the rect by s, with origin at 0, 0 */
inline Rect operator*(double const s) const {
return Rect(s * min(), s * max());
return _max[axis] - _min[axis];
}
return _max[axis] - _min[axis];
}
- template <Dim2 axis>
- bool isEmpty() const {
- return !( _min[axis] < _max[axis] );
+ template <NR::Dim2 axis>
+ bool isEmpty(double epsilon) const {
+ return extent<axis>() < epsilon;
}
template <Dim2 axis>
}
template <Dim2 axis>
Point _min, _max;
friend class MaybeStorage<Rect>;
Point _min, _max;
friend class MaybeStorage<Rect>;
- friend Maybe<Rect> intersection(Maybe<Rect const &>, Maybe<Rect const &>);
+ friend Maybe<Rect> intersection(Maybe<Rect> const &, Maybe<Rect> const &);
friend Rect union_bounds(Rect const &, Rect const &);
};
friend Rect union_bounds(Rect const &, Rect const &);
};
};
/** Returns the set of points shared by both rectangles. */
};
/** Returns the set of points shared by both rectangles. */
-Maybe<Rect> intersection(Maybe<Rect const &> a, Maybe<Rect const &> b);
+Maybe<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> const & b);
/** Returns the smallest rectangle that encloses both rectangles. */
Rect union_bounds(Rect const &a, Rect const &b);
/** Returns the smallest rectangle that encloses both rectangles. */
Rect union_bounds(Rect const &a, Rect const &b);
-inline Rect union_bounds(Maybe<Rect const &> a, Rect const &b) {
+inline Rect union_bounds(Maybe<Rect> const & a, Rect const &b) {
if (a) {
return union_bounds(*a, b);
} else {
return b;
}
}
if (a) {
return union_bounds(*a, b);
} else {
return b;
}
}
-inline Rect union_bounds(Rect const &a, Maybe<Rect const &> b) {
+inline Rect union_bounds(Rect const &a, Maybe<Rect> const & b) {
if (b) {
return union_bounds(a, *b);
} else {
return a;
}
}
if (b) {
return union_bounds(a, *b);
} else {
return a;
}
}
-inline Maybe<Rect> union_bounds(Maybe<Rect const &> a, Maybe<Rect const &> b)
+inline Maybe<Rect> union_bounds(Maybe<Rect> const & a, Maybe<Rect> const & b)
{
if (!a) {
return b;
{
if (!a) {
return b;
#define nr_rect_d_set_empty(r) (*(r) = NR_RECT_EMPTY)
#define nr_rect_l_set_empty(r) (*(r) = NR_RECT_L_EMPTY)
#define nr_rect_d_set_empty(r) (*(r) = NR_RECT_EMPTY)
#define nr_rect_l_set_empty(r) (*(r) = NR_RECT_L_EMPTY)
+/** "Empty" here includes the case of zero width or zero height. */
#define nr_rect_d_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
#define nr_rect_l_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
#define nr_rect_d_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))
#define nr_rect_l_test_empty(r) ((r) && NR_RECT_DFLS_TEST_EMPTY(r))