Sort damage by distance from origin in iced_graphics::damage
This commit is contained in:
parent
fdd9896dc5
commit
1e8554bf02
2 changed files with 12 additions and 13 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
//! Compute the damage between frames.
|
//! Compute the damage between frames.
|
||||||
use crate::core::Rectangle;
|
use crate::core::{Point, Rectangle};
|
||||||
|
|
||||||
/// Diffs the damage regions given some previous and current primitives.
|
/// Diffs the damage regions given some previous and current primitives.
|
||||||
pub fn diff<T>(
|
pub fn diff<T>(
|
||||||
|
|
@ -50,9 +50,10 @@ pub fn group(mut damage: Vec<Rectangle>, bounds: Rectangle) -> Vec<Rectangle> {
|
||||||
const AREA_THRESHOLD: f32 = 20_000.0;
|
const AREA_THRESHOLD: f32 = 20_000.0;
|
||||||
|
|
||||||
damage.sort_by(|a, b| {
|
damage.sort_by(|a, b| {
|
||||||
a.x.partial_cmp(&b.x)
|
a.center()
|
||||||
|
.distance(Point::ORIGIN)
|
||||||
|
.partial_cmp(&b.center().distance(Point::ORIGIN))
|
||||||
.unwrap_or(Ordering::Equal)
|
.unwrap_or(Ordering::Equal)
|
||||||
.then_with(|| a.y.partial_cmp(&b.y).unwrap_or(Ordering::Equal))
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
|
|
|
||||||
|
|
@ -213,16 +213,14 @@ impl Layer {
|
||||||
¤t.primitives,
|
¤t.primitives,
|
||||||
|item| match item {
|
|item| match item {
|
||||||
Item::Live(primitive) => vec![primitive.visible_bounds()],
|
Item::Live(primitive) => vec![primitive.visible_bounds()],
|
||||||
Item::Group(primitives, bounds, transformation) => {
|
Item::Group(primitives, group_bounds, transformation) => {
|
||||||
damage::group(
|
primitives
|
||||||
primitives
|
.as_slice()
|
||||||
.as_slice()
|
.iter()
|
||||||
.iter()
|
.map(Primitive::visible_bounds)
|
||||||
.map(Primitive::visible_bounds)
|
.map(|bounds| bounds * *transformation)
|
||||||
.map(|bounds| bounds * *transformation)
|
.filter_map(|bounds| bounds.intersection(group_bounds))
|
||||||
.collect(),
|
.collect()
|
||||||
*bounds,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Item::Cached(_, bounds, _) => {
|
Item::Cached(_, bounds, _) => {
|
||||||
vec![*bounds]
|
vec![*bounds]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue