Skip to main content

grid_map/loc/
loc.rs

1use crate::Scale;
2use std::fmt::{Debug, Display, Formatter};
3
4/// A two-dimensional grid location.
5#[derive(Copy, Clone, Eq, PartialEq, Hash, Default)]
6pub struct Loc {
7    pub x: Scale,
8    pub y: Scale,
9}
10
11impl Loc {
12    //! Construction
13
14    /// Creates a new location
15    pub const fn new(x: Scale, y: Scale) -> Self {
16        Self { x, y }
17    }
18}
19
20impl From<(Scale, Scale)> for Loc {
21    fn from((x, y): (Scale, Scale)) -> Self {
22        Self { x, y }
23    }
24}
25
26impl From<Loc> for (Scale, Scale) {
27    fn from(loc: Loc) -> Self {
28        (loc.x, loc.y)
29    }
30}
31
32impl Debug for Loc {
33    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
34        write!(f, "{}", self)
35    }
36}
37
38impl Display for Loc {
39    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40        write!(f, "({}, {})", self.x, self.y)
41    }
42}