Refactor: turn `ClippedShape` from struct-enum to a normal struct (#3225)
This commit is contained in:
parent
66cbb61ad5
commit
83c18498e9
|
|
@ -127,7 +127,7 @@ impl PaintList {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn add(&mut self, clip_rect: Rect, shape: Shape) -> ShapeIdx {
|
pub fn add(&mut self, clip_rect: Rect, shape: Shape) -> ShapeIdx {
|
||||||
let idx = ShapeIdx(self.0.len());
|
let idx = ShapeIdx(self.0.len());
|
||||||
self.0.push(ClippedShape(clip_rect, shape));
|
self.0.push(ClippedShape { clip_rect, shape });
|
||||||
idx
|
idx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ impl PaintList {
|
||||||
self.0.extend(
|
self.0.extend(
|
||||||
shapes
|
shapes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|shape| ClippedShape(clip_rect, shape)),
|
.map(|shape| ClippedShape { clip_rect, shape }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,12 +148,12 @@ impl PaintList {
|
||||||
/// and then later setting it using `paint_list.set(idx, cr, frame);`.
|
/// and then later setting it using `paint_list.set(idx, cr, frame);`.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set(&mut self, idx: ShapeIdx, clip_rect: Rect, shape: Shape) {
|
pub fn set(&mut self, idx: ShapeIdx, clip_rect: Rect, shape: Shape) {
|
||||||
self.0[idx.0] = ClippedShape(clip_rect, shape);
|
self.0[idx.0] = ClippedShape { clip_rect, shape };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translate each [`Shape`] and clip rectangle by this much, in-place
|
/// Translate each [`Shape`] and clip rectangle by this much, in-place
|
||||||
pub fn translate(&mut self, delta: Vec2) {
|
pub fn translate(&mut self, delta: Vec2) {
|
||||||
for ClippedShape(clip_rect, shape) in &mut self.0 {
|
for ClippedShape { clip_rect, shape } in &mut self.0 {
|
||||||
*clip_rect = clip_rect.translate(delta);
|
*clip_rect = clip_rect.translate(delta);
|
||||||
shape.translate(delta);
|
shape.translate(delta);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ fn tessellate_circles(c: &mut Criterion) {
|
||||||
for _ in 0..10_000 {
|
for _ in 0..10_000 {
|
||||||
let clip_rect = Rect::from_min_size(Pos2::ZERO, Vec2::splat(1024.0));
|
let clip_rect = Rect::from_min_size(Pos2::ZERO, Vec2::splat(1024.0));
|
||||||
let shape = Shape::circle_filled(Pos2::new(10.0, 10.0), r, Color32::WHITE);
|
let shape = Shape::circle_filled(Pos2::new(10.0, 10.0), r, Color32::WHITE);
|
||||||
clipped_shapes.push(ClippedShape(clip_rect, shape));
|
clipped_shapes.push(ClippedShape { clip_rect, shape });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_eq!(clipped_shapes.len(), 100_000);
|
assert_eq!(clipped_shapes.len(), 100_000);
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,14 @@ impl Default for TextureId {
|
||||||
///
|
///
|
||||||
/// Everything is using logical points.
|
/// Everything is using logical points.
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct ClippedShape(
|
pub struct ClippedShape {
|
||||||
/// Clip / scissor rectangle.
|
/// Clip / scissor rectangle.
|
||||||
/// Only show the part of the [`Shape`] that falls within this.
|
/// Only show the part of the [`Shape`] that falls within this.
|
||||||
pub emath::Rect,
|
pub clip_rect: emath::Rect,
|
||||||
|
|
||||||
/// The shape
|
/// The shape
|
||||||
pub Shape,
|
pub shape: Shape,
|
||||||
);
|
}
|
||||||
|
|
||||||
/// A [`Mesh`] or [`PaintCallback`] within a clip rectangle.
|
/// A [`Mesh`] or [`PaintCallback`] within a clip rectangle.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ impl PaintStats {
|
||||||
stats.shape_vec.element_size = ElementSize::Heterogenous; // nicer display later
|
stats.shape_vec.element_size = ElementSize::Heterogenous; // nicer display later
|
||||||
|
|
||||||
stats.shapes = AllocInfo::from_slice(shapes);
|
stats.shapes = AllocInfo::from_slice(shapes);
|
||||||
for ClippedShape(_, shape) in shapes {
|
for ClippedShape { shape, .. } in shapes {
|
||||||
stats.add(shape);
|
stats.add(shape);
|
||||||
}
|
}
|
||||||
stats
|
stats
|
||||||
|
|
|
||||||
|
|
@ -1036,7 +1036,10 @@ impl Tessellator {
|
||||||
clipped_shape: ClippedShape,
|
clipped_shape: ClippedShape,
|
||||||
out_primitives: &mut Vec<ClippedPrimitive>,
|
out_primitives: &mut Vec<ClippedPrimitive>,
|
||||||
) {
|
) {
|
||||||
let ClippedShape(new_clip_rect, new_shape) = clipped_shape;
|
let ClippedShape {
|
||||||
|
clip_rect: new_clip_rect,
|
||||||
|
shape: new_shape,
|
||||||
|
} = clipped_shape;
|
||||||
|
|
||||||
if !new_clip_rect.is_positive() {
|
if !new_clip_rect.is_positive() {
|
||||||
return; // skip empty clip rectangles
|
return; // skip empty clip rectangles
|
||||||
|
|
@ -1044,7 +1047,13 @@ impl Tessellator {
|
||||||
|
|
||||||
if let Shape::Vec(shapes) = new_shape {
|
if let Shape::Vec(shapes) = new_shape {
|
||||||
for shape in shapes {
|
for shape in shapes {
|
||||||
self.tessellate_clipped_shape(ClippedShape(new_clip_rect, shape), out_primitives);
|
self.tessellate_clipped_shape(
|
||||||
|
ClippedShape {
|
||||||
|
clip_rect: new_clip_rect,
|
||||||
|
shape,
|
||||||
|
},
|
||||||
|
out_primitives,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1641,7 +1650,10 @@ fn test_tessellator() {
|
||||||
shapes.push(Shape::mesh(mesh));
|
shapes.push(Shape::mesh(mesh));
|
||||||
|
|
||||||
let shape = Shape::Vec(shapes);
|
let shape = Shape::Vec(shapes);
|
||||||
let clipped_shapes = vec![ClippedShape(rect, shape)];
|
let clipped_shapes = vec![ClippedShape {
|
||||||
|
clip_rect: rect,
|
||||||
|
shape,
|
||||||
|
}];
|
||||||
|
|
||||||
let font_tex_size = [1024, 1024]; // unused
|
let font_tex_size = [1024, 1024]; // unused
|
||||||
let prepared_discs = vec![]; // unused
|
let prepared_discs = vec![]; // unused
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue