#linear-algebra #vector #point2d

yanked points

Data structure for representing a pair of coordinates of integer and float types

3 releases

0.1.4 Dec 13, 2023
0.1.3 Dec 12, 2023
0.1.2 Dec 12, 2023
0.1.1 Dec 12, 2023

#238 in #linear-algebra

21 downloads per month

MIT license

10KB
187 lines

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);

No runtime deps