@@ -20,17 +20,19 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
20
20
size_t len = 0 ;
21
21
mp_obj_t * items ;
22
22
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 );
24
24
25
25
if ( len < 3 ) {
26
26
mp_raise_TypeError_varg (translate ("Polygon needs at least 3 points" ));
27
27
}
28
28
29
29
if ( self -> len < 2 * len ) {
30
30
if ( self -> points_list != NULL ) {
31
+ VECTORIO_POLYGON_DEBUG ("free(%d), " , sizeof (self -> points_list ));
31
32
gc_free ( self -> points_list );
32
33
}
33
34
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 ));
34
36
}
35
37
self -> len = 2 * len ;
36
38
@@ -56,22 +58,35 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
56
58
57
59
58
60
void 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 );
60
62
self -> points_list = NULL ;
61
63
self -> len = 0 ;
62
64
self -> on_dirty .obj = NULL ;
63
65
_clobber_points_list ( self , points_list );
66
+ VECTORIO_POLYGON_DEBUG ("\n" );
64
67
}
65
68
66
69
67
70
mp_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 (self -> len /2 , 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 ;
69
82
}
70
83
void 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 );
71
85
_clobber_points_list ( self , points_list );
72
86
if (self -> on_dirty .obj != NULL ) {
73
87
self -> on_dirty .event (self -> on_dirty .obj );
74
88
}
89
+ VECTORIO_POLYGON_DEBUG ("\n" );
75
90
}
76
91
77
92
void common_hal_vectorio_polygon_set_on_dirty (vectorio_polygon_t * self , vectorio_event_t notification ) {
0 commit comments