Refactor Path::contains_point() using any()

This commit is contained in:
pylbrecht 2019-08-25 16:43:29 +02:00
parent ee7f3dbc46
commit 89b8bd516f

View file

@ -185,27 +185,14 @@ impl Path {
} }
pub fn contains_point(&self, x: f64, y: f64, _path_transform: &Transform2D<f32>) -> bool { pub fn contains_point(&self, x: f64, y: f64, _path_transform: &Transform2D<f32>) -> bool {
for op in self.as_raqote().ops.iter() { self.as_raqote().ops.iter().any(|op| match op {
match op { PathOp::MoveTo(point) | PathOp::LineTo(point) => {
PathOp::MoveTo(point) | PathOp::LineTo(point) => { point.x as f64 == x && point.y as f64 == y
if point.x as f64 == x && point.y as f64 == y { },
return true; 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,
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
} }
pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> { pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> {