Skip to content

Commit efeae0d

Browse files
committed
fix 3169: Polygon.points property
The getter for vectorio.Polygon#points was not updated with the data type change of the stored points list. This moves the implementation to shared_module and updates the data type to reflect the actual state.
1 parent 9cdf5e1 commit efeae0d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

shared-bindings/vectorio/Polygon.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
4949
//|
5050
STATIC mp_obj_t vectorio_polygon_obj_get_points(mp_obj_t self_in) {
5151
vectorio_polygon_t *self = MP_OBJ_TO_PTR(self_in);
52-
mp_obj_t list = mp_obj_new_list(0, NULL);
53-
54-
size_t len = 0;
55-
mp_obj_t *items;
56-
mp_obj_list_get(common_hal_vectorio_polygon_get_points(self), &len, &items);
57-
58-
for (size_t i = 0; i < len; i += 2) {
59-
mp_obj_t tuple[] = { items[i], items[i+1] };
60-
mp_obj_list_append(
61-
list,
62-
mp_obj_new_tuple(2, tuple)
63-
);
64-
}
65-
return list;
52+
return common_hal_vectorio_polygon_get_points(self);
6653
}
6754
MP_DEFINE_CONST_FUN_OBJ_1(vectorio_polygon_get_points_obj, vectorio_polygon_obj_get_points);
6855

shared-module/vectorio/Polygon.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5860
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);
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

6770
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(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
}
7083
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);
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

7792
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {

0 commit comments

Comments
 (0)