@@ -166,8 +166,10 @@ void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
166166 vectorio_ishape_t ishape ,
167167 mp_obj_t pixel_shader , int32_t x , int32_t y ) {
168168 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 ;
171173 self -> pixel_shader = pixel_shader ;
172174 self -> ishape = ishape ;
173175 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) {
184186}
185187
186188
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 ) {
188190 VECTORIO_SHAPE_DEBUG ("%p set_x %d\n" , self , x );
189191 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 ;
194193 }
194+ vectorio_vector_shape_validate_x_bounds (x );
195195 self -> x = x ;
196- return true; // it's dirty
196+ common_hal_vectorio_vector_shape_set_dirty ( self );
197197}
198198
199199
@@ -203,16 +203,14 @@ mp_int_t common_hal_vectorio_vector_shape_get_y(vectorio_vector_shape_t *self) {
203203}
204204
205205
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 ) {
207207 VECTORIO_SHAPE_DEBUG ("%p set_y %d\n" , self , y );
208208 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 ;
213210 }
211+ vectorio_vector_shape_validate_y_bounds (y );
214212 self -> y = y ;
215- return true; // it's dirty
213+ common_hal_vectorio_vector_shape_set_dirty ( self );
216214}
217215
218216mp_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
239237 || !mp_obj_get_int_maybe (tuple_items [ 1 ], & y )) {
240238 mp_raise_ValueError_varg (translate ("unsupported %q type" ), MP_QSTR_point );
241239 }
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+ }
244251 if (dirty ) {
245252 common_hal_vectorio_vector_shape_set_dirty (self );
246253 }
247254}
248255
249256
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+
250271mp_obj_t common_hal_vectorio_vector_shape_get_pixel_shader (vectorio_vector_shape_t * self ) {
251272 VECTORIO_SHAPE_DEBUG ("%p get_pixel_shader\n" , self );
252273 return self -> pixel_shader ;
0 commit comments