From 554025ed7d4b60a428953d084ed987331f26d0bb Mon Sep 17 00:00:00 2001 From: mateuszJS Date: Sun, 24 Aug 2025 22:48:37 +0200 Subject: [PATCH 1/5] simplify rotation a bit --- src/logic/transform_ui.zig | 49 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/logic/transform_ui.zig b/src/logic/transform_ui.zig index 0fb8fce..60a0aad 100644 --- a/src/logic/transform_ui.zig +++ b/src/logic/transform_ui.zig @@ -113,20 +113,20 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra }, 9 => { // rotation - const asset_center = points[0].mid(points[2]); + const asset_center = un_rotated_points[0].mid(un_rotated_points[2]); const asset_new_angle = std.math.atan2( - asset_center.y - raw_y, - asset_center.x - raw_x, + asset_center.y - pointer.y, + asset_center.x - pointer.x, ) - std.math.pi / 2.0; - for (points) |*point| { - const current_angle = std.math.atan2(point.y - asset_center.y, point.x - asset_center.x); - const default_angle = current_angle - asset_angle_y; // angle without any user rotation introduced - const length = std.math.hypot(point.x - asset_center.x, point.y - asset_center.y); - const new_angle = default_angle + asset_new_angle; + var new_matrix = Matrix3x3.translation(asset_center.x, asset_center.y); + new_matrix.rotate(asset_new_angle); + new_matrix.translate(-asset_center.x, -asset_center.y); - point.x = asset_center.x + length * @cos(new_angle); - point.y = asset_center.y + length * @sin(new_angle); + for (&un_rotated_points) |*p| { + const new_point = new_matrix.get(p); + p.x = new_point.x; + p.y = new_point.y; } }, else => unreachable, @@ -142,22 +142,21 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra un_rotated_points[3].y = un_rotated_points[0].y + 1.0; un_rotated_points[2].y = un_rotated_points[1].y + 1.0; } - - // rotate bounds back to correct position - const p0 = t_matrix.get(un_rotated_points[0]); - const p1 = t_matrix.get(un_rotated_points[1]); - const p2 = t_matrix.get(un_rotated_points[2]); - const p3 = t_matrix.get(un_rotated_points[3]); - - points[0].x = p0.x; - points[0].y = p0.y; - points[1].x = p1.x; - points[1].y = p1.y; - points[2].x = p2.x; - points[2].y = p2.y; - points[3].x = p3.x; - points[3].y = p3.y; } + // rotate bounds back to correct position + const p0 = t_matrix.get(un_rotated_points[0]); + const p1 = t_matrix.get(un_rotated_points[1]); + const p2 = t_matrix.get(un_rotated_points[2]); + const p3 = t_matrix.get(un_rotated_points[3]); + + points[0].x = p0.x; + points[0].y = p0.y; + points[1].x = p1.x; + points[1].y = p1.y; + points[2].x = p2.x; + points[2].y = p2.y; + points[3].x = p3.x; + points[3].y = p3.y; } fn getPointsOfLine(points: [4]PointUV, t_line: TransformLine) struct { Point, Point } { From 46c9764deabfd7524f5851508981f9002de378c2 Mon Sep 17 00:00:00 2001 From: mateuszJS Date: Sun, 24 Aug 2025 22:56:54 +0200 Subject: [PATCH 2/5] simplify transformation further --- src/logic/transform_ui.zig | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/logic/transform_ui.zig b/src/logic/transform_ui.zig index 60a0aad..8a67b37 100644 --- a/src/logic/transform_ui.zig +++ b/src/logic/transform_ui.zig @@ -45,18 +45,20 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra const asset_angle_y = points[0].angleTo(points[3]) + std.math.pi / 2.0; // it's important we dont meausre horizontal one, because reflecting by X axis makes no change in horizontal angle // but should be 180 degree opposite - const t_matrix = Matrix3x3.rotation(asset_angle_y); // transfor matrix - const invert_t_matrix = t_matrix.inverse(); - const pointer = invert_t_matrix.get(Point{ + const asset_center = points[0].mid(points[2]); + var matrix = Matrix3x3.rotation(-asset_angle_y); // transfor matrix + matrix.translate(-asset_center.x, -asset_center.y); + + const pointer = matrix.get(Point{ .x = raw_x, .y = raw_y, }); var un_rotated_points = [4]Point{ - invert_t_matrix.get(points[0]), - invert_t_matrix.get(points[1]), - invert_t_matrix.get(points[2]), - invert_t_matrix.get(points[3]), + matrix.get(points[0]), + matrix.get(points[1]), + matrix.get(points[2]), + matrix.get(points[3]), }; switch (ui_component_id) { @@ -113,18 +115,13 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra }, 9 => { // rotation - const asset_center = un_rotated_points[0].mid(un_rotated_points[2]); const asset_new_angle = std.math.atan2( - asset_center.y - pointer.y, - asset_center.x - pointer.x, + -pointer.y, + -pointer.x, ) - std.math.pi / 2.0; - - var new_matrix = Matrix3x3.translation(asset_center.x, asset_center.y); - new_matrix.rotate(asset_new_angle); - new_matrix.translate(-asset_center.x, -asset_center.y); - + const new_rotation = Matrix3x3.rotation(asset_new_angle); for (&un_rotated_points) |*p| { - const new_point = new_matrix.get(p); + const new_point = new_rotation.get(p); p.x = new_point.x; p.y = new_point.y; } @@ -144,10 +141,11 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra } } // rotate bounds back to correct position - const p0 = t_matrix.get(un_rotated_points[0]); - const p1 = t_matrix.get(un_rotated_points[1]); - const p2 = t_matrix.get(un_rotated_points[2]); - const p3 = t_matrix.get(un_rotated_points[3]); + const i_matrix = matrix.inverse(); + const p0 = i_matrix.get(un_rotated_points[0]); + const p1 = i_matrix.get(un_rotated_points[1]); + const p2 = i_matrix.get(un_rotated_points[2]); + const p3 = i_matrix.get(un_rotated_points[3]); points[0].x = p0.x; points[0].y = p0.y; From 2b2b137a1e87c531186d63d394693a15a4f90e67 Mon Sep 17 00:00:00 2001 From: mateuszJS Date: Sun, 24 Aug 2025 23:24:57 +0200 Subject: [PATCH 3/5] simplify transforms --- src/logic/transform_ui.zig | 118 ++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 62 deletions(-) diff --git a/src/logic/transform_ui.zig b/src/logic/transform_ui.zig index 8a67b37..fb778b0 100644 --- a/src/logic/transform_ui.zig +++ b/src/logic/transform_ui.zig @@ -41,86 +41,89 @@ pub fn isTransformUi(id: u32) bool { return id >= 1 and id <= 9; } -pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, raw_y: f32) void { - const asset_angle_y = points[0].angleTo(points[3]) + std.math.pi / 2.0; - // it's important we dont meausre horizontal one, because reflecting by X axis makes no change in horizontal angle +pub fn transformPoints(ui_component_id: u32, bounds: *[4]PointUV, raw_x: f32, raw_y: f32) void { + const asset_angle_y = bounds[0].angleTo(bounds[3]) + std.math.pi / 2.0; + // it's important we don't measure horizontal one, because reflecting by X axis makes no change in horizontal angle // but should be 180 degree opposite - const asset_center = points[0].mid(points[2]); + const asset_center = bounds[0].mid(bounds[2]); var matrix = Matrix3x3.rotation(-asset_angle_y); // transfor matrix - matrix.translate(-asset_center.x, -asset_center.y); + matrix.translate(-asset_center.x, -asset_center.y); // useufl for angle and mirrored scaling(with shift/alt) const pointer = matrix.get(Point{ .x = raw_x, .y = raw_y, }); - var un_rotated_points = [4]Point{ - matrix.get(points[0]), - matrix.get(points[1]), - matrix.get(points[2]), - matrix.get(points[3]), + var points = [4]Point{ + matrix.get(bounds[0]), + matrix.get(bounds[1]), + matrix.get(bounds[2]), + matrix.get(bounds[3]), }; switch (ui_component_id) { 1 => { // Top left corner - un_rotated_points[0].x = pointer.x; - un_rotated_points[0].y = pointer.y; - un_rotated_points[1].y = pointer.y; - un_rotated_points[3].x = pointer.x; + points[0].x = pointer.x; + points[0].y = pointer.y; + points[1].y = pointer.y; + points[3].x = pointer.x; }, 2 => { // Top right corner - un_rotated_points[1].x = pointer.x; - un_rotated_points[1].y = pointer.y; - un_rotated_points[0].y = pointer.y; - un_rotated_points[2].x = pointer.x; + points[1].x = pointer.x; + points[1].y = pointer.y; + points[0].y = pointer.y; + points[2].x = pointer.x; }, 3 => { // bottom right corner - un_rotated_points[2].x = pointer.x; - un_rotated_points[2].y = pointer.y; - un_rotated_points[3].y = pointer.y; - un_rotated_points[1].x = pointer.x; + points[2].x = pointer.x; + points[2].y = pointer.y; + points[3].y = pointer.y; + points[1].x = pointer.x; }, 4 => { // bottom left corner - un_rotated_points[3].x = pointer.x; - un_rotated_points[3].y = pointer.y; - un_rotated_points[2].y = pointer.y; - un_rotated_points[0].x = pointer.x; + points[3].x = pointer.x; + points[3].y = pointer.y; + points[2].y = pointer.y; + points[0].x = pointer.x; }, 5 => { // top - un_rotated_points[0].y = pointer.y; - un_rotated_points[1].y = pointer.y; + points[0].y = pointer.y; + points[1].y = pointer.y; }, 6 => { // right - un_rotated_points[1].x = pointer.x; - un_rotated_points[2].x = pointer.x; + points[1].x = pointer.x; + points[2].x = pointer.x; }, 7 => { // bottom - un_rotated_points[2].y = pointer.y; - un_rotated_points[3].y = pointer.y; + points[2].y = pointer.y; + points[3].y = pointer.y; }, 8 => { // left - un_rotated_points[0].x = pointer.x; - un_rotated_points[3].x = pointer.x; + points[0].x = pointer.x; + points[3].x = pointer.x; }, 9 => { // rotation const asset_new_angle = std.math.atan2( - -pointer.y, - -pointer.x, - ) - std.math.pi / 2.0; + pointer.y, + pointer.x, + ) + std.math.pi / 2.0; const new_rotation = Matrix3x3.rotation(asset_new_angle); - for (&un_rotated_points) |*p| { + + // Would be nice if all transformation work this way or preparing matrix + // and just apply matrix to all points + for (&points) |*p| { const new_point = new_rotation.get(p); p.x = new_point.x; p.y = new_point.y; @@ -129,32 +132,23 @@ pub fn transformPoints(ui_component_id: u32, points: *[4]PointUV, raw_x: f32, ra else => unreachable, } - if (ui_component_id != 9) { - // make sure bounds is not smaller tan 1x1(it removed tons of edge cases) - if (@abs(un_rotated_points[0].x - un_rotated_points[1].x) < 1.0) { - un_rotated_points[1].x = un_rotated_points[0].x + 1.0; - un_rotated_points[2].x = un_rotated_points[3].x + 1.0; - } - if (@abs(un_rotated_points[0].y - un_rotated_points[3].y) < 1.0) { - un_rotated_points[3].y = un_rotated_points[0].y + 1.0; - un_rotated_points[2].y = un_rotated_points[1].y + 1.0; - } + // make sure bounds is not smaller tan 1x1(it removed tons of edge cases) + if (points[0].distance(points[1]) < 1.0) { + points[1].x = points[0].x + 1.0; + points[2].x = points[3].x + 1.0; + } + if (points[0].distance(points[3]) < 1.0) { + points[3].y = points[0].y + 1.0; + points[2].y = points[1].y + 1.0; } - // rotate bounds back to correct position - const i_matrix = matrix.inverse(); - const p0 = i_matrix.get(un_rotated_points[0]); - const p1 = i_matrix.get(un_rotated_points[1]); - const p2 = i_matrix.get(un_rotated_points[2]); - const p3 = i_matrix.get(un_rotated_points[3]); - points[0].x = p0.x; - points[0].y = p0.y; - points[1].x = p1.x; - points[1].y = p1.y; - points[2].x = p2.x; - points[2].y = p2.y; - points[3].x = p3.x; - points[3].y = p3.y; + // transform bounds back to correct position + const i_matrix = matrix.inverse(); + for (bounds, points) |*b, p| { + const t_p = i_matrix.get(p); + b.x = t_p.x; + b.y = t_p.y; + } } fn getPointsOfLine(points: [4]PointUV, t_line: TransformLine) struct { Point, Point } { From 37c21d3d0aa07a4a4240093c11ce91be3479b586 Mon Sep 17 00:00:00 2001 From: mateuszJS Date: Mon, 25 Aug 2025 14:36:35 +0200 Subject: [PATCH 4/5] simplify transformations --- src/logic/index.zig | 6 +- src/logic/matrix.zig | 27 +++++++ src/logic/transform_ui.zig | 141 +++++++++++++------------------------ 3 files changed, 80 insertions(+), 94 deletions(-) diff --git a/src/logic/index.zig b/src/logic/index.zig index 12bcbe7..dbde6cf 100644 --- a/src/logic/index.zig +++ b/src/logic/index.zig @@ -362,7 +362,11 @@ pub fn onPointerMove(x: f32, y: f32) !void { } }, .Transform => { - TransformUI.transformPoints(state.hovered_asset_id, bounds, x, y); + TransformUI.transformPoints( + state.hovered_asset_id, + bounds, + types.Point{ .x = x, .y = y }, + ); }, .None => {}, } diff --git a/src/logic/matrix.zig b/src/logic/matrix.zig index 75de9f9..de08d43 100644 --- a/src/logic/matrix.zig +++ b/src/logic/matrix.zig @@ -208,6 +208,33 @@ pub const Matrix3x3 = struct { 0.0, 0.0, 1.0, }); } + + // scales the matrix around a pivot point (px, py + pub fn pivotScale(self: *Matrix3x3, sx: f32, sy: f32, px: f32, py: f32) void { + self.* = Matrix3x3.multiply(self.*, Matrix3x3.from([_]f32{ + sx, 0, px * (1 - sx), + 0, sy, py * (1 - sy), + 0, 0, 1, + })); + } + + // this function rotated by the angle which is not uniform in x and y axis + // so for example x or y is scaled, so angle should be also adjusted + pub fn rotateScaled(self: *Matrix3x3, angle_rad: f32, aspect: f32) void { + const c = std.math.cos(angle_rad); + const s = std.math.sin(angle_rad); + self.* = Matrix3x3.multiply(self.*, Matrix3x3.from([_]f32{ + c, -s / aspect, 0.0, + s * aspect, c, 0.0, + 0.0, 0.0, 1.0, + })); + } + + // Returns true if the transformation causes a reflection (i.e., the coordinate system is flipped). + pub fn isMirrored(self: Matrix3x3) bool { + const det = self.values[0] * self.values[4] - self.values[1] * self.values[3]; + return det < 0; + } }; // --- Tests --- diff --git a/src/logic/transform_ui.zig b/src/logic/transform_ui.zig index fb778b0..bce6d08 100644 --- a/src/logic/transform_ui.zig +++ b/src/logic/transform_ui.zig @@ -41,114 +41,69 @@ pub fn isTransformUi(id: u32) bool { return id >= 1 and id <= 9; } -pub fn transformPoints(ui_component_id: u32, bounds: *[4]PointUV, raw_x: f32, raw_y: f32) void { - const asset_angle_y = bounds[0].angleTo(bounds[3]) + std.math.pi / 2.0; - // it's important we don't measure horizontal one, because reflecting by X axis makes no change in horizontal angle - // but should be 180 degree opposite - const asset_center = bounds[0].mid(bounds[2]); - var matrix = Matrix3x3.rotation(-asset_angle_y); // transfor matrix - matrix.translate(-asset_center.x, -asset_center.y); // useufl for angle and mirrored scaling(with shift/alt) - - const pointer = matrix.get(Point{ - .x = raw_x, - .y = raw_y, - }); - - var points = [4]Point{ - matrix.get(bounds[0]), - matrix.get(bounds[1]), - matrix.get(bounds[2]), - matrix.get(bounds[3]), +pub fn transformPoints(ui_component_id: u32, bounds: *[4]PointUV, raw_pointer: Point) void { + var matrix = Matrix3x3.getMatrixFromRectangle(bounds.*); + const pointer = matrix.inverse().get(raw_pointer); + + const DEFAULT_RECT: [4]PointUV = [_]PointUV{ + .{ .x = 0.0, .y = 1.0, .u = 0.0, .v = 1.0 }, + .{ .x = 1.0, .y = 1.0, .u = 1.0, .v = 1.0 }, + .{ .x = 1.0, .y = 0.0, .u = 1.0, .v = 0.0 }, + .{ .x = 0.0, .y = 0.0, .u = 0.0, .v = 0.0 }, }; switch (ui_component_id) { - 1 => { - // Top left corner - points[0].x = pointer.x; - points[0].y = pointer.y; - points[1].y = pointer.y; - points[3].x = pointer.x; - }, - 2 => { - // Top right corner - points[1].x = pointer.x; - points[1].y = pointer.y; - points[0].y = pointer.y; - points[2].x = pointer.x; - }, - 3 => { - // bottom right corner - points[2].x = pointer.x; - points[2].y = pointer.y; - points[3].y = pointer.y; - points[1].x = pointer.x; - }, - 4 => { - // bottom left corner - points[3].x = pointer.x; - points[3].y = pointer.y; - points[2].y = pointer.y; - points[0].x = pointer.x; - }, - 5 => { - // top - points[0].y = pointer.y; - points[1].y = pointer.y; - }, - - 6 => { - // right - points[1].x = pointer.x; - points[2].x = pointer.x; - }, - - 7 => { - // bottom - points[2].y = pointer.y; - points[3].y = pointer.y; - }, - - 8 => { - // left - points[0].x = pointer.x; - points[3].x = pointer.x; - }, + 1 => matrix.pivotScale(1 - pointer.x, pointer.y, 1, 0), // Top left corner + 2 => matrix.pivotScale(pointer.x, pointer.y, 0, 0), // Top right corner + 3 => matrix.pivotScale(pointer.x, 1 - pointer.y, 0, 1), // bottom right corner + 4 => matrix.pivotScale(1 - pointer.x, 1 - pointer.y, 1, 1), // bottom left corner + 5 => matrix.pivotScale(1, pointer.y, 0, 0), // top + 6 => matrix.pivotScale(pointer.x, 1, 0, 0), // right + 7 => matrix.pivotScale(1, 1 - pointer.y, 0, 1), // bottom + 8 => matrix.pivotScale(1 - pointer.x, 1, 1, 0), // left 9 => { // rotation - const asset_new_angle = std.math.atan2( - pointer.y, - pointer.x, - ) + std.math.pi / 2.0; - const new_rotation = Matrix3x3.rotation(asset_new_angle); + const center = bounds[0].mid(bounds[2]); + const asset_angle_y = bounds[0].angleTo(bounds[3]); + var asset_new_angle = center.angleTo(raw_pointer) - asset_angle_y; - // Would be nice if all transformation work this way or preparing matrix - // and just apply matrix to all points - for (&points) |*p| { - const new_point = new_rotation.get(p); - p.x = new_point.x; - p.y = new_point.y; + if (matrix.isMirrored()) { + asset_new_angle *= -1; } + + matrix.translate(0.5, 0.5); + const aspect = bounds[0].distance(bounds[1]) / bounds[0].distance(bounds[3]); + matrix.rotateScaled(asset_new_angle, aspect); + matrix.translate(-0.5, -0.5); }, else => unreachable, } - // make sure bounds is not smaller tan 1x1(it removed tons of edge cases) - if (points[0].distance(points[1]) < 1.0) { - points[1].x = points[0].x + 1.0; - points[2].x = points[3].x + 1.0; - } - if (points[0].distance(points[3]) < 1.0) { - points[3].y = points[0].y + 1.0; - points[2].y = points[1].y + 1.0; - } + // angles has to be captured before transformation + // just in case we will flatten one of the dimensions, then all the angles will point in one of two directions + // and will NOT produce 1x1 bounds, but more like 1x0 or 0x1 + const angle_x = bounds[0].angleTo(bounds[1]); + const angle_y = bounds[0].angleTo(bounds[3]); - // transform bounds back to correct position - const i_matrix = matrix.inverse(); - for (bounds, points) |*b, p| { - const t_p = i_matrix.get(p); + for (bounds, DEFAULT_RECT) |*b, p| { + const t_p = matrix.get(p); b.x = t_p.x; b.y = t_p.y; } + + if (bounds[0].distance(bounds[1]) < 1.0) { + bounds[1].x = bounds[0].x + @cos(angle_x); + bounds[1].y = bounds[0].y + @sin(angle_x); + bounds[2].x = bounds[3].x + @cos(angle_x); + bounds[2].y = bounds[3].y + @sin(angle_x); + } + + if (bounds[0].distance(bounds[3]) < 1.0) { + bounds[3].x = bounds[0].x + @cos(angle_y); + bounds[3].y = bounds[0].y + @sin(angle_y); + bounds[2].x = bounds[1].x + @cos(angle_y); + bounds[2].y = bounds[1].y + @sin(angle_y); + } } fn getPointsOfLine(points: [4]PointUV, t_line: TransformLine) struct { Point, Point } { From 5e037f2514b4ebcc4b72c37c075612c5093de89c Mon Sep 17 00:00:00 2001 From: mateuszJS Date: Mon, 25 Aug 2025 14:39:57 +0200 Subject: [PATCH 5/5] extract default bounds --- src/logic/consts.zig | 8 ++++++++ src/logic/shapes/shapes.zig | 8 +------- src/logic/transform_ui.zig | 10 ++-------- 3 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 src/logic/consts.zig diff --git a/src/logic/consts.zig b/src/logic/consts.zig new file mode 100644 index 0000000..e3156fe --- /dev/null +++ b/src/logic/consts.zig @@ -0,0 +1,8 @@ +const PointUV = @import("types.zig").PointUV; + +pub const DEFAULT_BOUNDS = [4]PointUV{ + .{ .x = 0.0, .y = 1.0, .u = 0.0, .v = 1.0 }, + .{ .x = 1.0, .y = 1.0, .u = 1.0, .v = 1.0 }, + .{ .x = 1.0, .y = 0.0, .u = 1.0, .v = 0.0 }, + .{ .x = 0.0, .y = 0.0, .u = 0.0, .v = 0.0 }, +}; diff --git a/src/logic/shapes/shapes.zig b/src/logic/shapes/shapes.zig index b3b1fc2..d38297f 100644 --- a/src/logic/shapes/shapes.zig +++ b/src/logic/shapes/shapes.zig @@ -10,6 +10,7 @@ const Path = @import("paths.zig").Path; const shared = @import("../shared.zig"); const images = @import("../images.zig"); const Matrix3x3 = @import("../matrix.zig").Matrix3x3; +const DEFAULT_BOUNDS = @import("../consts.zig").DEFAULT_BOUNDS; const EPSILON = std.math.floatEps(f32); @@ -39,13 +40,6 @@ pub const Preview = struct { point: Point, }; -const DEFAULT_BOUNDS = [4]PointUV{ - .{ .x = 0.0, .y = 1.0, .u = 0.0, .v = 1.0 }, - .{ .x = 1.0, .y = 1.0, .u = 1.0, .v = 1.0 }, - .{ .x = 1.0, .y = 0.0, .u = 1.0, .v = 0.0 }, - .{ .x = 0.0, .y = 0.0, .u = 0.0, .v = 0.0 }, -}; - pub fn getSkeletonUniform() Uniform { return Uniform{ .stroke_width = 2.0 * shared.render_scale, diff --git a/src/logic/transform_ui.zig b/src/logic/transform_ui.zig index bce6d08..deece52 100644 --- a/src/logic/transform_ui.zig +++ b/src/logic/transform_ui.zig @@ -7,6 +7,7 @@ const Matrix3x3 = @import("matrix.zig").Matrix3x3; const Msdf = @import("msdf.zig"); const Triangle = @import("triangle.zig"); const shared = @import("shared.zig"); +const DEFAULT_BOUNDS = @import("consts.zig").DEFAULT_BOUNDS; const white = [4]u8{ 255, 255, 255, 255 }; const black = [4]u8{ 0, 0, 0, 255 }; @@ -45,13 +46,6 @@ pub fn transformPoints(ui_component_id: u32, bounds: *[4]PointUV, raw_pointer: P var matrix = Matrix3x3.getMatrixFromRectangle(bounds.*); const pointer = matrix.inverse().get(raw_pointer); - const DEFAULT_RECT: [4]PointUV = [_]PointUV{ - .{ .x = 0.0, .y = 1.0, .u = 0.0, .v = 1.0 }, - .{ .x = 1.0, .y = 1.0, .u = 1.0, .v = 1.0 }, - .{ .x = 1.0, .y = 0.0, .u = 1.0, .v = 0.0 }, - .{ .x = 0.0, .y = 0.0, .u = 0.0, .v = 0.0 }, - }; - switch (ui_component_id) { 1 => matrix.pivotScale(1 - pointer.x, pointer.y, 1, 0), // Top left corner 2 => matrix.pivotScale(pointer.x, pointer.y, 0, 0), // Top right corner @@ -85,7 +79,7 @@ pub fn transformPoints(ui_component_id: u32, bounds: *[4]PointUV, raw_pointer: P const angle_x = bounds[0].angleTo(bounds[1]); const angle_y = bounds[0].angleTo(bounds[3]); - for (bounds, DEFAULT_RECT) |*b, p| { + for (bounds, DEFAULT_BOUNDS) |*b, p| { const t_p = matrix.get(p); b.x = t_p.x; b.y = t_p.y;