diff --git a/core/src/point.rs b/core/src/point.rs index 55872911..e2b51e04 100644 --- a/core/src/point.rs +++ b/core/src/point.rs @@ -34,6 +34,18 @@ impl Point { a.hypot(b) } + + /// Computes the distance to another [`Point`], using a slower but more deterministic algorithm. + /// Useful for sorting algorithms. + pub fn distance_slow(&self, to: Self) -> T + where + T: Float, + { + let a = self.x - to.x; + let b = self.y - to.y; + + (a * a + b * b).sqrt() + } } impl From<[T; 2]> for Point diff --git a/graphics/src/damage.rs b/graphics/src/damage.rs index 8aa42798..6e2d1ab8 100644 --- a/graphics/src/damage.rs +++ b/graphics/src/damage.rs @@ -49,8 +49,8 @@ pub fn group(mut damage: Vec, bounds: Rectangle) -> Vec { damage.sort_by(|a, b| { a.center() - .distance(Point::ORIGIN) - .total_cmp(&b.center().distance(Point::ORIGIN)) + .distance_slow(Point::ORIGIN) + .total_cmp(&b.center().distance_slow(Point::ORIGIN)) }); let mut output = Vec::new();