@@ -166,8 +166,10 @@ void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
166
166
vectorio_ishape_t ishape ,
167
167
mp_obj_t pixel_shader , int32_t x , int32_t y ) {
168
168
VECTORIO_SHAPE_DEBUG ("%p vector_shape_construct x:%3d, y:%3d\n" , self , x , y );
169
- common_hal_vectorio_vector_shape_set_x (self , x );
170
- common_hal_vectorio_vector_shape_set_y (self , y );
169
+ vectorio_vector_shape_validate_x_bounds (x );
170
+ self -> x = x ;
171
+ vectorio_vector_shape_validate_y_bounds (y );
172
+ self -> y = y ;
171
173
self -> pixel_shader = pixel_shader ;
172
174
self -> ishape = ishape ;
173
175
self -> absolute_transform = & null_transform ; // Critical to have a valid transform before getting screen area.
@@ -184,16 +186,14 @@ mp_int_t common_hal_vectorio_vector_shape_get_x(vectorio_vector_shape_t *self) {
184
186
}
185
187
186
188
187
- bool common_hal_vectorio_vector_shape_set_x (vectorio_vector_shape_t * self , mp_int_t x ) {
189
+ void common_hal_vectorio_vector_shape_set_x (vectorio_vector_shape_t * self , mp_int_t x ) {
188
190
VECTORIO_SHAPE_DEBUG ("%p set_x %d\n" , self , x );
189
191
if (self -> x == x ) {
190
- return false; // it's not dirty
191
- }
192
- if (x < SHRT_MIN || x > SHRT_MAX ) {
193
- mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
192
+ return ;
194
193
}
194
+ vectorio_vector_shape_validate_x_bounds (x );
195
195
self -> x = x ;
196
- return true; // it's dirty
196
+ common_hal_vectorio_vector_shape_set_dirty ( self );
197
197
}
198
198
199
199
@@ -203,16 +203,14 @@ mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self) {
203
203
}
204
204
205
205
206
- bool common_hal_vectorio_vector_shape_set_y (vectorio_vector_shape_t * self , mp_int_t y ) {
206
+ void common_hal_vectorio_vector_shape_set_y (vectorio_vector_shape_t * self , mp_int_t y ) {
207
207
VECTORIO_SHAPE_DEBUG ("%p set_y %d\n" , self , y );
208
208
if (self -> y == y ) {
209
- return false; // it's not dirty
210
- }
211
- if (y < SHRT_MIN || y > SHRT_MAX ) {
212
- mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
209
+ return ;
213
210
}
211
+ vectorio_vector_shape_validate_y_bounds (y );
214
212
self -> y = y ;
215
- return true; // it's dirty
213
+ common_hal_vectorio_vector_shape_set_dirty ( self );
216
214
}
217
215
218
216
mp_obj_tuple_t * common_hal_vectorio_vector_shape_get_location (vectorio_vector_shape_t * self ) {
@@ -239,14 +237,37 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
239
237
|| !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )) {
240
238
mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
241
239
}
242
- bool dirty = common_hal_vectorio_vector_shape_set_x (self , x );
243
- dirty |= common_hal_vectorio_vector_shape_set_y (self , y );
240
+ bool dirty = false;
241
+ if (self -> x != x ) {
242
+ vectorio_vector_shape_validate_x_bounds (x );
243
+ self -> x = x ;
244
+ dirty = true;
245
+ }
246
+ if (self -> y != y ) {
247
+ vectorio_vector_shape_validate_y_bounds (y );
248
+ self -> y = y ;
249
+ dirty = true;
250
+ }
244
251
if (dirty ) {
245
252
common_hal_vectorio_vector_shape_set_dirty (self );
246
253
}
247
254
}
248
255
249
256
257
+ void vectorio_vector_shape_validate_x_bounds (mp_int_t x ) {
258
+ if (x < SHRT_MIN || x > SHRT_MAX ) {
259
+ mp_raise_ValueError_varg (translate ("%q must be between %d and %d" ), MP_QSTR_x , SHRT_MIN , SHRT_MAX );
260
+ }
261
+ }
262
+
263
+
264
+ void vectorio_vector_shape_validate_y_bounds (mp_int_t y ) {
265
+ if (y < SHRT_MIN || y > SHRT_MAX ) {
266
+ mp_raise_ValueError_varg (translate ("%q must be between %d and %d" ), MP_QSTR_y , SHRT_MIN , SHRT_MAX );
267
+ }
268
+ }
269
+
270
+
250
271
mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader (vectorio_vector_shape_t * self ) {
251
272
VECTORIO_SHAPE_DEBUG ("%p get_pixel_shader\n" , self );
252
273
return self -> pixel_shader ;
0 commit comments