Crates.io | points |
lib.rs | points |
version | 0.1.4 |
source | src |
created_at | 2023-12-12 18:29:00.576067 |
updated_at | 2023-12-13 11:59:52.653227 |
description | Data structure for representing a pair of coordinates of integer and float types |
homepage | |
repository | https://github.com/jgardona/points |
max_upload_size | |
id | 1066787 |
size | 11,330 |
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 R² space:
cargo add points
// 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);