diff options
| author | Jeff Epler <jepler@gmail.com> | 2021-03-18 09:04:53 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2021-03-18 09:05:07 -0500 |
| commit | f40c0c13adacf39bc9a21afd2d9ebbf29135e0f0 (patch) | |
| tree | ed95adabfc04d947fb49574fb812b9223a8dbb27 /shared-module | |
| parent | 47ca7927659946115f3667a5e6f2da29abf5882e (diff) | |
displayio: area: add displayo_area_copy_coords, displayio_area_empty
.. and simplify the implmentation of displayio_area_union
This _slightly_ changes the behavior of displayio_area_union:
Formerly, if one of the areas was empty, its coordinates were still
used in the min/max calculations.
Now, if one of the areas is empty, the result gets the other area's coords
In particular, taking the union of the empty area with coords (0,0,0,0)
with the non-empty area (x1,y1,x2,y2) would give the area (0,0,x2,y2)
before, and (x1,y1,x2,y2) after the change.
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/displayio/__init__.c | 35 | ||||
| -rw-r--r-- | shared-module/displayio/area.h | 2 |
2 files changed, 23 insertions, 14 deletions
diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 3c9c2cc3a..07fd60386 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -309,26 +309,33 @@ bool displayio_area_compute_overlap(const displayio_area_t *a, return true; } +void displayio_copy_coords(const displayio_area_t *src, displayio_area_t *dest) { + dest->x1 = src->x1; + dest->y1 = src->y1; + dest->x2 = src->x2; + dest->y2 = src->y2; +} + +bool displayio_area_empty(const displayio_area_t *a) { + return (a->x1 == a->x2) || (a->y1 == a->y2); +} + void displayio_area_union(const displayio_area_t *a, const displayio_area_t *b, displayio_area_t *u) { - u->x1 = a->x1; - if (b->x1 < u->x1) { - u->x1 = b->x1; - } - u->x2 = a->x2; - if (b->x2 > u->x2) { - u->x2 = b->x2; - } - u->y1 = a->y1; - if (b->y1 < u->y1) { - u->y1 = b->y1; + if (displayio_area_empty(a)) { + displayio_copy_coords(b, u); + return; } - u->y2 = a->y2; - if (b->y2 > u->y2) { - u->y2 = b->y2; + if (displayio_area_empty(b)) { + displayio_copy_coords(a, u); + return; } + u->x1 = MIN(a->x1, b->x1); + u->y1 = MIN(a->y1, b->y1); + u->x2 = MAX(a->x2, b->x2); + u->y2 = MAX(a->y2, b->y2); } uint16_t displayio_area_width(const displayio_area_t *area) { diff --git a/shared-module/displayio/area.h b/shared-module/displayio/area.h index 21bf2f8b2..1b30ce96f 100644 --- a/shared-module/displayio/area.h +++ b/shared-module/displayio/area.h @@ -53,6 +53,8 @@ typedef struct { extern displayio_buffer_transform_t null_transform; +bool displayio_area_empty(const displayio_area_t *a); +void displayio_area_copy_coords(const displayio_area_t *src, displayio_area_t *dest); void displayio_area_union(const displayio_area_t *a, const displayio_area_t *b, displayio_area_t *u); |
