1#[cfg(feature="serde")]
2use serde::{Deserialize, Serialize};
3
4use super::Dimensions;
5
6#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
24#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
25pub struct Coordinate {
26 pub row : usize,
27 pub column : usize
28}
29
30impl From <(usize, usize)> for Coordinate {
31 fn from ((row, column) : (usize, usize)) -> Self {
32 Coordinate { row, column }
33 }
34}
35impl From <[usize; 2]> for Coordinate {
36 fn from ([row, column] : [usize; 2]) -> Self {
37 Coordinate { row, column }
38 }
39}
40impl From <Coordinate> for (usize, usize) {
41 fn from (Coordinate { row, column } : Coordinate) -> Self {
42 (row, column)
43 }
44}
45impl From <Coordinate> for [usize; 2] {
46 fn from (Coordinate { row, column } : Coordinate) -> Self {
47 [row, column]
48 }
49}
50impl std::ops::Add <Dimensions> for Coordinate {
51 type Output = Coordinate;
52 fn add (self, rhs : Dimensions) -> Coordinate {
53 (self.row + rhs.rows, self.column + rhs.columns).into()
54 }
55}
56impl std::ops::Sub <Dimensions> for Coordinate {
57 type Output = Coordinate;
58 fn sub (self, rhs : Dimensions) -> Coordinate {
59 (self.row - rhs.rows, self.column - rhs.columns).into()
60 }
61}