summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 864a275)
raw | patch | inline | side by side (parent: 864a275)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 18 Mar 2007 21:03:20 +0000 (21:03 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Sun, 18 Mar 2007 21:03:20 +0000 (21:03 +0000) |
src/libnr/nr-rect.cpp | patch | blob | history | |
src/libnr/nr-rect.h | patch | blob | history |
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index f3eb498af26c50e809fe8aef56f07bacd1913366..d34c548adae2f970f8c3331d43a8880157de0351 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
_max(std::max(p0[X], p1[X]), std::max(p0[Y], p1[Y]))
{}
+Rect::Rect(NRRect *r)
+ : _min(r->x0, r->y0),
+ _max(r->x1, r->y1)
+{}
+
+Rect::Rect(NRRectL *r)
+ : _min(r->x0, r->y0),
+ _max(r->x1, r->y1)
+{}
+
/** returns the four corners of the rectangle in the correct winding order */
Point Rect::corner(unsigned i) const {
switch (i % 4) {
}
}
+void Rect::growBy(double size) {
+ for ( unsigned d = 0 ; d < 2 ; d++ ) {
+ _min[d] -= size;
+ _max[d] += size;
+ if ( _min[d] > _max[d] ) {
+ _min[d] = _max[d] = ( _min[d] + _max[d] ) / 2;
+ }
+ }
+}
+
/** Returns the set of points shared by both rectangles. */
Maybe<Rect> intersection(Maybe<Rect> const & a, Maybe<Rect> const & b) {
if ( !a || !b ) {
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index 1062df955b132d9142a60f6f14eecb18ab5595e9..2439df95d3361dde016a240eb35f3e518fd0386e 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
#include <libnr/nr-maybe.h>
#include <libnr/nr-point-matrix-ops.h>
+struct NRRect;
+struct NRRectL;
+
namespace NR {
struct Matrix;
public:
Rect() : _min(-_inf(), -_inf()), _max(_inf(), _inf()) {}
Rect(Point const &p0, Point const &p1);
+ Rect(NRRect *r);
+ Rect(NRRectL *r);
Point const &min() const { return _min; }
Point const &max() const { return _max; }
_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());