
intersection2d
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.

Quick iterative example:
fish
cargo run --example fltk_gui --features console_trace
Intersection function API example:
```rust
use intersection2d::{intersect, Intersection};
use geo;
let line1 = geo::Line::::new(
geo::Coordinate { x: 100.0, y: 150.0 },
geo::Coordinate { x: 150.0, y: 100.0 },
);
let line2 = geo::Line::::new(
geo::Coordinate { x: 100.0, y: 150.0 },
geo::Coordinate { x: 150.0, y: 100.0 },
);
let rv = intersect(&line1, &line2);
match _rv {
Some(Intersection::Intersection(a)) => panic!("expected an overlap"),
Some(Intersection::OverLap(a)) => println!("{:?}", a),
None => panic!("expected an overlap"),
}
// you can also get a single intersection point from the Intersection enum.
// Albeit geometrically incorrect, it makes things easy
if let Some(rv) =rv {
println!("{:?}", _rv.single());
}
```
Sweep-line API example:
```rust
use geo;
use intersect2d::algorithm::AlgorithmData;
let l = vec!(geo::Line::new(geo::Coordinate{x:200.,y:200.},geo::Coordinate{x:350.,y:300.}),
geo::Line::new(geo::Coordinate{x:400.,y:200.},geo::Coordinate{x:250.,y:300.}));
if let Some(results) = {
let mut ad = AlgorithmData::::default();
ad.withignoreendpointintersections(false);
ad.withlines(l.iter());
ad.compute(false);
ad.takeresults()
} {
for (p,l) in results.iter() {
println!("Intersection @{:?} Involved lines:{:?}", p, l);
}
}
```
Todo
- [ ] Error handling
- [ ] Benchmark and optimize
- [ ] Stable overlapping co-linear line detection