#[derive(Debug, Clone)] pub struct Gene { pub x: f64, pub y: f64, pub name: String, } impl Gene { // Eucledian distance between two points pub fn dist(&self, other: &Self) -> f64 { ((self.x - other.x).powi(2) + (self.y - other.y).powi(2)).sqrt() } } #[test] fn test_dist() { let g1 = Gene { x: 4.0, y: 1.0, name: "".to_string() }; let g2 = Gene { x: 3.0, y: 0.0, name: "".to_string() }; assert_eq!(format!("{:.3}", g1.dist(&g2)), "1.414"); }