use super::path::*;
use super::to_curves::*;
use super::super::curve::*;
use super::super::intersection::*;
use super::super::super::geo::*;
use super::super::super::line::*;
pub fn path_intersects_line<'a, Path: BezierPath, L: Line<Point=Path::Point>>(path: &'a Path, line: &'a L) -> impl 'a+Iterator<Item=(usize, f64, f64)>
where Path::Point: 'a+Coordinate2D {
path_to_curves::<_, Curve<_>>(path)
.enumerate()
.flat_map(move |(section_id, curve)| curve_intersects_line(&curve, line).into_iter().map(move |(t, s, _pos)| (section_id, t, s)))
}
pub fn path_intersects_ray<'a, Path: BezierPath, L: Line<Point=Path::Point>>(path: &'a Path, line: &'a L) -> impl 'a+Iterator<Item=(usize, f64, f64)>
where Path::Point: 'a+Coordinate2D {
path_to_curves::<_, Curve<_>>(path)
.enumerate()
.flat_map(move |(section_id, curve)| curve_intersects_line(&curve, line).into_iter().map(move |(t, s, _pos)| (section_id, t, s)))
}
pub fn path_intersects_path<'a, Path: BezierPath>(path1: &'a Path, path2: &'a Path, accuracy: f64) -> Vec<((usize, f64), (usize, f64))>
where Path::Point: 'a+Coordinate2D {
let path1_sections = path_to_curves::<_, Curve<_>>(path1)
.enumerate()
.map(|(section_id, curve)| (section_id, curve, curve.bounding_box::<Bounds<_>>()));
let path2_sections = path_to_curves::<_, Curve<_>>(path2)
.enumerate()
.map(|(section_id, curve)| (section_id, curve, curve.bounding_box::<Bounds<_>>()))
.collect::<Vec<_>>();
let mut result = vec![];
for (p1_section_id, p1_curve, p1_curve_bounds) in path1_sections {
for (p2_section_id, p2_curve, p2_curve_bounds) in path2_sections.iter() {
if p1_curve_bounds.overlaps(p2_curve_bounds) {
let intersections = curve_intersects_curve_clip(&p1_curve, p2_curve, accuracy);
result.extend(intersections.into_iter().map(|(t1, t2)| ((p1_section_id, t1), (*p2_section_id, t2)) ));
}
}
}
result
}