@@ -217,8 +217,7 @@ void POLYGON_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t ki
217
217
(void )kind;
218
218
_POLYGON_obj_t *self = MP_OBJ_TO_PTR2 (self_in, _POLYGON_obj_t);
219
219
220
- mp_print_str (print, " Polygon(" );
221
- mp_print_str (print, " , points = " );
220
+ mp_print_str (print, " Polygon(points = " );
222
221
mp_obj_print_helper (print, mp_obj_new_int (self->contour .count ), PRINT_REPR);
223
222
mp_print_str (print, " , bounds = " );
224
223
mp_obj_print_helper (print, mp_obj_new_int (self->contour .bounds ().x ), PRINT_REPR);
@@ -238,6 +237,38 @@ mp_obj_t POLYGON__del__(mp_obj_t self_in) {
238
237
return mp_const_none;
239
238
}
240
239
240
+ typedef struct _mp_obj_polygon_it_t {
241
+ mp_obj_base_t base;
242
+ mp_fun_1_t iternext;
243
+ mp_obj_t polygon;
244
+ size_t cur;
245
+ } mp_obj_polygon_it_t ;
246
+
247
+ STATIC mp_obj_t py_image_it_iternext (mp_obj_t self_in) {
248
+ mp_obj_polygon_it_t *self = MP_OBJ_TO_PTR2 (self_in, mp_obj_polygon_it_t );
249
+ _POLYGON_obj_t *polygon = MP_OBJ_TO_PTR2 (self->polygon , _POLYGON_obj_t);
250
+
251
+ // mp_printf(&mp_plat_print, "points: %d, current: %d\n", polygon->contour.count, self->cur);
252
+
253
+ if (self->cur >= polygon->contour .count ) return MP_OBJ_STOP_ITERATION;
254
+
255
+ mp_obj_t tuple[2 ];
256
+ tuple[0 ] = mp_obj_new_int ((int )(polygon->contour .points [self->cur ].x ));
257
+ tuple[1 ] = mp_obj_new_int ((int )(polygon->contour .points [self->cur ].y ));
258
+
259
+ self->cur ++;
260
+ return mp_obj_new_tuple (2 , tuple);
261
+ }
262
+
263
+ mp_obj_t POLYGON_getiter (mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
264
+ mp_obj_polygon_it_t *o = (mp_obj_polygon_it_t *)iter_buf;
265
+ o->base .type = &mp_type_polymorph_iter;
266
+ o->iternext = py_image_it_iternext;
267
+ o->polygon = o_in;
268
+ o->cur = 0 ;
269
+ return MP_OBJ_FROM_PTR (o);
270
+ }
271
+
241
272
/* VECTOR */
242
273
243
274
mp_obj_t VECTOR_make_new (const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
0 commit comments