haystack_core/kinds/
coord.rs1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq)]
8pub struct Coord {
9 pub lat: f64,
11 pub lng: f64,
13}
14
15impl Coord {
16 pub fn new(lat: f64, lng: f64) -> Self {
21 Self { lat, lng }
22 }
23}
24
25impl fmt::Display for Coord {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 write!(f, "C({},{})", self.lat, self.lng)
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn coord_display() {
37 let c = Coord::new(37.5458266, -77.4491888);
38 assert_eq!(c.to_string(), "C(37.5458266,-77.4491888)");
39 }
40
41 #[test]
42 fn coord_equality() {
43 assert_eq!(Coord::new(37.0, -77.0), Coord::new(37.0, -77.0));
44 assert_ne!(Coord::new(37.0, -77.0), Coord::new(37.0, -78.0));
45 }
46
47 #[test]
48 fn coord_is_copy() {
49 let c = Coord::new(1.0, 2.0);
50 let c2 = c;
51 assert_eq!(c, c2);
52 }
53}