From 89b8bd516fb2173ecd0f7eef98dc3744a0ddccc3 Mon Sep 17 00:00:00 2001 From: pylbrecht Date: Sun, 25 Aug 2019 16:43:29 +0200 Subject: [PATCH] Refactor Path::contains_point() using any() --- components/canvas/raqote_backend.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/components/canvas/raqote_backend.rs b/components/canvas/raqote_backend.rs index 137b00e4bf0..7dc84610809 100644 --- a/components/canvas/raqote_backend.rs +++ b/components/canvas/raqote_backend.rs @@ -185,27 +185,14 @@ impl Path { } pub fn contains_point(&self, x: f64, y: f64, _path_transform: &Transform2D) -> bool { - for op in self.as_raqote().ops.iter() { - match op { - PathOp::MoveTo(point) | PathOp::LineTo(point) => { - if point.x as f64 == x && point.y as f64 == y { - return true; - } - }, - PathOp::QuadTo(_, point) => { - if point.x as f64 == x && point.y as f64 == y { - return true; - } - }, - PathOp::CubicTo(_, _, point) => { - if point.x as f64 == x && point.y as f64 == y { - return true; - } - }, - _ => {}, - } - } - false + self.as_raqote().ops.iter().any(|op| match op { + PathOp::MoveTo(point) | PathOp::LineTo(point) => { + point.x as f64 == x && point.y as f64 == y + }, + PathOp::QuadTo(_, point) => point.x as f64 == x && point.y as f64 == y, + PathOp::CubicTo(_, _, point) => point.x as f64 == x && point.y as f64 == y, + _ => false, + }) } pub fn copy_to_builder(&self) -> Box {