@@ -185,10 +185,193 @@ static mp_obj_t vectorio_circle_circle_intersects(size_t n_args, const mp_obj_t
185185}
186186MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_circle_circle_intersects_obj , 0 , vectorio_circle_circle_intersects );
187187
188+ //| def circle_contains_point(
189+ //| cx: int, cy: int, cr: int, px: int, py: int
190+ //| ) -> bool:
191+ //| """Checks whether a circle contains the given point
192+ //|
193+ //| :param int cx: Circle center x coordinate
194+ //| :param int cy: Circle center y coordinate
195+ //| :param int cr: Circle radius
196+ //| :param int px: Point x coordinate
197+ //| :param int py: Point y coordinate
198+ //| ...
199+ //|
200+ static mp_obj_t vectorio_circle_contains_point (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
201+ enum {ARG_cx , ARG_cy , ARG_cr , ARG_px , ARG_py };
202+
203+ static const mp_arg_t allowed_args [] = {
204+ {MP_QSTR_cx , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
205+ {MP_QSTR_cy , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
206+ {MP_QSTR_cr , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
207+ {MP_QSTR_px , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
208+ {MP_QSTR_py , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
209+ };
210+
211+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
212+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
213+
214+ int16_t cx = args [ARG_cx ].u_int ;
215+ int16_t cy = args [ARG_cy ].u_int ;
216+ int16_t cr = args [ARG_cr ].u_int ;
217+ int16_t px = args [ARG_px ].u_int ;
218+ int16_t py = args [ARG_py ].u_int ;
219+
220+ bool result = common_hal_vectorio_circle_contains_point (cx , cy , cr , px , py );
221+ if (result ) {
222+ return mp_const_true ;
223+ } else {
224+ return mp_const_false ;
225+ }
226+ }
227+ MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_circle_contains_point_obj , 0 , vectorio_circle_contains_point );
228+
229+ //| def rectangle_contains_point(
230+ //| rx: int, ry: int, rw: int, rh: int, px: int, py: int
231+ //| ) -> bool:
232+ //| """Checks whether a rectangle contains the given point
233+ //|
234+ //| :param int rx: Rectangle x coordinate
235+ //| :param int ry: Rectangle y coordinate
236+ //| :param int rw: Rectangle width
237+ //| :param int rh: Rectangle height
238+ //| :param int px: Point x coordinate
239+ //| :param int py: Point y coordinate
240+ //| ...
241+ //|
242+ static mp_obj_t vectorio_rectangle_contains_point (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
243+ enum {ARG_rx , ARG_ry , ARG_rw , ARG_rh , ARG_px , ARG_py };
244+
245+ static const mp_arg_t allowed_args [] = {
246+ {MP_QSTR_rx , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
247+ {MP_QSTR_ry , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
248+ {MP_QSTR_rw , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
249+ {MP_QSTR_rh , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
250+ {MP_QSTR_px , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
251+ {MP_QSTR_py , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
252+ };
253+
254+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
255+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
256+
257+ int16_t rx = args [ARG_rx ].u_int ;
258+ int16_t ry = args [ARG_ry ].u_int ;
259+ int16_t rw = args [ARG_rw ].u_int ;
260+ int16_t rh = args [ARG_rh ].u_int ;
261+ int16_t px = args [ARG_px ].u_int ;
262+ int16_t py = args [ARG_py ].u_int ;
263+
264+ bool result = common_hal_vectorio_rectangle_contains_point (rx , ry , rw , rh , px , py );
265+ if (result ) {
266+ return mp_const_true ;
267+ } else {
268+ return mp_const_false ;
269+ }
270+ }
271+ MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_rectangle_contains_point_obj , 0 , vectorio_rectangle_contains_point );
272+
273+
274+ //| def line_contains_point(
275+ //| x1: int, y1: int, x2: int, y2: int, px: int, py: int
276+ //| ) -> bool:
277+ //| """Checks whether a line contains the given point
278+ //|
279+ //| :param int x1: Line x1 coordinate
280+ //| :param int y1: Line y1 coordinate
281+ //| :param int x2: Line x2 coordinate
282+ //| :param int y2: Line y2 coordinate
283+ //| :param int px: Point x coordinate
284+ //| :param int py: Point y coordinate
285+ //| :param float padding: Extra padding outside of the line to consider as positive intersection
286+ //| ...
287+ //|
288+ static mp_obj_t vectorio_line_contains_point (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
289+ enum {ARG_x1 , ARG_y1 , ARG_x2 , ARG_y2 , ARG_px , ARG_py , ARG_padding };
290+
291+ static const mp_arg_t allowed_args [] = {
292+ {MP_QSTR_x1 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
293+ {MP_QSTR_y1 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
294+ {MP_QSTR_x2 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
295+ {MP_QSTR_y2 , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
296+ {MP_QSTR_px , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
297+ {MP_QSTR_py , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
298+ {MP_QSTR_padding , MP_ARG_KW_ONLY | MP_ARG_OBJ , {.u_obj = mp_const_none } }, // None convert to 0.0
299+ };
300+
301+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
302+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
303+
304+ int16_t x1 = args [ARG_x1 ].u_int ;
305+ int16_t y1 = args [ARG_y1 ].u_int ;
306+ int16_t x2 = args [ARG_x2 ].u_int ;
307+ int16_t y2 = args [ARG_y2 ].u_int ;
308+ int16_t px = args [ARG_px ].u_int ;
309+ int16_t py = args [ARG_py ].u_int ;
310+
311+ // Confirm the angle value
312+ mp_float_t padding = 0.0 ;
313+ if (args [ARG_padding ].u_obj != mp_const_none ) {
314+ padding = mp_obj_get_float (args [ARG_padding ].u_obj );
315+ }
316+
317+ bool result = common_hal_vectorio_line_contains_point (x1 , y1 , x2 , y2 , px , py , padding );
318+ if (result ) {
319+ return mp_const_true ;
320+ } else {
321+ return mp_const_false ;
322+ }
323+ }
324+ MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_line_contains_point_obj , 0 , vectorio_line_contains_point );
325+
326+
327+ //| def polygon_circle_intersects(
328+ //| points: List[Tuple[int, int]], cx: int, cy: int, cr: int
329+ //| ) -> bool:
330+ //| """Checks for intersection between a polygon and a cricle.
331+ //|
332+ //| :param List[Tuple[int,int]] points: Vertices for the polygon
333+ //| :param int cx: Circle center x coordinate
334+ //| :param int cy: Circle center y coordinate
335+ //| :param int cr: Circle radius"""
336+ //| ...
337+ //|
338+ static 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 };
340+
341+ static const mp_arg_t allowed_args [] = {
342+ {MP_QSTR_points , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = MP_OBJ_NULL }},
343+ {MP_QSTR_cx , MP_ARG_REQUIRED | MP_ARG_INT , {.u_obj = MP_OBJ_NULL }},
344+ {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 }}
346+ };
347+
348+ mp_arg_val_t args [MP_ARRAY_SIZE (allowed_args )];
349+ mp_arg_parse_all (n_args , pos_args , kw_args , MP_ARRAY_SIZE (allowed_args ), allowed_args , args );
350+
351+ mp_obj_t points_list = mp_arg_validate_type (args [ARG_points_list ].u_obj , & mp_type_list , MP_QSTR_points );
352+
353+ int16_t cx = args [ARG_cx ].u_int ;
354+ int16_t cy = args [ARG_cy ].u_int ;
355+ int16_t cr = args [ARG_cr ].u_int ;
356+
357+ bool result = common_hal_vectorio_polygon_circle_intersects (points_list , cx , cy , cr );
358+ if (result ) {
359+ return mp_const_true ;
360+ } else {
361+ return mp_const_false ;
362+ }
363+ }
364+ MP_DEFINE_CONST_FUN_OBJ_KW (vectorio_polygon_circle_intersects_obj , 0 , vectorio_polygon_circle_intersects );
365+
366+
188367static const mp_rom_map_elem_t vectorio_module_globals_table [] = {
189368 { MP_ROM_QSTR (MP_QSTR___name__ ), MP_ROM_QSTR (MP_QSTR_vectorio ) },
190369 { MP_ROM_QSTR (MP_QSTR_circle_rectangle_intersects ), MP_ROM_PTR (& vectorio_circle_rectangle_intersects_obj ) },
370+ { MP_ROM_QSTR (MP_QSTR_polygon_circle_intersects ), MP_ROM_PTR (& vectorio_polygon_circle_intersects_obj ) },
191371 { MP_ROM_QSTR (MP_QSTR_circle_circle_intersects ), MP_ROM_PTR (& vectorio_circle_circle_intersects_obj ) },
372+ { MP_ROM_QSTR (MP_QSTR_circle_contains_point ), MP_ROM_PTR (& vectorio_circle_contains_point_obj ) },
373+ { MP_ROM_QSTR (MP_QSTR_rectangle_contains_point ), MP_ROM_PTR (& vectorio_rectangle_contains_point_obj ) },
374+ { MP_ROM_QSTR (MP_QSTR_line_contains_point ), MP_ROM_PTR (& vectorio_line_contains_point_obj ) },
192375 { MP_ROM_QSTR (MP_QSTR_rectangle_rectangle_intersects ), MP_ROM_PTR (& vectorio_rectangle_rectangle_intersects_obj ) },
193376 { MP_ROM_QSTR (MP_QSTR_Circle ), MP_ROM_PTR (& vectorio_circle_type ) },
194377 { MP_ROM_QSTR (MP_QSTR_Polygon ), MP_ROM_PTR (& vectorio_polygon_type ) },
0 commit comments