fix(chart): clip rotated retained paint only to the sheet

This commit is contained in:
Dylan M. Taylor
2026-12-02 00:21:27 -05:00
parent d6dc4eb038
commit 8fb0e16ed3
+8 -1
View File
@@ -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));
}