points

Crates.iopoints
lib.rspoints
version0.1.4
sourcesrc
created_at2023-12-12 18:29:00.576067
updated_at2023-12-13 11:59:52.653227
descriptionData structure for representing a pair of coordinates of integer and float types
homepage
repositoryhttps://github.com/jgardona/points
max_upload_size
id1066787
size11,330
Júlio César de Brito Gardona (jgardona)

documentation

README

points

Data structure for representing a pair of coordinates of float type. The structure supports the same sets of linear algebra operation from vectors for a space:

  • Point addition
  • Scalar point addtition
  • Point subtraction
  • Scalar point subtraction
  • Point scalar multiplication
  • Point scalar division
  • Euclidean distance
  • Squared euclidean distance
  • Euclidean norm

Usage

  • Install
cargo add points
  • Expressions
// execute (a + b) * 3 + (a - c)
let p1: Point = Point::default();
let p2 = Point::new(1.0, 3.0);
let p3 = Point::new(1.5, 2.5);
let result = (p1 + p2) * 3.0 + (p1 - p3);
assert_eq!(Point::new(1.5, 6.5), result);

// squared euclidean distance
let p1 = Point::new(1.0, 3.0);
let p2 = Point::new(1.5, 2.0);
let expected = 1.25;
let result = p1.squared_distance_to(p2);
assert_eq!(expected, result);

// euclidean distance
let p1 = Point::new(1.0, 3.0);
let p2 = Point::new(1.5, 2.0);
let expected = 1.118033988749895;
let result = p1.distance_to(p2);
assert_eq!(expected, result);
Commit count: 24

cargo fmt