Simplify order match statement in quad::Batch::add
This commit is contained in:
parent
6d650e7f99
commit
cd7d33aa8e
1 changed files with 9 additions and 26 deletions
|
|
@ -244,9 +244,6 @@ pub struct Batch {
|
||||||
|
|
||||||
/// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count.
|
/// The quad order of the [`Layer`]; stored as a tuple of the quad type & its count.
|
||||||
order: Vec<(Kind, usize)>,
|
order: Vec<(Kind, usize)>,
|
||||||
|
|
||||||
/// The last index of quad ordering.
|
|
||||||
index: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Batch {
|
impl Batch {
|
||||||
|
|
@ -257,7 +254,7 @@ impl Batch {
|
||||||
|
|
||||||
/// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`].
|
/// Adds a [`Quad`] with the provided `Background` type to the quad [`Layer`].
|
||||||
pub fn add(&mut self, quad: Quad, background: &Background) {
|
pub fn add(&mut self, quad: Quad, background: &Background) {
|
||||||
let quad_order = match background {
|
let kind = match background {
|
||||||
Background::Color(color) => {
|
Background::Color(color) => {
|
||||||
self.solids.push(Solid {
|
self.solids.push(Solid {
|
||||||
color: color.into_linear(),
|
color: color.into_linear(),
|
||||||
|
|
@ -276,37 +273,23 @@ impl Batch {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.gradients.push(quad);
|
self.gradients.push(quad);
|
||||||
|
|
||||||
Kind::Gradient
|
Kind::Gradient
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match (self.order.get_mut(self.index), quad_order) {
|
match self.order.last_mut() {
|
||||||
(Some((quad_order, count)), Kind::Solid) => match quad_order {
|
Some((last_kind, count)) if kind == *last_kind => {
|
||||||
Kind::Solid => {
|
*count += 1;
|
||||||
*count += 1;
|
}
|
||||||
}
|
_ => {
|
||||||
Kind::Gradient => {
|
self.order.push((kind, 1));
|
||||||
self.order.push((Kind::Solid, 1));
|
|
||||||
self.index += 1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(Some((quad_order, count)), Kind::Gradient) => match quad_order {
|
|
||||||
Kind::Solid => {
|
|
||||||
self.order.push((Kind::Gradient, 1));
|
|
||||||
self.index += 1;
|
|
||||||
}
|
|
||||||
Kind::Gradient => {
|
|
||||||
*count += 1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
(None, _) => {
|
|
||||||
self.order.push((quad_order, 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
/// The kind of a quad.
|
/// The kind of a quad.
|
||||||
enum Kind {
|
enum Kind {
|
||||||
/// A solid quad
|
/// A solid quad
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue