From 6d4df2b9099f97c1eef2c1b722629a5a690d8838 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Thu, 12 Nov 2026 21:15:22 -0500 Subject: [PATCH] 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 Model-Effort: Opus 5.5 drove and wrote --- crates/ui-egui/src/present/actions.rs | 4 ++++ crates/ui-egui/src/present/tests.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/ui-egui/src/present/actions.rs b/crates/ui-egui/src/present/actions.rs index ec23bd8be..d3386da0a 100644 --- a/crates/ui-egui/src/present/actions.rs +++ b/crates/ui-egui/src/present/actions.rs @@ -281,6 +281,10 @@ impl Presenter { moving: bool, now: f64, ) -> Option { + // 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 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; diff --git a/crates/ui-egui/src/present/tests.rs b/crates/ui-egui/src/present/tests.rs index 58c669754..2cb710923 100644 --- a/crates/ui-egui/src/present/tests.rs +++ b/crates/ui-egui/src/present/tests.rs @@ -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"); } +#[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] fn detail_plan_edge_cases() { use figcraft_geom::Rect as R;