vectorio: Simplify argument checking of x/y values
This commit is contained in:
parent
267ec1dc4f
commit
ef35ca1d3e
@ -4181,7 +4181,6 @@ msgid "unreadable attribute"
|
||||
msgstr ""
|
||||
|
||||
#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
|
||||
#: shared-module/vectorio/Polygon.c shared-module/vectorio/VectorShape.c
|
||||
msgid "unsupported %q type"
|
||||
msgstr ""
|
||||
|
||||
|
@ -80,9 +80,9 @@ STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_arg
|
||||
STATIC mp_obj_t displayio_shape_obj_set_boundary(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
displayio_shape_t *self = MP_OBJ_TO_PTR(args[0]);
|
||||
mp_int_t y = mp_arg_validate_type_int(args[1], MP_ARG_y);
|
||||
mp_int_t start_x = mp_arg_validate_type_int(args[1], MP_ARG_start_x);
|
||||
mp_int_t end_x = mp_arg_validate_type_int(args[1], MP_ARG_end_x);
|
||||
mp_int_t y = mp_arg_validate_type_int(args[1], MP_QSTR_y);
|
||||
mp_int_t start_x = mp_arg_validate_type_int(args[1], MP_QSTR_start_x);
|
||||
mp_int_t end_x = mp_arg_validate_type_int(args[1], MP_QSTR_end_x);
|
||||
common_hal_displayio_shape_set_boundary(self, y, start_x, end_x);
|
||||
|
||||
return mp_const_none;
|
||||
|
@ -14,7 +14,8 @@
|
||||
|
||||
|
||||
// Converts a list of points tuples to a flat list of ints for speedier internal use.
|
||||
// Also validates the points.
|
||||
// Also validates the points. If this fails due to invalid types or values, the
|
||||
// content of the points is undefined.
|
||||
static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple_list) {
|
||||
size_t len = 0;
|
||||
mp_obj_t *items;
|
||||
@ -26,12 +27,8 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
|
||||
}
|
||||
|
||||
if (self->len < 2 * len) {
|
||||
if (self->points_list != NULL) {
|
||||
VECTORIO_POLYGON_DEBUG("free(%d), ", sizeof(self->points_list));
|
||||
gc_free(self->points_list);
|
||||
}
|
||||
self->points_list = gc_alloc(2 * len * sizeof(uint16_t), false, false);
|
||||
VECTORIO_POLYGON_DEBUG("alloc(%p, %d)", self->points_list, 2 * len * sizeof(uint16_t));
|
||||
self->points_list = gc_realloc(self->points_list, 2 * len * sizeof(uint16_t), true);
|
||||
VECTORIO_POLYGON_DEBUG("realloc(%d) -> %p", self->points_list, 2 * len * sizeof(uint16_t));
|
||||
}
|
||||
self->len = 2 * len;
|
||||
|
||||
@ -42,17 +39,10 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
|
||||
|
||||
mp_arg_validate_length(tuple_len, 2, MP_QSTR_point);
|
||||
|
||||
mp_int_t x;
|
||||
mp_int_t y;
|
||||
if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &x)
|
||||
|| !mp_obj_get_int_maybe(tuple_items[ 1 ], &y)
|
||||
|| x < SHRT_MIN || x > SHRT_MAX || y < SHRT_MIN || y > SHRT_MAX
|
||||
) {
|
||||
gc_free(self->points_list);
|
||||
self->points_list = NULL;
|
||||
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
|
||||
self->len = 0;
|
||||
}
|
||||
mp_int_t x = mp_arg_validate_type_int(tuple_items[0], MP_QSTR_x);
|
||||
mp_arg_validate_int_range(x, SHRT_MIN, SHRT_MAX, MP_QSTR_x);
|
||||
mp_int_t y = mp_arg_validate_type_int(tuple_items[1], MP_QSTR_y);
|
||||
mp_arg_validate_int_range(y, SHRT_MIN, SHRT_MAX, MP_QSTR_y);
|
||||
self->points_list[2 * i ] = (int16_t)x;
|
||||
self->points_list[2 * i + 1] = (int16_t)y;
|
||||
}
|
||||
|
@ -277,12 +277,8 @@ void common_hal_vectorio_vector_shape_set_location(vectorio_vector_shape_t *self
|
||||
mp_obj_tuple_get(xy, &tuple_len, &tuple_items);
|
||||
mp_arg_validate_length(tuple_len, 2, MP_QSTR_location);
|
||||
|
||||
mp_int_t x;
|
||||
mp_int_t y;
|
||||
if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &x)
|
||||
|| !mp_obj_get_int_maybe(tuple_items[ 1 ], &y)) {
|
||||
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
|
||||
}
|
||||
mp_int_t x = mp_arg_validate_type_int(tuple_items[0], MP_QSTR_x);
|
||||
mp_int_t y = mp_arg_validate_type_int(tuple_items[0], MP_QSTR_y);
|
||||
bool dirty = false;
|
||||
if (self->x != x) {
|
||||
check_bounds_and_set_x(self, x);
|
||||
|
Loading…
x
Reference in New Issue
Block a user