Fix shape not closed after using Fill Tool (#510)

* Always set shape property 'closed' on fill

* Remove closed property on Shape

* Make color mandatory in Fill

* Fix intersection for filled but open shapes

* Code style tweak

* Add TODO note to rework ClosePath check
This commit is contained in:
Paul Kupper
2022-02-06 23:06:23 +01:00
committed by Keavon Chambers
parent ca46767cf2
commit 386c970b60
10 changed files with 32 additions and 47 deletions
+9 -3
View File
@@ -47,18 +47,24 @@ fn to_point(vec: DVec2) -> Point {
Point::new(vec.x, vec.y)
}
pub fn intersect_quad_bez_path(quad: Quad, shape: &BezPath, closed: bool) -> bool {
pub fn intersect_quad_bez_path(quad: Quad, shape: &BezPath, filled: bool) -> bool {
let mut shape = shape.clone();
// for filled shapes act like shape was closed even if it isn't
if filled && shape.elements().last() != Some(&kurbo::PathEl::ClosePath) {
shape.close_path();
}
// check if outlines intersect
if shape.segments().any(|path_segment| quad.lines().iter().any(|line| !path_segment.intersect_line(*line).is_empty())) {
return true;
}
// check if selection is entirely within the shape
if closed && shape.contains(to_point(quad.0[0])) {
if filled && shape.contains(to_point(quad.0[0])) {
return true;
}
// check if shape is entirely within selection
get_arbitrary_point_on_path(shape).map(|shape_point| quad.path().contains(shape_point)).unwrap_or_default()
get_arbitrary_point_on_path(&shape).map(|shape_point| quad.path().contains(shape_point)).unwrap_or_default()
}
pub fn get_arbitrary_point_on_path(path: &BezPath) -> Option<Point> {