Repository: GraphiteEditor/Graphite
File: node-graph/gcore/src/vector/algorithms/bezpath_algorithms.rs (Rust)

Code before:
	}

	compute_circular_subpath_details(left, arc_point, right, center, Some(angle))
}

/// Returns `true` if the `bezpath1` is completely inside the `bezpath2`.
/// NOTE: `bezpath2` must be a closed path to get correct results.
pub fn bezpath_is_inside_bezpath(bezpath1: &BezPath, bezpath2: &BezPath, accuracy: Option<f64>, minimum_separation: Option<f64>) -> bool {
	// Eliminate any possibility of one being inside the other, if either of them are empty
	if bezpath1.is_empty() || bezpath2.is_empty() {
		return false;
	}

	let inner_bbox = bezpath1.bounding_box();
	let outer_bbox = bezpath2.bounding_box();

	// Eliminate bezpath1 if its bounding box is not completely inside the bezpath2's bounding box.
	// Reasoning:
	// If the inner bezpath bounding box is larger than the outer bezpath bounding box in any direction
	// then the inner bezpath is intersecting with or outside the outer bezpath.
	if !outer_bbox.contains_rect(inner_bbox) && outer_bbox.intersect(inner_bbox).is_zero_area() {
		return false;
	}

	// Eliminate bezpath1 if any of its anchor points are outside the bezpath2.
	if !bezpath1.elements().iter().filter_map(|elm| elm.end_point()).all(|point| bezpath2.contains(point)) {
		return false;
	}

	// Eliminate this subpath if it intersects with the other subpath.
	if !bezpath_intersections(bezpath1, bezpath2, accuracy, minimum_separation).is_empty() {
		return false;
	}

	// At this point:
	// (1) This subpath's bounding box is inside the other subpath's bounding box,
	// (2) Its anchors are inside the other subpath, and
	// (3) It is not intersecting with the other subpath.
	// Hence, this subpath is completely inside the given other subpath.
	true
}

#[cfg(test)]
mod tests {
	// TODO: add more intersection tests

	use super::bezpath_is_inside_bezpath;
	use kurbo::{BezPath, DEFAULT_ACCURACY, Line, Point, Rect, Shape};

	#[test]
	fn is_inside_subpath() {

Review comment (suggestion):
```suggestion
	if !bezpath1.elements().iter().filter_map(|el| el.end_point()).all(|point| bezpath2.contains(point)) {
```

Code after:
	}

	compute_circular_subpath_details(left, arc_point, right, center, Some(angle))
}

/// Returns `true` if the `bezpath1` is completely inside the `bezpath2`.
/// NOTE: `bezpath2` must be a closed path to get correct results.
pub fn bezpath_is_inside_bezpath(bezpath1: &BezPath, bezpath2: &BezPath, accuracy: Option<f64>, minimum_separation: Option<f64>) -> bool {
	// Eliminate any possibility of one being inside the other, if either of them are empty
	if bezpath1.is_empty() || bezpath2.is_empty() {
		return false;
	}

	let inner_bbox = bezpath1.bounding_box();
	let outer_bbox = bezpath2.bounding_box();

	// Eliminate bezpath1 if its bounding box is not completely inside the bezpath2's bounding box.
	// Reasoning:
	// If the inner bezpath bounding box is larger than the outer bezpath bounding box in any direction
	// then the inner bezpath is intersecting with or outside the outer bezpath.
	if !outer_bbox.contains_rect(inner_bbox) && outer_bbox.intersect(inner_bbox).is_zero_area() {
		return false;
	}

	// Eliminate bezpath1 if any of its anchor points are outside the bezpath2.
	if !bezpath1.elements().iter().filter_map(|el| el.end_point()).all(|point| bezpath2.contains(point)) {
		return false;
	}

	// Eliminate this subpath if it intersects with the other subpath.
	if !bezpath_intersections(bezpath1, bezpath2, accuracy, minimum_separation).is_empty() {
		return false;
	}

	// At this point:
	// (1) This subpath's bounding box is inside the other subpath's bounding box,
	// (2) Its anchors are inside the other subpath, and
	// (3) It is not intersecting with the other subpath.
	// Hence, this subpath is completely inside the given other subpath.
	true
}

#[cfg(test)]
mod tests {
	// TODO: add more intersection tests

	use super::bezpath_is_inside_bezpath;
	use kurbo::{BezPath, DEFAULT_ACCURACY, Line, Point, Rect, Shape};

	#[test]
	fn is_inside_subpath() {