static void _expectCompare( Region* r, const SkinBox* boxes, int count ) { if (count == 0) { if ( !skin_region_is_empty(r) ) { printf( " result is not empty\n" ); panic(); } } else if (count == 1) { SkinRect rect1, rect2; if ( !skin_region_is_rect(r) ) { printf( " result is not a rectangle\n" ); panic(); } skin_region_get_bounds( r, &rect1 ); skin_box_to_rect( (SkinBox*)boxes, &rect2 ); if ( !skin_rect_equals( &rect1, &rect2 ) ) { printf( " result is (%d,%d,%d,%d), expected (%d,%d,%d,%d)\n", rect1.pos.x, rect1.pos.y, rect1.pos.x + rect1.size.w, rect1.pos.y + rect1.size.h, rect2.pos.x, rect2.pos.y, rect2.pos.x + rect2.size.w, rect2.pos.y + rect2.size.h ); panic(); } } else { SkinRegionIterator iter; SkinBox b; int n; skin_region_iterator_init( &iter, r ); n = 0; while (n < count) { if ( !skin_region_iterator_next_box( &iter, &b ) ) { printf( "missing region box (%d, %d, %d, %d)\n", boxes->x1, boxes->y1, boxes->x2, boxes->y2 ); panic(); } if (b.x1 != boxes->x1 || b.x2 != boxes->x2|| b.y1 != boxes->y1 || b.y2 != boxes->y2) { printf( "invalid region box (%d,%d,%d,%d) expecting (%d,%d,%d,%d)\n", b.x1, b.y1, b.x2, b.y2, boxes->x1, boxes->y1, boxes->x2, boxes->y2 ); panic(); } boxes += 1; n += 1; } if ( skin_region_iterator_next_box( &iter, &b ) ) { printf( "excess region box (%d,%d,%d,%d)\n", b.x1, b.y1, b.x2, b.y2 ); panic(); } } }
int skin_box_minmax_to_rect( SkinBox* box, SkinRect* r ) { if (box->x1 > box->x2) { r->pos.x = r->pos.y = r->size.w = r->size.h = 0; return 0; } skin_box_to_rect( box, r ); return 1; }
/* returns 1 if the result is not empty */ static int region_operator_done( RegionOperator* o ) { Run* src = o->runs; int count; SkinBox minmax; RunStore* store; if (src <= o->runs_base + 1) { /* result is empty */ skin_region_init_empty( o->result ); return 0; } /* coalesce the temp runs in-place and compute the corresponding bounds */ minmax.x1 = minmax.y1 = INT_MAX; minmax.x2 = minmax.y2 = INT_MIN; count = runs_coalesce( o->runs_base, o->runs_base, &minmax ); if (count == 1) { /* result is empty */ skin_region_init_empty( o->result ); } else { skin_box_to_rect( &minmax, &o->result->bounds ); if (count == RUNS_RECT_COUNT) { o->result->runs = RUNS_RECT; } else { /* result is complex */ store = runstore_alloc( count ); o->result->runs = runstore_to_runs(store); memcpy( o->result->runs, o->runs_base, count*sizeof(Run) ); } } /* release temporary runstore */ runstore_unrefp( &o->store ); return region_isEmpty(o->result); }
int skin_rect_intersect( SkinRect* result, SkinRect* r1, SkinRect* r2 ) { SkinBox a, b, r; skin_box_from_rect( &a, r1 ); skin_box_from_rect( &b, r2 ); if (a.x2 <= b.x1 || b.x2 <= a.x1 || a.y2 <= b.y1 || b.y2 <= a.y1) { result->pos.x = result->pos.y = result->size.w = result->size.h = 0; return 0; } r.x1 = (a.x1 > b.x1) ? a.x1 : b.x1; r.x2 = (a.x2 < b.x2) ? a.x2 : b.x2; r.y1 = (a.y1 > b.y1) ? a.y1 : b.y1; r.y2 = (a.y2 < b.y2) ? a.y2 : b.y2; skin_box_to_rect( &r, result ); return 1; }