Skip to content

Commit d600759

Browse files
committed
Utilize MIN and MAX functions from py/misc.h
1 parent 297b719 commit d600759

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

shared-module/displayio/Shape.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <string.h>
3030

3131
#include "py/runtime.h"
32+
#include "py/misc.h"
3233

3334
void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t width,
3435
uint32_t height, bool mirror_x, bool mirror_y) {
@@ -76,20 +77,12 @@ void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y
7677
uint16_t lower_x, upper_x;
7778

7879
// find x-boundaries for updating based on current data and start_x, end_x
79-
if (start_x < self->data[2 * y]) {
80-
lower_x = start_x;
81-
} else {
82-
lower_x = self->data[2 * y];
83-
}
80+
lower_x = MIN(start_x, self->data[2 * y]);
8481

8582
if (self->mirror_x) {
8683
upper_x = self->width-lower_x;
8784
} else {
88-
if (end_x > self->data[2 * y + 1]) {
89-
upper_x = end_x + 1;
90-
} else {
91-
upper_x = self->data[2 * y + 1] + 1;
92-
}
85+
upper_x = 1 + MAX(end_x, self->data[2 * y + 1]);
9386
}
9487

9588
self->data[2 * y] = start_x;
@@ -105,12 +98,10 @@ void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y
10598
self->dirty_area.y2 = y+1;
10699
}
107100
} else { // Dirty region is not empty
108-
if (lower_x < self->dirty_area.x1) {
109-
self->dirty_area.x1 = lower_x;
110-
}
111-
if (upper_x > self->dirty_area.x2) {
112-
self->dirty_area.x2 = upper_x;
113-
}
101+
102+
self->dirty_area.x1 = MIN(lower_x, self->dirty_area.x1);
103+
self->dirty_area.x2 = MAX(upper_x, self->dirty_area.x2);
104+
114105
if (y < self->dirty_area.y1) {
115106
self->dirty_area.y1=y;
116107
if (self->mirror_y) { // if y is mirrored and the lower y was updated, the upper y must be updated too

0 commit comments

Comments
 (0)