From d7c64d7e566bf4a1ed7a6a6f2bbd28714307f79a Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Thu, 30 Mar 2023 14:52:26 +0900 Subject: [PATCH] graphics: support shear operation on transformation matrices --- base/usr/include/toaru/graphics.h | 1 + lib/graphics.c | 7 +++++++ lib/kuroko/_yutani2.c | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/base/usr/include/toaru/graphics.h b/base/usr/include/toaru/graphics.h index 4f6275b5..afce2f93 100644 --- a/base/usr/include/toaru/graphics.h +++ b/base/usr/include/toaru/graphics.h @@ -133,6 +133,7 @@ extern void gfx_matrix_identity(gfx_matrix_t); extern void gfx_matrix_scale(gfx_matrix_t, double x, double y); extern void gfx_matrix_translate(gfx_matrix_t, double x, double y); extern void gfx_matrix_rotate(gfx_matrix_t, double rotation); +extern void gfx_matrix_shear(gfx_matrix_t matrix, double x, double y); extern void gfx_apply_matrix(double x, double y, gfx_matrix_t matrix, double *out_x, double *out_y); diff --git a/lib/graphics.c b/lib/graphics.c index 5619ff4d..345b010e 100644 --- a/lib/graphics.c +++ b/lib/graphics.c @@ -896,6 +896,13 @@ void gfx_matrix_scale(gfx_matrix_t matrix, double x, double y) { }); } +void gfx_matrix_shear(gfx_matrix_t matrix, double x, double y) { + multiply_matrix(matrix, (gfx_matrix_t){ + {1.0, x, 0.0}, + {y, 1.0, 0.0}, + }); +} + void gfx_matrix_rotate(gfx_matrix_t matrix, double r) { multiply_matrix(matrix, (gfx_matrix_t){ { cos(r), -sin(r), 0.0}, diff --git a/lib/kuroko/_yutani2.c b/lib/kuroko/_yutani2.c index 097b7a8e..c5ee38f2 100644 --- a/lib/kuroko/_yutani2.c +++ b/lib/kuroko/_yutani2.c @@ -903,6 +903,13 @@ KRK_Method(TransformMatrix,rotate) { return NONE_VAL(); } +KRK_Method(TransformMatrix,shear) { + double x, y; + if (!krk_parseArgs(".dd", (const char*[]){"x","y"}, &x, &y)) return NONE_VAL(); + gfx_matrix_shear(self->matrix,x,y); + return NONE_VAL(); +} + KRK_Method(TransformMatrix,apply) { double x, y; if (!krk_parseArgs(".dd", (const char*[]){"x","y"}, &x, &y)) return NONE_VAL(); @@ -2113,6 +2120,7 @@ KrkValue krk_module_onload__yutani2(void) { BIND_METHOD(TransformMatrix,scale); BIND_METHOD(TransformMatrix,translate); BIND_METHOD(TransformMatrix,rotate); + BIND_METHOD(TransformMatrix,shear); BIND_METHOD(TransformMatrix,apply); krk_finalizeClass(TransformMatrix);