Skip to content

Commit 6ad053e

Browse files
committed
correcting feedback
1 parent f3d85d6 commit 6ad053e

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

locale/circuitpython.pot

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ msgid "%q in %q must be of type %q, not %q"
122122
msgstr ""
123123

124124
#: ports/espressif/common-hal/espulp/ULP.c
125+
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
125126
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
126127
#: shared-bindings/digitalio/DigitalInOut.c
127128
#: shared-bindings/microcontroller/Pin.c
@@ -1217,13 +1218,15 @@ msgstr ""
12171218
msgid "Interrupt error."
12181219
msgstr ""
12191220

1221+
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
12201222
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c
12211223
#: shared-bindings/digitalio/DigitalInOut.c
12221224
#: shared-bindings/displayio/EPaperDisplay.c
12231225
msgid "Invalid %q"
12241226
msgstr ""
12251227

12261228
#: ports/atmel-samd/common-hal/microcontroller/Pin.c
1229+
#: ports/mimxrt10xx/common-hal/microcontroller/Pin.c
12271230
#: shared-bindings/microcontroller/Pin.c
12281231
msgid "Invalid %q pin"
12291232
msgstr ""
@@ -3827,11 +3830,7 @@ msgstr ""
38273830
msgid "out must be a float dense array"
38283831
msgstr ""
38293832

3830-
#: shared-bindings/displayio/Bitmap.c
3831-
msgid "out of range of source"
3832-
msgstr ""
3833-
3834-
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
3833+
#: shared-bindings/bitmaptools/__init__.c
38353834
msgid "out of range of target"
38363835
msgstr ""
38373836

@@ -3856,14 +3855,10 @@ msgstr ""
38563855
msgid "parameters must be registers in sequence r0 to r3"
38573856
msgstr ""
38583857

3859-
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
3858+
#: shared-bindings/bitmaptools/__init__.c
38603859
msgid "pixel coordinates out of bounds"
38613860
msgstr ""
38623861

3863-
#: shared-bindings/displayio/Bitmap.c
3864-
msgid "pixel value requires too many bits"
3865-
msgstr ""
3866-
38673862
#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
38683863
msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter"
38693864
msgstr ""
@@ -3905,6 +3900,10 @@ msgstr ""
39053900
msgid "queue overflow"
39063901
msgstr ""
39073902

3903+
#: shared-bindings/bitmaptools/__init__.c
3904+
msgid "radius must be greater than zero"
3905+
msgstr ""
3906+
39083907
#: py/parse.c
39093908
msgid "raw f-strings are not supported"
39103909
msgstr ""
@@ -4276,10 +4275,6 @@ msgstr ""
42764275
msgid "value out of range of target"
42774276
msgstr ""
42784277

4279-
#: shared-bindings/displayio/Bitmap.c
4280-
msgid "value_count must be > 0"
4281-
msgstr ""
4282-
42834278
#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
42844279
msgid "watchdog not initialized"
42854280
msgstr ""

shared-bindings/bitmaptools/__init__.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -871,20 +871,48 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_dither_obj, 0, bitmaptools_dither);
871871
// requires all 5 arguments
872872

873873
//| def draw_circle(
874-
//| dest_bitmap: displayio.Bitmap, x0: int, y0: int, radius: int, value: int
874+
//| dest_bitmap: displayio.Bitmap, x: int, y: int, radius: int, value: int
875875
//| ) -> None:
876876
//| """Draws a circle into a bitmap specified using a center (x0,y0) and radius r.
877877
//|
878878
//| :param bitmap dest_bitmap: Destination bitmap that will be written into
879-
//| :param int x0: x-pixel position of the circle's center
880-
//| :param int y0: y-pixel position of the circle's center
879+
//| :param int x: x-pixel position of the circle's center
880+
//| :param int y: y-pixel position of the circle's center
881881
//| :param int radius: circle's radius
882882
//| :param int value: Bitmap palette index that will be written into the
883-
//| circle in the destination bitmap"""
883+
//| circle in the destination bitmap
884+
//|
885+
//| .. code-block:: Python
886+
//|
887+
//| import board
888+
//| import displayio
889+
//| import bitmaptools
890+
//|
891+
//| display = board.DISPLAY
892+
//| main_group = displayio.Group()
893+
//| display.root_group = main_group
894+
//|
895+
//| palette = displayio.Palette(2)
896+
//| palette[0] = 0xffffff
897+
//| palette[1] = 0x440044
898+
//|
899+
//| bmp = displayio.Bitmap(128,128, 2)
900+
//| bmp.fill(0)
901+
//|
902+
//| bitmaptools.circle(64,64, 32, 1)
903+
//|
904+
//| tilegrid = displayio.TileGrid(bitmap=bmp, pixel_shader=palette)
905+
//| main_group.append(tilegrid)
906+
//|
907+
//| while True:
908+
//| pass
909+
//|
910+
//| """
911+
//|
884912
//| ...
885913
//|
886914
STATIC mp_obj_t bitmaptools_obj_draw_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
887-
enum {ARG_dest_bitmap, ARG_x0, ARG_y0, ARG_radius, ARG_value};
915+
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_radius, ARG_value};
888916

889917
static const mp_arg_t allowed_args[] = {
890918
{MP_QSTR_dest_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
@@ -906,12 +934,21 @@ STATIC mp_obj_t bitmaptools_obj_draw_circle(size_t n_args, const mp_obj_t *pos_a
906934
}
907935

908936

909-
int16_t x0 = args[ARG_x0].u_int;
910-
int16_t y0 = args[ARG_y0].u_int;
937+
int16_t x = args[ARG_x].u_int;
938+
int16_t y = args[ARG_y].u_int;
911939
int16_t radius = args[ARG_radius].u_int;
912940

941+
if (x < 0 || x >= destination->width) {
942+
mp_raise_ValueError(translate("out of range of target"));
943+
}
944+
if (y < 0 || y >= destination->height) {
945+
mp_raise_ValueError(translate("out of range of target"));
946+
}
947+
if (radius < 0) {
948+
mp_raise_ValueError(translate("radius must be greater than zero"));
949+
}
913950

914-
common_hal_bitmaptools_draw_circle(destination, x0, y0, radius, value);
951+
common_hal_bitmaptools_draw_circle(destination, x, y, radius, value);
915952

916953
return mp_const_none;
917954
}

shared-module/bitmaptools/__init__.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,11 @@ STATIC void draw_circle(displayio_bitmap_t *destination,
931931
mp_arg_validate_int_range(x0, SHRT_MIN, SHRT_MAX, MP_QSTR_x0);
932932
mp_arg_validate_int_range(y0, SHRT_MIN, SHRT_MAX, MP_QSTR_y0);
933933

934+
x0 = MIN(x0, destination->width);
935+
x0 = MAX(0, x0);
936+
y0 = MIN(y0, destination->height);
937+
y0 = MIN(0, y0);
938+
934939
BITMAP_DEBUG("x, y, radius (%4d, %4d, %4d)\n", x0, y0, radius);
935940

936941
y = radius;

0 commit comments

Comments
 (0)