Skip to content

Commit 051d7a9

Browse files
committed
fix rotation and mirroring
now works with all vector shapes, even those with internal reference locations that are negative. All shape locations are anchored to their 0,0 but they can display pixels from negative coordinates if the shape's location on the screen would have room for it.
1 parent b5837b1 commit 051d7a9

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

shared-module/vectorio/VectorShape.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
#include "shared-bindings/vectorio/Rectangle.h"
1515

1616
// Lifecycle actions.
17-
// #define VECTORIO_SHAPE_DEBUG(...) (void)0
18-
#define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
17+
#define VECTORIO_SHAPE_DEBUG(...) (void)0
18+
// #define VECTORIO_SHAPE_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
1919

2020

2121
// Used in both logging and ifdefs, for extra variables
2222
// #define VECTORIO_PERF(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2323

2424

2525
// Really verbose.
26-
// #define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
27-
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
26+
#define VECTORIO_SHAPE_PIXEL_DEBUG(...) (void)0
27+
// #define VECTORIO_SHAPE_PIXEL_DEBUG(...) mp_printf(&mp_plat_print, __VA_ARGS__)
2828

2929
#define U32_TO_BINARY_FMT "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
3030
#define U32_TO_BINARY(u32) \
@@ -244,15 +244,8 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
244244
displayio_input_pixel_t input_pixel;
245245
displayio_output_pixel_t output_pixel;
246246

247-
uint16_t width_px_indices;
248-
uint16_t height_px_indices;
249-
if (self->absolute_transform->transpose_xy) {
250-
width_px_indices = displayio_area_height(&self->current_area) - 1;
251-
height_px_indices = displayio_area_width(&self->current_area) - 1;
252-
} else {
253-
width_px_indices = displayio_area_width(&self->current_area) - 1;
254-
height_px_indices = displayio_area_height(&self->current_area) - 1;
255-
}
247+
displayio_area_t shape_area;
248+
self->ishape.get_area(self->ishape.shape, &shape_area);
256249

257250
uint16_t mask_start_px = line_dirty_offset_px;
258251
for (input_pixel.y = overlap.y1; input_pixel.y < overlap.y2; ++input_pixel.y) {
@@ -275,22 +268,24 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
275268
if (self->absolute_transform->transpose_xy) {
276269
pixel_to_get_x = input_pixel.y - self->absolute_transform->y - self->absolute_transform->dy * self->x;
277270
pixel_to_get_y = input_pixel.x - self->absolute_transform->x - self->absolute_transform->dx * self->y;
271+
VECTORIO_SHAPE_PIXEL_DEBUG(" a(%3d, %3d)", pixel_to_get_x, pixel_to_get_y);
278272

279273
if (self->absolute_transform->mirror_x) {
280-
pixel_to_get_y = height_px_indices - pixel_to_get_y;
274+
pixel_to_get_y = shape_area.y2 - 1 - (pixel_to_get_y - shape_area.y1);
281275
}
282276
if (self->absolute_transform->mirror_y) {
283-
pixel_to_get_x = width_px_indices - pixel_to_get_x;
277+
pixel_to_get_x = shape_area.x2 - 1 - (pixel_to_get_x - shape_area.x1);
284278
}
285279
} else {
286280
pixel_to_get_x = input_pixel.x - self->absolute_transform->x - self->absolute_transform->dx * self->x;
287281
pixel_to_get_y = input_pixel.y - self->absolute_transform->y - self->absolute_transform->dy * self->y;
282+
VECTORIO_SHAPE_PIXEL_DEBUG(" a(%3d, %3d)", pixel_to_get_x, pixel_to_get_y);
288283

289284
if (self->absolute_transform->mirror_x) {
290-
pixel_to_get_x = width_px_indices - pixel_to_get_x;
285+
pixel_to_get_x = shape_area.x2 - 1 - (pixel_to_get_x - shape_area.x1);
291286
}
292287
if (self->absolute_transform->mirror_y) {
293-
pixel_to_get_y = height_px_indices - pixel_to_get_y;
288+
pixel_to_get_y = shape_area.y2 - 1 - (pixel_to_get_y - shape_area.y1);
294289
}
295290
}
296291

0 commit comments

Comments
 (0)