@@ -282,7 +282,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_rectangle_contains_point_obj, 0, vectorio_re
282282//| :param int y2: Line y2 coordinate
283283//| :param int px: Point x coordinate
284284//| :param int py: Point y coordinate
285- //| :param float padding: Extra padding outside of the line to consider as positive intersection
285+ //| :param float padding: Extra padding outside of the line to consider as positive intersection"""
286286//| ...
287287//|
288288static mp_obj_t vectorio_line_contains_point (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
@@ -308,7 +308,7 @@ static mp_obj_t vectorio_line_contains_point(size_t n_args, const mp_obj_t *pos_
308308 int16_t px = args [ARG_px ].u_int ;
309309 int16_t py = args [ARG_py ].u_int ;
310310
311- // Confirm the angle value
311+ // Use default padding if None was passed
312312 mp_float_t padding = 0.0 ;
313313 if (args [ARG_padding ].u_obj != mp_const_none ) {
314314 padding = mp_obj_get_float (args [ARG_padding ].u_obj );
@@ -324,37 +324,115 @@ static mp_obj_t vectorio_line_contains_point(size_t n_args, const mp_obj_t *pos_
324324MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_line_contains_point_obj , 0 , vectorio_line_contains_point );
325325
326326
327+ //| def line_circle_intersects(
328+ //| x1: int, y1: int, x2: int, y2: int,
329+ // cx: int, cy: int, cr: int
330+ //| ) -> bool:
331+ //| """Checks whether a line intersects with a circle
332+ //|
333+ //| :param int x1: Line x1 coordinate
334+ //| :param int y1: Line y1 coordinate
335+ //| :param int x2: Line x2 coordinate
336+ //| :param int y2: Line y2 coordinate
337+ //| :param int cx: Circle center x coordinate
338+ //| :param int cy: Circle center y coordinate
339+ //| :param int cr: Circle radius
340+ //| :param float padding: Extra padding outside of the line to consider as positive intersection
341+ //| ...
342+ //|
343+ static mp_obj_t vectorio_line_circle_intersects (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
344+ enum {ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 , ARG_cx , ARG_cy , ARG_cr , ARG_padding };
345+
346+ static const mp_arg_t allowed_args [] = {
347+ {MP_QSTR_x1 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
348+ {MP_QSTR_y1 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
349+ {MP_QSTR_x2 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
350+ {MP_QSTR_y2 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
351+ {MP_QSTR_cx , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
352+ {MP_QSTR_cy , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
353+ {MP_QSTR_cr , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
354+ {MP_QSTR_padding , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to 0.0
355+ };
356+
357+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
358+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
359+
360+ int16_t x1 = args [ARG_x1 ].u_int ;
361+ int16_t y1 = args [ARG_y1 ].u_int ;
362+ int16_t x2 = args [ARG_x2 ].u_int ;
363+ int16_t y2 = args [ARG_y2 ].u_int ;
364+ int16_t cx = args [ARG_cx ].u_int ;
365+ int16_t cy = args [ARG_cy ].u_int ;
366+ int16_t cr = args [ARG_cr ].u_int ;
367+
368+ // Use default padding if None was passed
369+ mp_float_t padding = 0.0 ;
370+ if (args [ARG_padding ].u_obj != mp_const_none ) {
371+ padding = mp_obj_get_float (args [ARG_padding ].u_obj );
372+ }
373+
374+ bool result = common_hal_vectorio_line_circle_intersects (x1 , y1 , x2 , y2 , cx , cy , cr , padding );
375+
376+ if (result ) {
377+ return mp_const_true ;
378+ } else {
379+ return mp_const_false ;
380+ }
381+ }
382+ MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_line_circle_intersects_obj , 0 , vectorio_line_circle_intersects );
383+
384+
327385//| def polygon_circle_intersects(
328- //| points: List[Tuple[int, int]], cx: int, cy: int, cr: int
386+ //| points: List[Tuple[int, int]], polygon_x: int, polygon_y: int,
387+ //| cx: int, cy: int, cr: int, padding: float
329388//| ) -> bool:
330389//| """Checks for intersection between a polygon and a cricle.
331390//|
332391//| :param List[Tuple[int,int]] points: Vertices for the polygon
392+ //| :param int polygon_x: Polygon x coordinate. All other polygon points are relative to this
393+ //| :param int polygon_y: Polygon y coordinate. All other polygon points are relative to this
333394//| :param int cx: Circle center x coordinate
334395//| :param int cy: Circle center y coordinate
335- //| :param int cr: Circle radius"""
396+ //| :param int cr: Circle radius
397+ //| :param float padding: Extra padding outside of the line to consider as positive intersection"""
336398//| ...
337399//|
338400static mp_obj_t vectorio_polygon_circle_intersects (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
339- enum {ARG_points_list , ARG_cx , ARG_cy , ARG_cr };
401+ enum {ARG_points_list , ARG_polygon_x , ARG_polygon_y , ARG_cx , ARG_cy , ARG_cr , ARG_padding };
340402
341403 static const mp_arg_t allowed_args [] = {
342404 {MP_QSTR_points , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL }},
405+ {MP_QSTR_polygon_x , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
406+ {MP_QSTR_polygon_y , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
343407 {MP_QSTR_cx , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
344408 {MP_QSTR_cy , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
345- {MP_QSTR_cr , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }}
409+ {MP_QSTR_cr , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
410+ {MP_QSTR_padding , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to 0.0
346411 };
347412
348413 mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
349414 mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
350415
351416 mp_obj_t points_list = mp_arg_validate_type (args [ARG_points_list ].u_obj , & mp_type_list , MP_QSTR_points );
352417
418+ int16_t polygon_x = args [ARG_polygon_x ].u_int ;
419+ int16_t polygon_y = args [ARG_polygon_y ].u_int ;
420+
353421 int16_t cx = args [ARG_cx ].u_int ;
354422 int16_t cy = args [ARG_cy ].u_int ;
355423 int16_t cr = args [ARG_cr ].u_int ;
356424
357- bool result = common_hal_vectorio_polygon_circle_intersects (points_list , cx , cy , cr );
425+ // Use default padding if None was passed
426+ mp_float_t padding = 0.0 ;
427+ if (args [ARG_padding ].u_obj != mp_const_none ) {
428+ padding = mp_obj_get_float (args [ARG_padding ].u_obj );
429+ }
430+
431+ bool result = common_hal_vectorio_polygon_circle_intersects (
432+ points_list , polygon_x , polygon_y ,
433+ cx , cy , cr , padding
434+ );
435+
358436 if (result ) {
359437 return mp_const_true ;
360438 } else {
@@ -369,6 +447,7 @@ static const mp_rom_map_elem_t vectorio_module_globals_table[] = {
369447 { MP_ROM_QSTR (MP_QSTR_circle_rectangle_intersects ), MP_ROM_PTR (& vectorio_circle_rectangle_intersects_obj ) },
370448 { MP_ROM_QSTR (MP_QSTR_polygon_circle_intersects ), MP_ROM_PTR (& vectorio_polygon_circle_intersects_obj ) },
371449 { MP_ROM_QSTR (MP_QSTR_circle_circle_intersects ), MP_ROM_PTR (& vectorio_circle_circle_intersects_obj ) },
450+ { MP_ROM_QSTR (MP_QSTR_line_circle_intersects ), MP_ROM_PTR (& vectorio_line_circle_intersects_obj ) },
372451 { MP_ROM_QSTR (MP_QSTR_circle_contains_point ), MP_ROM_PTR (& vectorio_circle_contains_point_obj ) },
373452 { MP_ROM_QSTR (MP_QSTR_rectangle_contains_point ), MP_ROM_PTR (& vectorio_rectangle_contains_point_obj ) },
374453 { MP_ROM_QSTR (MP_QSTR_line_contains_point ), MP_ROM_PTR (& vectorio_line_contains_point_obj ) },
0 commit comments