@@ -20,17 +20,19 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
2020 size_t len = 0 ;
2121 mp_obj_t * items ;
2222 mp_obj_list_get (points_tuple_list , & len , & items );
23- VECTORIO_POLYGON_DEBUG ("polygon_points_list len: %d\n" , len );
23+ VECTORIO_POLYGON_DEBUG (" self. len: %d, len: %d, " , self -> len , len );
2424
2525 if ( len < 3 ) {
2626 mp_raise_TypeError_varg (translate ("Polygon needs at least 3 points" ));
2727 }
2828
2929 if ( self -> len < 2 * len ) {
3030 if ( self -> points_list != NULL ) {
31+ VECTORIO_POLYGON_DEBUG ("free(%d), " , sizeof (self -> points_list ));
3132 gc_free ( self -> points_list );
3233 }
3334 self -> points_list = gc_alloc ( 2 * len * sizeof (int ), false, false );
35+ VECTORIO_POLYGON_DEBUG ("alloc(%p, %d)" , self -> points_list , 2 * len * sizeof (int ));
3436 }
3537 self -> len = 2 * len ;
3638
@@ -56,22 +58,35 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
5658
5759
5860void common_hal_vectorio_polygon_construct (vectorio_polygon_t * self , mp_obj_t points_list ) {
59- VECTORIO_POLYGON_DEBUG ("%p polygon_construct\n " , self );
61+ VECTORIO_POLYGON_DEBUG ("%p polygon_construct: " , self );
6062 self -> points_list = NULL ;
6163 self -> len = 0 ;
6264 self -> on_dirty .obj = NULL ;
6365 _clobber_points_list ( self , points_list );
66+ VECTORIO_POLYGON_DEBUG ("\n" );
6467}
6568
6669
6770mp_obj_t common_hal_vectorio_polygon_get_points (vectorio_polygon_t * self ) {
68- return self -> points_list ;
71+ VECTORIO_POLYGON_DEBUG ("%p common_hal_vectorio_polygon_get_points {len: %d, points_list: %p}\n" , self , self -> len , self -> points_list );
72+ mp_obj_t list = mp_obj_new_list (0 , NULL );
73+
74+ for (size_t i = 0 ; i < self -> len ; i += 2 ) {
75+ mp_obj_t tuple [] = { mp_obj_new_int (self -> points_list [i ]), mp_obj_new_int (self -> points_list [i + 1 ]) };
76+ mp_obj_list_append (
77+ list ,
78+ mp_obj_new_tuple (2 , tuple )
79+ );
80+ }
81+ return list ;
6982}
7083void common_hal_vectorio_polygon_set_points (vectorio_polygon_t * self , mp_obj_t points_list ) {
84+ VECTORIO_POLYGON_DEBUG ("%p common_hal_vectorio_polygon_set_points: " , self );
7185 _clobber_points_list ( self , points_list );
7286 if (self -> on_dirty .obj != NULL ) {
7387 self -> on_dirty .event (self -> on_dirty .obj );
7488 }
89+ VECTORIO_POLYGON_DEBUG ("\n" );
7590}
7691
7792void common_hal_vectorio_polygon_set_on_dirty (vectorio_polygon_t * self , vectorio_event_t notification ) {
0 commit comments