From 60b69a32d0bff5700bff83884d1fc8561e541d17 Mon Sep 17 00:00:00 2001 From: Matthew Winter <33818+wintermi@users.noreply.github.com> Date: Tue, 31 Oct 2023 21:23:53 +1100 Subject: [PATCH 1/4] feat: update undercurl thickness and wave height --- src/font/sprite/underline.zig | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index d28b9d677..ed08896c6 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -175,10 +175,8 @@ const Draw = struct { // cell height and this doesn't allow us to make a high enough // wave. This constant is arbitrary, change it for aesthetics. const pos: u32 = pos: { - const MIN_HEIGHT = 5; - const clamped_pos = @min(y_max, self.pos); - const height = y_max - clamped_pos; - break :pos if (height < MIN_HEIGHT) clamped_pos -| MIN_HEIGHT else clamped_pos; + const MIN_HEIGHT: u32 = @max(self.height / 10, 3); + break :pos y_max - (MIN_HEIGHT * 2); }; // The full height of the wave can be from the bottom to the @@ -192,7 +190,7 @@ const Draw = struct { while (x < self.width) : (x += 1) { const y: f64 = @as(f64, @floatFromInt(y_mid)) + (half_height * @cos(@as(f64, @floatFromInt(x)) * x_factor)); const y_upper: u32 = @intFromFloat(@floor(y)); - const y_lower: u32 = y_upper - 1 + self.thickness; + const y_lower: u32 = y_upper + self.thickness; const alpha: u8 = @intFromFloat(255 * @abs(y - @floor(y))); // upper and lower bounds From d7a16e024564248cd1211170f8722cfd9b93e101 Mon Sep 17 00:00:00 2001 From: Matthew Winter <33818+wintermi@users.noreply.github.com> Date: Tue, 31 Oct 2023 21:53:04 +1100 Subject: [PATCH 2/4] feat: update undercurl thickness and wave height --- src/font/sprite/underline.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index ed08896c6..2e3a70958 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -175,7 +175,7 @@ const Draw = struct { // cell height and this doesn't allow us to make a high enough // wave. This constant is arbitrary, change it for aesthetics. const pos: u32 = pos: { - const MIN_HEIGHT: u32 = @max(self.height / 10, 3); + const MIN_HEIGHT: u32 = @max(self.height / 9, 3); break :pos y_max - (MIN_HEIGHT * 2); }; From 212b30a163d425632a9496f500db6e6e64a7978e Mon Sep 17 00:00:00 2001 From: Matthew Winter <33818+wintermi@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:51:32 +1100 Subject: [PATCH 3/4] feat: change minimum height to 2 --- src/font/sprite/underline.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 2e3a70958..6f9ab1493 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -175,7 +175,7 @@ const Draw = struct { // cell height and this doesn't allow us to make a high enough // wave. This constant is arbitrary, change it for aesthetics. const pos: u32 = pos: { - const MIN_HEIGHT: u32 = @max(self.height / 9, 3); + const MIN_HEIGHT: u32 = @max(self.height / 9, 2); break :pos y_max - (MIN_HEIGHT * 2); }; From a81c7b7bb2fcfd3361c2fd6d680bd9164bc9228e Mon Sep 17 00:00:00 2001 From: Matthew Winter <33818+wintermi@users.noreply.github.com> Date: Wed, 1 Nov 2023 19:04:20 +1100 Subject: [PATCH 4/4] feat: improve variable naming --- src/font/sprite/underline.zig | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/font/sprite/underline.zig b/src/font/sprite/underline.zig index 6f9ab1493..55a29d80c 100644 --- a/src/font/sprite/underline.zig +++ b/src/font/sprite/underline.zig @@ -166,29 +166,29 @@ const Draw = struct { // This is the lowest that the curl can go. const y_max = self.height - 1; - // Determines the density of the waves. + // Calculate the wave period for a single character // `2 * pi...` = 1 peak per character // `4 * pi...` = 2 peaks per character - const x_factor = 2 * std.math.pi / @as(f64, @floatFromInt(self.width - 1)); + const wave_period = 2 * std.math.pi / @as(f64, @floatFromInt(self.width - 1)); // Some fonts put the underline too close to the bottom of the // cell height and this doesn't allow us to make a high enough // wave. This constant is arbitrary, change it for aesthetics. const pos: u32 = pos: { - const MIN_HEIGHT: u32 = @max(self.height / 9, 2); - break :pos y_max - (MIN_HEIGHT * 2); + const MIN_AMPLITUDE: u32 = @max(self.height / 9, 2); + break :pos y_max - (MIN_AMPLITUDE * 2); }; - // The full height of the wave can be from the bottom to the + // The full aplitude of the wave can be from the bottom to the // underline position. We also calculate our mid y point of the wave - const wave_height: f64 = @floatFromInt(y_max - pos); - const half_height: f64 = @max(1, wave_height / 4); - const y_mid: u32 = pos + @as(u32, @intFromFloat(2 * half_height)); + const double_amplitude: f64 = @floatFromInt(y_max - pos); + const half_amplitude: f64 = @max(1, double_amplitude / 4); + const y_mid: u32 = pos + @as(u32, @intFromFloat(2 * half_amplitude)); // follow Xiaolin Wu's antialias algorithm to draw the curve var x: u32 = 0; while (x < self.width) : (x += 1) { - const y: f64 = @as(f64, @floatFromInt(y_mid)) + (half_height * @cos(@as(f64, @floatFromInt(x)) * x_factor)); + const y: f64 = @as(f64, @floatFromInt(y_mid)) + (half_amplitude * @cos(@as(f64, @floatFromInt(x)) * wave_period)); const y_upper: u32 = @intFromFloat(@floor(y)); const y_lower: u32 = y_upper + self.thickness; const alpha: u8 = @intFromFloat(255 * @abs(y - @floor(y)));