coordinates_outliers/point.rs
1//! A simple point in 2D plane of type (x,y)
2
3use std::fmt;
4
5/// Custom point type, location is usually in float numeric
6#[derive(Debug, Copy, Clone)]
7pub struct Point {
8 pub(crate) x: f64,
9 pub(crate) y: f64,
10}
11
12impl Point {
13 /// We round off the location to upto `3` decimal places
14 pub fn new(x: f64, y: f64) -> Self {
15 Point {
16 x: f64::trunc(x * 1000.0) / 1000.0,
17 y: f64::trunc(y * 1000.0) / 1000.0,
18 }
19 }
20}
21
22/// Pretty display for coordinates, also used to make hashes
23impl fmt::Display for Point {
24 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25 write!(f, "{:5} {:5}", self.x, self.y)
26 }
27}