https://github.com/cuppachino/intersection_detection
Compute generic 2D line intersections
https://github.com/cuppachino/intersection_detection
2d algebraic-geometry intersection triangulation
Last synced: 11 months ago
JSON representation
Compute generic 2D line intersections
- Host: GitHub
- URL: https://github.com/cuppachino/intersection_detection
- Owner: cuppachino
- Created: 2023-12-05T22:54:29.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-07T07:38:52.000Z (about 2 years ago)
- Last Synced: 2025-03-28T10:49:18.785Z (11 months ago)
- Topics: 2d, algebraic-geometry, intersection, triangulation
- Language: Rust
- Homepage: https://crates.io/crates/intersection_detection
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# intersection_detection
This crate provides functionality for computing intersections between line segments in 2D space.
It defines types for representing intersections and includes methods for checking intersection results,
converting between intersection types, and rounding intersection components to a specified precision.
## Usage
To use this crate, add it as a dependency to your `Cargo.toml` file:
```rust
[dependencies]
intersection_detection = "0.1.3"
```
## Example
```rust
use intersection_detection::{IntersectionResult, Line, PointLike};
fn main() {
let line1 = Line::new([0.0, 0.0], [1.0, 1.0]);
let line2 = Line::new([0.0, 1.0], [1.0, 0.0]);
let computation = line1
.intersection(&line2)
.try_into_intersection()
.ok();
assert_eq!(computation, Some(Intersection::Point([0.5, 0.5])));
}
```
## Points
Implement `FromIntoPointLike` to use custom types as points.
Out-of-the-box implementations are provided for:
- `[F; 2]`
- `[F; 3]`
- `(F, F)`
- `(F, F, F)`
> **Note:** This crate re-exports the `point_like` crate, which is a trait for types that can be used as points.
> The idea here was to let users determine float precision and avoid forcing usage of a specific algebra crate.
> However, most of the methods in `PointLike` are "inspired" by the `glam` crate, so I would recommend using that if you're fine with `f32`.