26static int _cmpX(
const void *av,
const void *bv);
28static int _cmpY(
const void *av,
const void *bv);
57 if(list->
areas == NULL) {
63 while((area = va_arg(ap,
RArea *)) != NULL) {
95 int top_margin,
int bottom_margin)
97 if(left_margin > 0 || right_margin > 0
98 || top_margin > 0 || bottom_margin > 0) {
103 if(left_margin < 0) {
106 if(right_margin < 0) {
112 if(bottom_margin < 0) {
117 big_area.
x += left_margin;
118 big_area.
width -= left_margin + right_margin;
119 big_area.
y += top_margin;
120 big_area.
height -= top_margin + bottom_margin;
157 if(index >= self->
len) {
163 if(index == self->
len) {
167 memcpy(&self->
areas[index], &self->
areas[index + 1],
168 (self->
len - index) *
sizeof(
RArea));
178 if(self->
cap == self->
len) {
180 if(new_list == NULL) {
185 self->
areas = new_list;
201 if(new_list == NULL) {
206 self->
areas = new_list;
219_cmpX(
const void *av,
const void *bv)
231 return (a->
y > b->y) - (a->
y < b->y);
253_cmpY(
const void *av,
const void *bv)
265 return (a->
x > b->x) - (a->
x < b->x);
301 for(
int i = 0; i < copy->
len - 1; i++) {
302 for(
int j = i + 1; j < copy->
len; j++) {
334 for(
int i = 0; i < copy->
len - 1; i++) {
335 for(
int j = i + 1; j < copy->
len; j++) {
363 for(
int i = 0; i < self->
len; i++) {
379 bool (*func)(
const RArea *cur_area,
void *data),
382 for(
int i = 0 ; i < self->
len ; i++) {
383 if(func(&(self->
areas[i]), data) ==
true) {
400 for(
int i = 0; i < self->
len; i++) {
430 for(
int i = 0 ; i < self->
len ; i++) {
432 if(i == 0 || area->
x <
x) {
436 if(i == 0 || area->
y <
y) {
440 if(i == 0 ||
RAreaX2(area) > x2) {
444 if(i == 0 ||
RAreaY2(area) > y2) {
465 for(
int i = 0; i < self->
len; i++) {
469 full_area = self->
areas[i];
484 int max_x = self->
len ? cur_area->
x : 0;
489 while(++cur_area < area_end) {
490 if(cur_area->
x > max_x) {
506 int max_y = self->
len ? cur_area->
y : 0;
508 while(++cur_area < area_end) {
509 if(cur_area->
y > max_y) {
526 int min_x = self->
len ?
RAreaX2(cur_area) : 0;
528 while(++cur_area < area_end) {
529 if(
RAreaX2(cur_area) < min_x) {
546 int min_y = self->
len ?
RAreaY2(cur_area) : 0;
548 while(++cur_area < area_end) {
549 if(
RAreaY2(cur_area) < min_y) {
566 fprintf(stderr,
"[len=%d cap=%d", self->
len, self->
cap);
568 for(
int i = 0 ; i < self->
len ; i++) {
570 fprintf(stderr,
" ");
574 fprintf(stderr,
"]");
RArea RAreaInvalid(void)
Return a facially-invalid RArea.
RArea RAreaNew(int x, int y, int width, int height)
Construct an RArea from given components.
RArea RAreaIntersect(const RArea *self, const RArea *other)
Return an RArea describing the intersection of two RArea's.
int RAreaArea(const RArea *self)
Return the area of an RArea.
RAreaList * RAreaHorizontalUnion(const RArea *self, const RArea *other)
Create a list of maximal horizontal stripes of two RArea's.
bool RAreaIsIntersect(const RArea *self, const RArea *other)
Do two areas intersect?
bool RAreaIsValid(const RArea *self)
Is an RArea facially valid?
void RAreaPrint(const RArea *self)
Pretty-print an RArea.
int RAreaY2(const RArea *self)
Return the bottom edge of an RArea.
int RAreaX2(const RArea *self)
Return the right edge of an RArea.
RAreaList * RAreaVerticalUnion(const RArea *self, const RArea *other)
Create a list of maximal vertical stripes of two RArea's.
RAreaList * RAreaListNew(int cap,...)
Create an RAreaList from a set of RArea's.
RArea RAreaListBestTarget(const RAreaList *self, const RArea *area)
Find the RArea in an RAreaList that has the largest intersection with a given RArea.
static int _cmpX(const void *av, const void *bv)
qsort comparison function to sort by RArea.x
int RAreaListMinY2(const RAreaList *self)
Find the y coordinate of the bottom edge of the top-most RArea in an RAreaList.
static void RAreaListSortY(const RAreaList *self)
Sort the RArea's in an RAreaList by their y coordinate.
static RAreaList * RAreaListIntersectCrop(const RAreaList *self, const RArea *area)
Create an RAreaList from another, cropped to a certain area defined by an RArea.
static void RAreaListAddList(RAreaList *self, const RAreaList *other)
Add the RArea's from one RAreaList onto another.
RAreaList * RAreaListVerticalUnion(const RAreaList *self)
Create an RAreaList whose RArea's are the vertical union of our RArea's.
void RAreaListFree(RAreaList *self)
Clean up and free an RAreaList.
RArea RAreaListBigArea(const RAreaList *self)
Create a maximal RArea describing the union of an RAreaList.
int RAreaListMaxY(const RAreaList *self)
Find the y coordinate of the bottom-most RArea in an RAreaList.
void RAreaListPrint(const RAreaList *self)
Pretty-print an RAreaList.
static int _cmpY(const void *av, const void *bv)
qsort comparison function to sort by RArea.t
RAreaList * RAreaListIntersect(const RAreaList *self, const RArea *area)
Create an RAreaList of all the areas in an RAreaList that a given RArea intersects with.
static void RAreaListDelete(RAreaList *self, int index)
Delete an RArea from inside an RAreaList.
int RAreaListMaxX(const RAreaList *self)
Find the x coordinate of the right-most RArea in an RAreaList.
static RAreaList * RAreaListCopy(const RAreaList *self)
Create a copy of a given RAreaList.
RAreaList * RAreaListHorizontalUnion(const RAreaList *self)
Create an RAreaList whose RArea's are the horizontal union of our RArea's.
void RAreaListForeach(const RAreaList *self, bool(*func)(const RArea *cur_area, void *data), void *data)
Run a function over each RArea in an RAreaList until one returns true, allowing them a place to stash...
static void RAreaListSortX(const RAreaList *self)
Sort the RArea's in an RAreaList by their x coordinate.
RAreaList * RAreaListCopyCropped(const RAreaList *self, int left_margin, int right_margin, int top_margin, int bottom_margin)
Create a copy of an RAreaList with given amounts cropped off the sides.
void RAreaListAdd(RAreaList *self, const RArea *area)
Add an RArea onto an RAreaList.
int RAreaListMinX2(const RAreaList *self)
Find the x coordinate of the right edge of the left-most RArea in an RAreaList.
RArea * areas
Array of RArea members of this list.
int cap
How many we have space for.
int len
How many we're using.
A particular extent of space.