@@ -20,6 +20,7 @@ typedef struct _ModPicoGraphics_obj_t {
20
20
21
21
typedef struct _VECTOR_obj_t {
22
22
mp_obj_base_t base;
23
+ void *mem;
23
24
PicoVector *vector;
24
25
} _VECTOR_obj_t;
25
26
@@ -132,10 +133,10 @@ mp_obj_t RECTANGLE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_k
132
133
self->contour .points = m_new (pretty_poly::point_t <picovector_point_type>, 4 );
133
134
self->contour .count = 4 ;
134
135
135
- self->contour .points [0 ] = {float (x), float (y)};
136
- self->contour .points [1 ] = {float (x + w), float (y)};
137
- self->contour .points [2 ] = {float (x + w), float (y + h)};
138
- self->contour .points [3 ] = {float (x), float (y + h)};
136
+ self->contour .points [0 ] = {picovector_point_type (x), picovector_point_type (y)};
137
+ self->contour .points [1 ] = {picovector_point_type (x + w), picovector_point_type (y)};
138
+ self->contour .points [2 ] = {picovector_point_type (x + w), picovector_point_type (y + h)};
139
+ self->contour .points [3 ] = {picovector_point_type (x), picovector_point_type (y + h)};
139
140
140
141
return self;
141
142
}
@@ -286,10 +287,12 @@ mp_obj_t VECTOR_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw,
286
287
_VECTOR_obj_t *self = m_new_obj (_VECTOR_obj_t);
287
288
self->base .type = &VECTOR_type;
288
289
ModPicoGraphics_obj_t *graphics = (ModPicoGraphics_obj_t *)MP_OBJ_TO_PTR (args[ARG_picographics].u_obj );
289
-
290
- void *mem = m_tracked_calloc (PicoVector::pretty_poly_buffer_size (), sizeof (uint8_t ));
291
290
292
- self->vector = m_new_class (PicoVector, graphics->graphics , mem);
291
+ // The PicoVector class calls `pretty_poly::init()` with the memory region
292
+ // it does not store a pointer to this, so we need to store one ourselves
293
+ self->mem = m_new (uint8_t , PicoVector::pretty_poly_buffer_size ());
294
+
295
+ self->vector = m_new_class (PicoVector, graphics->graphics , self->mem );
293
296
294
297
return self;
295
298
}
@@ -427,7 +430,7 @@ mp_obj_t VECTOR_draw(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
427
430
if (!MP_OBJ_IS_TYPE (poly_obj, &POLYGON_type)) mp_raise_TypeError (" draw: Polygon required." );
428
431
429
432
_POLYGON_obj_t *poly = MP_OBJ_TO_PTR2 (poly_obj, _POLYGON_obj_t);
430
- contours.push_back (poly->contour );
433
+ contours.emplace_back (poly->contour . points , poly-> contour . count );
431
434
}
432
435
433
436
self->vector ->polygon (contours);
0 commit comments