summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6795ba7)
raw | patch | inline | side by side (parent: 6795ba7)
author | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 16 Oct 2006 06:41:07 +0000 (06:41 +0000) | ||
committer | buliabyak <buliabyak@users.sourceforge.net> | |
Mon, 16 Oct 2006 06:41:07 +0000 (06:41 +0000) |
src/libnr/nr-macros.h | patch | blob | history | |
src/libnr/nr-rect.cpp | patch | blob | history | |
src/libnr/nr-rect.h | patch | blob | history |
diff --git a/src/libnr/nr-macros.h b/src/libnr/nr-macros.h
index 616504c6f8674b2b7f8a07baa48b7b79b59d282d..0ccad30c4a48b5d0846fba6dcc0ccaae4335e9c4 100644 (file)
--- a/src/libnr/nr-macros.h
+++ b/src/libnr/nr-macros.h
#define NR_RECT_DFLS_TEST_INTERSECT(a,b) (((a)->x0 < (b)->x1) && ((a)->x1 > (b)->x0) && ((a)->y0 < (b)->y1) && ((a)->y1 > (b)->y0))
#define NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
#define NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
+#define NR_RECT_LS_TEST_INSIDE(r,x,y) ((x >= (r)->x0) && (x < (r)->x1) && (y >= (r)->y0) && (y < (r)->y1))
#define NR_MATRIX_D_TO_DOUBLE(m) ((m)->c)
#define NR_MATRIX_D_FROM_DOUBLE(d) ((NRMatrix *) &(d)[0])
diff --git a/src/libnr/nr-rect.cpp b/src/libnr/nr-rect.cpp
index 6d881e7b0a75fac20b9740d84bb8862c2b521d8c..460816021f13257ca7e9c3478fc6c3ed60c163ec 100644 (file)
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
return d;
}
+// returns minimal rect which covers all of r0 not covered by r1
+NRRectL *
+nr_rect_l_subtract(NRRectL *d, NRRectL const *r0, NRRectL const *r1)
+{
+ bool inside1 = nr_rect_l_test_inside(r1, r0->x0, r0->y0);
+ bool inside2 = nr_rect_l_test_inside(r1, r0->x1, r0->y0);
+ bool inside3 = nr_rect_l_test_inside(r1, r0->x1, r0->y1);
+ bool inside4 = nr_rect_l_test_inside(r1, r0->x0, r0->y1);
+
+ if (inside1 && inside2 && inside3) {
+ nr_rect_l_set_empty (d);
+
+ } else if (inside1 && inside2) {
+ d->x0 = r0->x0;
+ d->y0 = r1->y1;
+
+ d->x1 = r0->x1;
+ d->y1 = r0->y1;
+ } else if (inside2 && inside3) {
+ d->x0 = r0->x0;
+ d->y0 = r0->y0;
+
+ d->x1 = r1->x0;
+ d->y1 = r0->y1;
+ } else if (inside3 && inside4) {
+ d->x0 = r0->x0;
+ d->y0 = r0->y0;
+
+ d->x1 = r0->x1;
+ d->y1 = r1->y0;
+ } else if (inside4 && inside1) {
+ d->x0 = r1->x1;
+ d->y0 = r0->y0;
+
+ d->x1 = r0->x1;
+ d->y1 = r0->y1;
+ } else {
+ d->x0 = r0->x0;
+ d->y0 = r0->y0;
+
+ d->x1 = r0->x1;
+ d->y1 = r0->y1;
+ }
+ return d;
+}
+
+NR::ICoord nr_rect_l_area(NRRectL *r)
+{
+ if (!r || NR_RECT_DFLS_TEST_EMPTY (r)) {
+ return 0;
+ }
+ return ((r->x1 - r->x0) * (r->y1 - r->y0));
+}
+
NRRect *
nr_rect_d_union (NRRect *d, const NRRect *r0, const NRRect *r1)
{
diff --git a/src/libnr/nr-rect.h b/src/libnr/nr-rect.h
index ab78c1651c53372eb9005d55520ba323c5929c58..e0b3f30ae0150309412db49978c9f96653c4dd6f 100644 (file)
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
!((r0) && (r1) && !NR_RECT_DFLS_TEST_INTERSECT(r0, r1)))
#define nr_rect_d_point_d_test_inside(r,p) ((p) && (!(r) || (!NR_RECT_DF_TEST_EMPTY(r) && NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p))))
+#define nr_rect_l_point_l_test_inside(r,p) ((p) && (!(r) || (!NR_RECT_DFLS_TEST_EMPTY(r) && NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p))))
+#define nr_rect_l_test_inside(r,x,y) ((!(r) || (!NR_RECT_DFLS_TEST_EMPTY(r) && NR_RECT_LS_TEST_INSIDE(r,x,y))))
+
+// returns minimal rect which covers all of r0 not covered by r1
+NRRectL *nr_rect_l_subtract(NRRectL *d, NRRectL const *r0, NRRectL const *r1);
+
+// returns the area of r
+NR::ICoord nr_rect_l_area(NRRectL *r);
/* NULL values are OK for r0 and r1, but not for d */
NRRect *nr_rect_d_intersect(NRRect *d, NRRect const *r0, NRRect const *r1);