Presenter: a view a rounding error past the frame keeps its detail texture (#2127)

The page rect of the view, converted back from the screen, can stand a hair outside the frame. The cached detail is always inside the frame, so it never covered that view, and a still view rendered a new detail every frame. detail_texture now clips the view to the frame first. Test: present::tests::a_view_a_rounding_error_past_the_frame_keeps_its_detail (failed before: a new texture on the second call).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 drove and wrote
This commit is contained in:
Trevor BrownandClaude Opus 5.5 committed 2026-11-12 21:15:22 -05:00
1 parent 0859f94c7d
commit 6d4df2b909
2 files changed
+20

No files matched your search

+4
View File
@@ -281,6 +281,10 @@ impl Presenter {
moving: bool, moving: bool,
now: f64, now: f64,
) -> Option<FrameTex> { ) -> Option<FrameTex> {
// Converted back from the screen, the view can stand a rounding error outside the frame,
// which a detail (always inside the frame) never covers: a still view would then render a
// new detail every frame.
let visible = visible.intersect(whole);
let (t, clock) = self.frame_clock(ctx, doc, id, now); let (t, clock) = self.frame_clock(ctx, doc, id, now);
let key = (self.rev, px.to_bits(), clock.map_or(0, |c| c.0)); let key = (self.rev, px.to_bits(), clock.map_or(0, |c| c.0));
let covers = |b: &figcraft_geom::Rect| b.x0 <= visible.x0 && b.y0 <= visible.y0 && b.x1 >= visible.x1 && b.y1 >= visible.y1; let covers = |b: &figcraft_geom::Rect| b.x0 <= visible.x0 && b.y0 <= visible.y0 && b.x1 >= visible.x1 && b.y1 >= visible.y1;
+16
View File
@@ -511,6 +511,22 @@ fn the_detail_is_kept_while_nothing_changes_and_made_again_when_the_frame_does()
assert_ne!(tex_id(&ui), Some(first), "an edit renders the detail again"); assert_ne!(tex_id(&ui), Some(first), "an edit renders the detail again");
} }
#[test]
fn a_view_a_rounding_error_past_the_frame_keeps_its_detail() {
let mut ui = tall_hidpi(16_384);
let ctx = ui.ctx.clone();
let doc = ui.app.session.doc().unwrap().clone();
let now = ui.time;
let p = ui.app.ui.present.as_mut().unwrap();
let id = p.current;
let whole = figcraft_geom::Rect::new(0.0, 0.0, 1440.0, 9701.0);
// The screen-to-page round trip can put the view a hair outside the frame.
let view = figcraft_geom::Rect::new(-1e-9, 0.0, 1440.0 + 1e-9, 860.0);
let first = p.detail_texture(&ctx, &doc, id, 2.0, whole, view, false, now).expect("a detail").tex.id();
let again = p.detail_texture(&ctx, &doc, id, 2.0, whole, view, false, now).expect("a detail").tex.id();
assert_eq!(again, first, "the same view reuses its detail instead of rendering a new one");
}
#[test] #[test]
fn detail_plan_edge_cases() { fn detail_plan_edge_cases() {
use figcraft_geom::Rect as R; use figcraft_geom::Rect as R;