29
29
#include <string.h>
30
30
31
31
#include "py/runtime.h"
32
+ #include "py/misc.h"
32
33
33
34
void common_hal_displayio_shape_construct (displayio_shape_t * self , uint32_t width ,
34
35
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
76
77
uint16_t lower_x , upper_x ;
77
78
78
79
// 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 ]);
84
81
85
82
if (self -> mirror_x ) {
86
83
upper_x = self -> width - lower_x ;
87
84
} 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 ]);
93
86
}
94
87
95
88
self -> data [2 * y ] = start_x ;
@@ -105,12 +98,10 @@ void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y
105
98
self -> dirty_area .y2 = y + 1 ;
106
99
}
107
100
} 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
+
114
105
if (y < self -> dirty_area .y1 ) {
115
106
self -> dirty_area .y1 = y ;
116
107
if (self -> mirror_y ) { // if y is mirrored and the lower y was updated, the upper y must be updated too
0 commit comments