4 releases
| 0.2.3 | Nov 29, 2025 |
|---|---|
| 0.2.1 | Feb 21, 2021 |
| 0.2.0 | Sep 11, 2020 |
| 0.1.0 | Sep 11, 2020 |
#457 in Math
57 downloads per month
Used in 9 crates
(via ramer_douglas_peucker)
8KB
144 lines
legasea_line
A simple utility for working with lines.
Provides a method to get the distance from a point to a Line.
Usage
Add this to your Cargo.toml:
[dependencies]
legasea_line = "0.2"
Example
use legasea_line::Line;
use mint::Point2;
// Create a horizontal line from (-3, 1) to (3, 1)
let a = Point2 { x: -3, y: 1 };
let b = Point2 { x: 3, y: 1 };
let line = Line::new(a, b);
// Get a LineDistance calculator for efficient repeated distance calculations
let line_distance = line.distance();
// Calculate the perpendicular distance from a point to the line
let point = Point2 { x: 0, y: 6 };
let distance = line_distance.to(&point).unwrap();
assert_eq!(distance, 5.0);
Types
Line<T>- A line defined by two points. Provides adistance()method that returns aLineDistance.LineDistance- Pre-calculates values for efficient repeated distance calculations. Useto(&point)to get the perpendicular distance from the line to a point. Also exposes thelengthof the line segment.
Dependencies
mint- For thePoint2typenum-traits- For numeric type conversions
License
MIT
Dependencies
~160KB