@@ -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//|
886914STATIC 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}
0 commit comments