#line #distance

legasea_line

Tools for working with lines

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

Download history 28/week @ 2025-10-23 10/week @ 2025-10-30 9/week @ 2025-11-06 48/week @ 2025-11-13 13/week @ 2025-11-20 15/week @ 2025-11-27 6/week @ 2025-12-04 3/week @ 2025-12-11 11/week @ 2025-12-18 8/week @ 2025-12-25 48/week @ 2026-01-01 7/week @ 2026-01-22 17/week @ 2026-01-29 33/week @ 2026-02-05

57 downloads per month
Used in 9 crates (via ramer_douglas_peucker)

MIT license

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 a distance() method that returns a LineDistance.
  • LineDistance - Pre-calculates values for efficient repeated distance calculations. Use to(&point) to get the perpendicular distance from the line to a point. Also exposes the length of the line segment.

Dependencies

  • mint - For the Point2 type
  • num-traits - For numeric type conversions

License

MIT

Dependencies

~160KB