diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index b632261aa235ef0500df2ba4d51cf8a42f5b2fcc..c61083b4b975eb1b98242534211995ee16aa60b1 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
#include <libnr/nr-point.h>
#include <libnr/nr-maybe.h>
#include <libnr/nr-point-matrix-ops.h>
+#include <libnr/nr-forward.h>
namespace NR {
- struct Matrix;
/** 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()) {}
/** returns the midpoint of this rect. */
Point midpoint() const;
- /** does this rectangle have zero area? */
- bool isEmpty() const {
- return isEmpty<X>() || isEmpty<Y>();
+ Point cornerFarthestFrom(Point const &p) const;
+
+ /** 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 {
_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());
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>
/* legacy rect stuff */
-struct NRMatrix;
-
/* NULL rect is infinite */
struct NRRect {
- NRRect() {}
+ NRRect()
+ : x0(0), y0(0), x1(0), y1(0)
+ {}
NRRect(NR::Coord xmin, NR::Coord ymin, NR::Coord xmax, NR::Coord ymax)
- : x0(xmin), y0(ymin), x1(xmin), y1(ymin)
+ : x0(xmin), y0(ymin), x1(xmax), y1(ymax)
{}
explicit NRRect(NR::Rect const &rect);
explicit NRRect(NR::Maybe<NR::Rect> const &rect);
#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))
NRRectL *nr_rect_l_union_xy(NRRectL *d, NR::ICoord x, NR::ICoord y);
NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const &m);
-NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NRMatrix const *m);
+NRRect *nr_rect_d_matrix_transform(NRRect *d, NRRect const *s, NR::Matrix const *m);
NRRectL *nr_rect_l_enlarge(NRRectL *d, int amount);