intersect2d
After watching Philipp Kindermann's excellent sweep-line videos I think I finally understand how this algorithm works.
This is my humble take on an implementation of the segment line
intersection sweep-line algorithm.
The library crate also contains a line intersection function.
Code still in development, not ready for any purpose.
Interactive step-by-step example:
cargo run --example fltk_gui --features console_trace
Most of this crate have been adapted for nalgebra, cgmath, mint and plain vector here.
Intersection function API example:
use ;
use geo;
let line1: = .into;
let line2: = .into;
let _rv = intersect;
match _rv
// you can also get a single intersection point from the Intersection enum.
// Albeit geometrically incorrect, it makes things easy
if let Some =_rv
Sweep-line API example:
use geo;
use AlgorithmData;
let _l = vec!;
let results = default
.with_ignore_end_point_intersections?
.with_lines?
.compute?;
for in results.iter
Detection of self-intersecting geo::LineString:
let coordinates = vec!;
let line_string = from;
// Obviously this example only makes sense for LinesStrings with many points.
// A simple brute force O(n²) intersection test will be faster than this O(nlog(n)+k)
// sweep-line algorithm if n is small enough.
let result = default
.with_ignore_end_point_intersections?
.with_stop_at_first_intersection?
.with_lines?
.compute?;
for in result.iter
or using the SelfIntersectingExclusive
trait:
// SelfIntersectingExclusive does not report endpoint intersections
use SelfIntersectingExclusive;
let coordinates = vec!;
let line_string = from;
if line_string.is_self_intersecting?
for intersections in line_string.self_intersections?
You can also check a bunch of geo::Line
for self intersections using the SelfIntersectingInclusive
trait:
// SelfIntersectingInclusive reports endpoint intersections
use SelfIntersectingInclusive;
let lines = vec!;
if lines.is_self_intersecting_inclusive?
for intersections in lines.self_intersections_inclusive?
Todo
- Error handling
- Benchmark and optimize
- Stable overlapping co-linear line detection