From: buliabyak Date: Mon, 16 Oct 2006 06:41:07 +0000 (+0000) Subject: some more NRRectL goodies for canvas optimizations X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a92fe682f48fd3b2dd3df18bd377abacf344e210;p=inkscape.git some more NRRectL goodies for canvas optimizations --- 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);