legasea_line

Crates.iolegasea_line
lib.rslegasea_line
version0.2.3
created_at2020-09-11 15:52:34.176311+00
updated_at2025-11-29 05:04:01.346093+00
descriptionTools for working with lines
homepagehttps://git.sr.ht/~halzy/legasea_line
repositoryhttps://git.sr.ht/~halzy/legasea_line
max_upload_size
id287425
size10,304
Benjamin Halsted (halzy)

documentation

README

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

Commit count: 0

cargo fmt