@@ -608,6 +608,7 @@ pub fn round_line_join(bezpath1: &BezPath, bezpath2: &BezPath, center: DVec2) ->
608
608
}
609
609
610
610
/// Returns `true` if the `bezpath1` is completely inside the `bezpath2`.
611
+ /// NOTE: The `bezpath2` has to be a closed path to get correct result.
611
612
pub fn bezpath_is_inside_bezpath ( bezpath1 : & BezPath , bezpath2 : & BezPath , accuracy : Option < f64 > , minimum_separation : Option < f64 > ) -> bool {
612
613
// Eliminate any possibility of one being inside the other, if either of them is empty
613
614
if bezpath1. is_empty ( ) || bezpath2. is_empty ( ) {
@@ -617,19 +618,25 @@ pub fn bezpath_is_inside_bezpath(bezpath1: &BezPath, bezpath2: &BezPath, accurac
617
618
let inner_bbox = bezpath1. bounding_box ( ) ;
618
619
let outer_bbox = bezpath2. bounding_box ( ) ;
619
620
620
- // Eliminate 'bezpath1' if its bounding box is completely outside the bezpath2's bounding box
621
+ // Eliminate if the 'bezpath1' bounding box is completely outside the bezpath2's bounding box
621
622
if !outer_bbox. contains_rect ( inner_bbox) && outer_bbox. intersect ( inner_bbox) . is_zero_area ( ) {
622
623
return false ;
623
624
}
624
625
625
- // Eliminate this subpath if it intersects with the other subpath.
626
+ // Eliminate if any anchors point of the 'bezpath1' is outside the 'bezpath2'.
627
+ if !bezpath1. elements ( ) . iter ( ) . flat_map ( |elm| elm. end_point ( ) ) . all ( |point| bezpath2. contains ( point) ) {
628
+ return false ;
629
+ }
630
+
631
+ // Eliminate if 'bezpath1' intersects with 'bezpath2'.
626
632
if !bezpath_intersections ( bezpath1, & bezpath2, accuracy, minimum_separation) . is_empty ( ) {
627
633
return false ;
628
634
}
629
635
630
636
// At this point:
631
637
// (1) The 'bezpath1' bounding box either intersect or is inside the 'bezpath2's bounding box,
632
- // (2) The 'bezpath1' is not intersecting with the 'bezpath2'.
638
+ // (2) All the anchor point of the 'bezpath1' is inside 'bezpath2'
639
+ // (3) The 'bezpath1' is not intersecting with the 'bezpath2'.
633
640
// Hence, this subpath is completely inside the given other subpath.
634
641
true
635
642
}
0 commit comments