From 8fb0e16ed3d1cdec34ccb74635db69a9f854bb85 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 2 Dec 2026 00:21:27 -0500 Subject: [PATCH] fix(chart): clip rotated retained paint only to the sheet --- crates/ui-egui/src/chartview.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/chartview.rs b/crates/ui-egui/src/chartview.rs index bcf697d0f..30db74dcd 100644 --- a/crates/ui-egui/src/chartview.rs +++ b/crates/ui-egui/src/chartview.rs @@ -743,6 +743,10 @@ fn turn_shape(shape: &mut egui::Shape, c: Pos2, deg: f32) { Shape::Vec(v) => v.iter_mut().for_each(|s| turn_shape(s, c, deg)), Shape::PaintChunk(shapes) => { for clipped in std::sync::Arc::make_mut(shapes) { + // The sheet clip is already applied by turn_painted. Retained child clips + // are in their parent's coordinate space, so drop them rather than substituting + // the sheet's screen-space rect, which could be transformed a second time. + clipped.clip_rect = Rect::EVERYTHING; // The retained shape may have its own post-tessellation scale and translation. let local_center = clipped.transform_after_tessellation.inverse() * c; turn_shape(&mut clipped.shape, local_center, deg); @@ -808,7 +812,8 @@ pub(crate) mod tests { #[test] fn rotating_retained_paint_keeps_shared_records_unchanged() { let center = pos2(10.0, 10.0); - let mut clipped = egui::epaint::ClippedShape::new(Rect::EVERYTHING, egui::Shape::circle_filled(pos2(2.0, 0.0), 1.0, Color32::WHITE)); + let child_clip = Rect::from_min_max(pos2(11.0, 9.0), pos2(13.0, 11.0)); + let mut clipped = egui::epaint::ClippedShape::new(child_clip, egui::Shape::circle_filled(pos2(2.0, 0.0), 1.0, Color32::WHITE)); clipped.transform_after_tessellation = egui::emath::TSTransform::from_translation(center.to_vec2()); let original: std::sync::Arc<[_]> = vec![clipped].into(); let mut chunk = egui::Shape::PaintChunk(original.clone()); @@ -818,6 +823,8 @@ pub(crate) mod tests { let egui::Shape::PaintChunk(turned) = chunk else { panic!("expected retained paint") }; let egui::Shape::Circle(circle) = &turned[0].shape else { panic!("expected circle") }; assert!(circle.center.distance(pos2(0.0, 2.0)) < 0.001); + assert_eq!(turned[0].clip_rect, Rect::EVERYTHING, "rotated paint clips only to its sheet"); + assert_eq!(original[0].clip_rect, child_clip, "shared paint retains its own clip"); let egui::Shape::Circle(circle) = &original[0].shape else { panic!("expected original circle") }; assert_eq!(circle.center, pos2(2.0, 0.0)); }