correcting feedback

This commit is contained in:
jposada202020 2023-03-30 08:51:52 -04:00
parent f3d85d6932
commit 6ad053e403
3 changed files with 59 additions and 22 deletions

View File

@ -122,6 +122,7 @@ msgid "%q in %q must be of type %q, not %q"
msgstr ""
#: ports/espressif/common-hal/espulp/ULP.c
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/microcontroller/Pin.c
@ -1217,6 +1218,7 @@ msgstr ""
msgid "Interrupt error."
msgstr ""
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/displayio/EPaperDisplay.c
@ -1224,6 +1226,7 @@ msgid "Invalid %q"
msgstr ""
#: ports/atmel-samd/common-hal/microcontroller/Pin.c
#: ports/mimxrt10xx/common-hal/microcontroller/Pin.c
#: shared-bindings/microcontroller/Pin.c
msgid "Invalid %q pin"
msgstr ""
@ -3827,11 +3830,7 @@ msgstr ""
msgid "out must be a float dense array"
msgstr ""
#: shared-bindings/displayio/Bitmap.c
msgid "out of range of source"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "out of range of target"
msgstr ""
@ -3856,14 +3855,10 @@ msgstr ""
msgid "parameters must be registers in sequence r0 to r3"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "pixel coordinates out of bounds"
msgstr ""
#: shared-bindings/displayio/Bitmap.c
msgid "pixel value requires too many bits"
msgstr ""
#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter"
msgstr ""
@ -3905,6 +3900,10 @@ msgstr ""
msgid "queue overflow"
msgstr ""
#: shared-bindings/bitmaptools/__init__.c
msgid "radius must be greater than zero"
msgstr ""
#: py/parse.c
msgid "raw f-strings are not supported"
msgstr ""
@ -4276,10 +4275,6 @@ msgstr ""
msgid "value out of range of target"
msgstr ""
#: shared-bindings/displayio/Bitmap.c
msgid "value_count must be > 0"
msgstr ""
#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""

View File

@ -871,20 +871,48 @@ MP_DEFINE_CONST_FUN_OBJ_KW(bitmaptools_dither_obj, 0, bitmaptools_dither);
// requires all 5 arguments
//| def draw_circle(
//| dest_bitmap: displayio.Bitmap, x0: int, y0: int, radius: int, value: int
//| dest_bitmap: displayio.Bitmap, x: int, y: int, radius: int, value: int
//| ) -> None:
//| """Draws a circle into a bitmap specified using a center (x0,y0) and radius r.
//|
//| :param bitmap dest_bitmap: Destination bitmap that will be written into
//| :param int x0: x-pixel position of the circle's center
//| :param int y0: y-pixel position of the circle's center
//| :param int x: x-pixel position of the circle's center
//| :param int y: y-pixel position of the circle's center
//| :param int radius: circle's radius
//| :param int value: Bitmap palette index that will be written into the
//| circle in the destination bitmap"""
//| circle in the destination bitmap
//|
//| .. code-block:: Python
//|
//| import board
//| import displayio
//| import bitmaptools
//|
//| display = board.DISPLAY
//| main_group = displayio.Group()
//| display.root_group = main_group
//|
//| palette = displayio.Palette(2)
//| palette[0] = 0xffffff
//| palette[1] = 0x440044
//|
//| bmp = displayio.Bitmap(128,128, 2)
//| bmp.fill(0)
//|
//| bitmaptools.circle(64,64, 32, 1)
//|
//| tilegrid = displayio.TileGrid(bitmap=bmp, pixel_shader=palette)
//| main_group.append(tilegrid)
//|
//| while True:
//| pass
//|
//| """
//|
//| ...
//|
STATIC mp_obj_t bitmaptools_obj_draw_circle(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum {ARG_dest_bitmap, ARG_x0, ARG_y0, ARG_radius, ARG_value};
enum {ARG_dest_bitmap, ARG_x, ARG_y, ARG_radius, ARG_value};
static const mp_arg_t allowed_args[] = {
{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
}
int16_t x0 = args[ARG_x0].u_int;
int16_t y0 = args[ARG_y0].u_int;
int16_t x = args[ARG_x].u_int;
int16_t y = args[ARG_y].u_int;
int16_t radius = args[ARG_radius].u_int;
if (x < 0 || x >= destination->width) {
mp_raise_ValueError(translate("out of range of target"));
}
if (y < 0 || y >= destination->height) {
mp_raise_ValueError(translate("out of range of target"));
}
if (radius < 0) {
mp_raise_ValueError(translate("radius must be greater than zero"));
}
common_hal_bitmaptools_draw_circle(destination, x0, y0, radius, value);
common_hal_bitmaptools_draw_circle(destination, x, y, radius, value);
return mp_const_none;
}

View File

@ -931,6 +931,11 @@ STATIC void draw_circle(displayio_bitmap_t *destination,
mp_arg_validate_int_range(x0, SHRT_MIN, SHRT_MAX, MP_QSTR_x0);
mp_arg_validate_int_range(y0, SHRT_MIN, SHRT_MAX, MP_QSTR_y0);
x0 = MIN(x0, destination->width);
x0 = MAX(0, x0);
y0 = MIN(y0, destination->height);
y0 = MIN(0, y0);
BITMAP_DEBUG("x, y, radius (%4d, %4d, %4d)\n", x0, y0, radius);
y = radius;