summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
authorKevin Matocha <kmatocha@icloud.com>2021-03-11 16:18:17 -0600
committerKevin Matocha <kmatocha@icloud.com>2021-03-11 16:18:17 -0600
commita9afa0d9d4c66cda8fe7e6c1a72765e704e94985 (patch)
treefdd7070b125ab3b4081ece4f2c99b34cd1b91d4c /shared-module
parent85f0f07d51343bd67c1b2308bdfed192cc470549 (diff)
Move input checks to shared-module, update docstrings
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/bitmaptools/__init__.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/shared-module/bitmaptools/__init__.c b/shared-module/bitmaptools/__init__.c
index 72db55c24..6f168b555 100644
--- a/shared-module/bitmaptools/__init__.c
+++ b/shared-module/bitmaptools/__init__.c
@@ -175,6 +175,17 @@ void common_hal_bitmaptools_rotozoom(displayio_bitmap_t *self, int16_t ox, int16
}
}
+int16_t constrain(int16_t input, int16_t min, int16_t max) {
+ // constrain the input between the min and max values
+ if (input < min) {
+ return min;
+ }
+ if (input > max) {
+ return max;
+ }
+ return input;
+}
+
void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
int16_t x1, int16_t y1,
int16_t x2, int16_t y2,
@@ -187,6 +198,24 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
mp_raise_RuntimeError(translate("Read-only object"));
}
+ // Ensure x1 < x2 and y1 < y2
+ if (x1 > x2) {
+ int16_t temp=x2;
+ x2=x1;
+ x1=temp;
+ }
+ if (y1 > y2) {
+ int16_t temp=y2;
+ y2=y1;
+ y1=temp;
+ }
+
+ // constrain to bitmap dimensions
+ x1 = constrain(x1, 0, destination->width);
+ x2 = constrain(x2, 0, destination->width);
+ y1 = constrain(y1, 0, destination->height);
+ y2 = constrain(y2, 0, destination->height);
+
// update the dirty rectangle
displayio_bitmap_set_dirty_area(destination, x1, y1, x2, y2);
@@ -198,17 +227,6 @@ void common_hal_bitmaptools_fill_region(displayio_bitmap_t *destination,
}
}
-int16_t constrain(int16_t input, int16_t min, int16_t max) {
- // constrain the input between the min and max values
- if (input < min) {
- return min;
- }
- if (input > max) {
- return max;
- }
- return input;
-}
-
void common_hal_bitmaptools_draw_line(displayio_bitmap_t *destination,
int16_t x0, int16_t y0,
int16_t x1, int16_t y1,