diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:28:24 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:20:23 -0300 |
| commit | 034ac8e5128e3dc917b3a98bead6db71a5249739 (patch) | |
| tree | dacb14c512f6c9b98bdcce2b16dac3db9bb616b8 | |
| parent | 3ac1a89c2587fd97e58900f1162fad21048b0577 (diff) | |
| download | pardes-034ac8e5128e3dc917b3a98bead6db71a5249739.tar.gz pardes-034ac8e5128e3dc917b3a98bead6db71a5249739.zip | |
Presentation: a cell is in a box by one test, animation.Box.contains, now the centre test its comment always said (its one other caller passes whole-cell pane boxes, where centre and corner agree), so boxContainsCell goes; the aliases used once are spelled where they are used
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/Presentation.zig | 41 | ||||
| -rw-r--r-- | src/animation.zig | 7 |
2 files changed, 19 insertions, 29 deletions
diff --git a/src/Presentation.zig b/src/Presentation.zig index 3fc9be44..fc6de5b6 100644 --- a/src/Presentation.zig +++ b/src/Presentation.zig @@ -12,13 +12,8 @@ const Box = animation.Box; const Track = animation.Track; const Phase = animation.Phase; const Transition = animation.Transition; -const CellArea = animation.CellArea; -const CharSource = animation.CharSource; -const charSource = animation.charSource; -const dissolveRevealed = animation.dissolveRevealed; const openingBox = animation.openingBox; const closingBox = animation.closingBox; -const paintOrder = animation.paintOrder; const panelBox = layout.panelBox; const Presentation = @This(); @@ -452,8 +447,8 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u closing -= 1; const track = self.shown_closing[closing]; if (!track.active()) continue; - if (boxContainsCell(track.contentBox(), col, row) and - boxContainsCell(track.presented(), col, row)) return null; + if (track.contentBox().contains(col, row) and + track.presented().contains(col, row)) return null; } const phases = [_]Phase{ .opening, .moving }; for (phases) |phase| { @@ -468,8 +463,8 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u .slide, .zoom => { const shown = track.presented(); // Past its mark, the neighbour's cells stay the neighbour's. - if (pastMark(track) and !boxContainsCell(track.to, col, row)) continue; - if (shown.w <= 0 or shown.h <= 0 or !boxContainsCell(shown, col, row)) continue; + if (pastMark(track) and !track.to.contains(col, row)) continue; + if (shown.w <= 0 or shown.h <= 0 or !shown.contains(col, row)) continue; const x = @as(f32, @floatFromInt(col)) + 0.5; const y = @as(f32, @floatFromInt(row)) + 0.5; const u = std.math.clamp((x - shown.x) / shown.w, 0, 0.999_999); @@ -483,9 +478,9 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u }, .vertical => { const clip = track.contentBox(); - if (!boxContainsCell(clip, col, row)) continue; + if (!clip.contains(col, row)) continue; const shown = track.presented(); - if (shown.w <= 0 or shown.h <= 0 or !boxContainsCell(shown, col, row)) + if (shown.w <= 0 or shown.h <= 0 or !shown.contains(col, row)) return null; const x = @as(f32, @floatFromInt(col)) + 0.5; const y = @as(f32, @floatFromInt(row)) + 0.5; @@ -497,7 +492,7 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u }; }, .dissolve, .ascii => { - if (!boxContainsCell(track.to, col, row)) continue; + if (!track.to.contains(col, row)) continue; const cell_diff = self.cellDiff(cols, rows, col, row); if (!cell_diff.changed()) return .{ .col = col, .row = row }; @@ -508,7 +503,7 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u @as(f32, @floatFromInt(row)) + 0.5 - track.to.y, )); const visible = switch (track.effect) { - .dissolve => dissolveRevealed( + .dissolve => animation.dissolveRevealed( track.serial, relative_col, relative_row, @@ -523,16 +518,16 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u return if (visible) .{ .col = col, .row = row } else null; }, .edges, .fall, .wave, .curtain, .scramble, .typewriter => { - if (!boxContainsCell(track.to, col, row)) continue; - const area = CellArea.of(track.to); + if (!track.to.contains(col, row)) continue; + const area = animation.CellArea.of(track.to); const settled = std.meta.eql( - charSource( + animation.charSource( track, col -| area.x0, row -| area.y0, area, ), - CharSource.settled, + animation.CharSource.settled, ); return if (settled) .{ .col = col, .row = row } else null; }, @@ -544,17 +539,11 @@ pub fn pointer(self: *const Presentation, cols: u16, rows: u16, col: u16, row: u const track = maybe orelse continue; if (!track.active() or (track.effect != .slide and track.effect != .zoom and track.effect != .vertical)) continue; - if (boxContainsCell(track.to, col, row)) return null; + if (track.to.contains(col, row)) return null; } return .{ .col = col, .row = row }; } -fn boxContainsCell(box: Box, col: u16, row: u16) bool { - const x = @as(f32, @floatFromInt(col)) + 0.5; - const y = @as(f32, @floatFromInt(row)) + 0.5; - return x >= box.x and x < box.x + box.w and y >= box.y and y < box.y + box.h; -} - pub fn cancel(self: *Presentation) void { self.tracks = @splat(null); self.closing_len = 0; @@ -585,7 +574,7 @@ fn prepareDiff(self: *Presentation, gpa: std.mem.Allocator, surface: *const pard while (row < surface.rows) : (row += 1) { var col: u16 = 0; while (col < surface.cols) : (col += 1) { - if (!boxContainsCell(track.to, col, row)) continue; + if (!track.to.contains(col, row)) continue; const index = @as(usize, row) * surface.cols + col; switch (self.diffs[index]) { .ascii => |diff| longest = @max(longest, diff.frameCount()), @@ -624,7 +613,7 @@ pub fn submit(self: *Presentation, p: *Pardes, s: *pardes.Surface) !void { s.previous_regions = self.previous_regions[0..self.previous_nregions]; s.cell_diffs = self.diffs; } - s.npanel_tracks = paintOrder( + s.npanel_tracks = animation.paintOrder( &self.tracks, self.closing[0..self.closing_len], &s.panel_tracks, diff --git a/src/animation.zig b/src/animation.zig index ae116e27..51164495 100644 --- a/src/animation.zig +++ b/src/animation.zig @@ -96,10 +96,11 @@ pub const Box = extern struct { return a.x == b.x and a.y == b.y and a.w == b.w and a.h == b.h; } - // A cell belongs to a fractional box when its center lies inside. + /// A cell belongs to a fractional box when its centre lies inside: + /// drawing and hit testing both ask this. pub fn contains(box: Box, col: u16, row: u16) bool { - const x: f32 = @floatFromInt(col); - const y: f32 = @floatFromInt(row); + const x = @as(f32, @floatFromInt(col)) + 0.5; + const y = @as(f32, @floatFromInt(row)) + 0.5; return x >= box.x and x < box.x + box.w and y >= box.y and y < box.y + box.h; } }; |
