|
9 | 9 | #include "py/obj.h" |
10 | 10 | #include "py/runtime.h" |
11 | 11 |
|
| 12 | + |
12 | 13 | #include "shared-bindings/vectorio/Circle.h" |
13 | 14 | #include "shared-bindings/vectorio/Polygon.h" |
14 | 15 | #include "shared-bindings/vectorio/Rectangle.h" |
| 16 | +#include "shared-bindings/vectorio/__init__.h" |
15 | 17 |
|
16 | 18 | //| """Lightweight 2D shapes for displays |
17 | 19 | //| |
|
37 | 39 | //| |
38 | 40 | //| """ |
39 | 41 |
|
| 42 | + |
| 43 | +//| def circle_rectangle_intersects( |
| 44 | +//| cx: int, cy: int, cr: int, rx: int, ry: int, rw: int, rh: int |
| 45 | +//| :param int cx: Circle center x coordinate |
| 46 | +//| :param int cy: Circle center y coordinate |
| 47 | +//| :param int cr: Circle radius |
| 48 | +//| :param int rx: Rectangle x coordinate |
| 49 | +//| :param int ry: Rectangle y coordinate |
| 50 | +//| :param int rw: Rectangle width |
| 51 | +//| :param int rh: Rectangle height |
| 52 | +//| ) -> None: |
| 53 | +static mp_obj_t vectorio_circle_rectangle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
| 54 | + enum {ARG_cx, ARG_cy, ARG_cr, ARG_rx, ARG_ry, ARG_rw, ARG_rh}; |
| 55 | + |
| 56 | + static const mp_arg_t allowed_args[] = { |
| 57 | + {MP_QSTR_cx, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 58 | + {MP_QSTR_cy, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 59 | + {MP_QSTR_cr, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 60 | + {MP_QSTR_rx, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 61 | + {MP_QSTR_ry, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 62 | + {MP_QSTR_rw, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 63 | + {MP_QSTR_rh, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 64 | + }; |
| 65 | + |
| 66 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 67 | + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 68 | + |
| 69 | + int16_t cx = args[ARG_cx].u_int; |
| 70 | + int16_t cy = args[ARG_cy].u_int; |
| 71 | + int16_t cr = args[ARG_cr].u_int; |
| 72 | + int16_t rx = args[ARG_rx].u_int; |
| 73 | + int16_t ry = args[ARG_ry].u_int; |
| 74 | + int16_t rw = args[ARG_rw].u_int; |
| 75 | + int16_t rh = args[ARG_rh].u_int; |
| 76 | + |
| 77 | + bool result = common_hal_vectorio_circle_rectangle_intersects(cx, cy, cr, rx, ry, rw, rh); |
| 78 | + if (result){ |
| 79 | + return mp_const_true; |
| 80 | + }else{ |
| 81 | + return mp_const_false; |
| 82 | + } |
| 83 | +} |
| 84 | +MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_circle_rectangle_intersects_obj, 0, vectorio_circle_rectangle_intersects); |
| 85 | + |
| 86 | + |
| 87 | +//| def rectangle_rectangle_intersects( |
| 88 | +//| r1x: int, r1y: int, r1w: int, r1h: int, |
| 89 | +// r2x: int, r2y: int, r2w: int, r2h: int |
| 90 | +//| |
| 91 | +//| :param int r1x: Rectangle x coordinate |
| 92 | +//| :param int r1y: Rectangle y coordinate |
| 93 | +//| :param int r1w: Rectangle width |
| 94 | +//| :param int r1h: Rectangle height |
| 95 | +//| :param int r2x: Other Rectangle x coordinate |
| 96 | +//| :param int r2y: Other Rectangle y coordinate |
| 97 | +//| :param int r2w: Other Rectangle width |
| 98 | +//| :param int r2h: Other Rectangle height |
| 99 | +//| ) -> None: |
| 100 | +static mp_obj_t vectorio_rectangle_rectangle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
| 101 | + enum {ARG_r1x, ARG_r1y, ARG_r1w, ARG_r1h, ARG_r2x, ARG_r2y, ARG_r2w, ARG_r2h}; |
| 102 | + |
| 103 | + static const mp_arg_t allowed_args[] = { |
| 104 | + {MP_QSTR_r1x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 105 | + {MP_QSTR_r1y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 106 | + {MP_QSTR_r1w, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 107 | + {MP_QSTR_r1h, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 108 | + {MP_QSTR_r2x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 109 | + {MP_QSTR_r2y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 110 | + {MP_QSTR_r2w, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 111 | + {MP_QSTR_r2h, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 112 | + }; |
| 113 | + |
| 114 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 115 | + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 116 | + |
| 117 | + int16_t r1x = args[ARG_r1x].u_int; |
| 118 | + int16_t r1y = args[ARG_r1y].u_int; |
| 119 | + int16_t r1w = args[ARG_r1w].u_int; |
| 120 | + int16_t r1h = args[ARG_r1h].u_int; |
| 121 | + |
| 122 | + int16_t r2x = args[ARG_r2x].u_int; |
| 123 | + int16_t r2y = args[ARG_r2y].u_int; |
| 124 | + int16_t r2w = args[ARG_r2w].u_int; |
| 125 | + int16_t r2h = args[ARG_r2h].u_int; |
| 126 | + |
| 127 | + |
| 128 | + bool result = common_hal_vectorio_rectangle_rectangle_intersects(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h); |
| 129 | + if (result){ |
| 130 | + return mp_const_true; |
| 131 | + }else{ |
| 132 | + return mp_const_false; |
| 133 | + } |
| 134 | +} |
| 135 | +MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_rectangle_rectangle_intersects_obj, 0, vectorio_rectangle_rectangle_intersects); |
| 136 | + |
| 137 | + |
| 138 | +//| def circle_circle_intersects( |
| 139 | +//| cx: int, cy: int, cr: int, rx: int, ry: int, rw: int, rh: int |
| 140 | +//| :param int c1x: Circle center x coordinate |
| 141 | +//| :param int c1y: Circle center y coordinate |
| 142 | +//| :param int c1r: Circle radius |
| 143 | +//| :param int c2x: Other Circle center x coordinate |
| 144 | +//| :param int c2y: Other Circle center y coordinate |
| 145 | +//| :param int c2r: Other Circle radius |
| 146 | +//| ) -> None: |
| 147 | +static mp_obj_t vectorio_circle_circle_intersects(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { |
| 148 | + enum {ARG_c1x, ARG_c1y, ARG_c1r, ARG_c2x, ARG_c2y, ARG_c2r}; |
| 149 | + |
| 150 | + static const mp_arg_t allowed_args[] = { |
| 151 | + {MP_QSTR_c1x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 152 | + {MP_QSTR_c1y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 153 | + {MP_QSTR_c1r, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 154 | + {MP_QSTR_c2x, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 155 | + {MP_QSTR_c2y, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 156 | + {MP_QSTR_c2r, MP_ARG_REQUIRED | MP_ARG_INT, {.u_obj = MP_OBJ_NULL}}, |
| 157 | + }; |
| 158 | + |
| 159 | + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; |
| 160 | + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); |
| 161 | + |
| 162 | + int16_t c1x = args[ARG_c1x].u_int; |
| 163 | + int16_t c1y = args[ARG_c1y].u_int; |
| 164 | + int16_t c1r = args[ARG_c1r].u_int; |
| 165 | + int16_t c2x = args[ARG_c2x].u_int; |
| 166 | + int16_t c2y = args[ARG_c2y].u_int; |
| 167 | + int16_t c2r = args[ARG_c2r].u_int; |
| 168 | + |
| 169 | + bool result = common_hal_vectorio_circle_circle_intersects(c1x, c1y, c1r, c2x, c2y, c2r); |
| 170 | + if (result){ |
| 171 | + return mp_const_true; |
| 172 | + }else{ |
| 173 | + return mp_const_false; |
| 174 | + } |
| 175 | +} |
| 176 | +MP_DEFINE_CONST_FUN_OBJ_KW(vectorio_circle_circle_intersects_obj, 0, vectorio_circle_circle_intersects); |
| 177 | + |
40 | 178 | static const mp_rom_map_elem_t vectorio_module_globals_table[] = { |
41 | 179 | { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_vectorio) }, |
| 180 | + { MP_ROM_QSTR(MP_QSTR_circle_rectangle_intersects), MP_ROM_PTR(&vectorio_circle_rectangle_intersects_obj) }, |
| 181 | + { MP_ROM_QSTR(MP_QSTR_circle_circle_intersects), MP_ROM_PTR(&vectorio_circle_circle_intersects_obj) }, |
| 182 | + { MP_ROM_QSTR(MP_QSTR_rectangle_rectangle_intersects), MP_ROM_PTR(&vectorio_rectangle_rectangle_intersects_obj) }, |
42 | 183 | { MP_ROM_QSTR(MP_QSTR_Circle), MP_ROM_PTR(&vectorio_circle_type) }, |
43 | 184 | { MP_ROM_QSTR(MP_QSTR_Polygon), MP_ROM_PTR(&vectorio_polygon_type) }, |
44 | 185 | { MP_ROM_QSTR(MP_QSTR_Rectangle), MP_ROM_PTR(&vectorio_rectangle_type) }, |
|
0 commit comments