summaryrefslogtreecommitdiffstats
path: root/src/libnr
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-10-16 06:41:07 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-10-16 06:41:07 +0000
commitfc9793730d8c73a72daf8c0bff66e14bcb5cb7d4 (patch)
tree21ba63a63d3c53050ad38c9651a8e9e174003428 /src/libnr
parentreally add video templates (diff)
downloadinkscape-fc9793730d8c73a72daf8c0bff66e14bcb5cb7d4.tar.gz
inkscape-fc9793730d8c73a72daf8c0bff66e14bcb5cb7d4.zip
some more NRRectL goodies for canvas optimizations
(bzr r1804)
Diffstat (limited to 'src/libnr')
-rw-r--r--src/libnr/nr-macros.h1
-rw-r--r--src/libnr/nr-rect.cpp54
-rw-r--r--src/libnr/nr-rect.h8
3 files changed, 63 insertions, 0 deletions
diff --git a/src/libnr/nr-macros.h b/src/libnr/nr-macros.h
index 616504c6f..0ccad30c4 100644
--- a/src/libnr/nr-macros.h
+++ b/src/libnr/nr-macros.h
@@ -60,6 +60,7 @@
#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 6d881e7b0..460816021 100644
--- a/src/libnr/nr-rect.cpp
+++ b/src/libnr/nr-rect.cpp
@@ -45,6 +45,60 @@ nr_rect_d_intersect (NRRect *d, const NRRect *r0, const NRRect *r1)
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 ab78c1651..e0b3f30ae 100644
--- a/src/libnr/nr-rect.h
+++ b/src/libnr/nr-rect.h
@@ -55,6 +55,14 @@ inline bool empty(NRRect const &r)
!((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);