1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::log::tools::{CellTool, Grid, Pixel};

/// Represents one cell of a grid
#[derive(Hash, Eq, PartialEq, Debug, Clone, Copy)]
pub struct Cell {
  grid_id: usize,
  grid: Grid,
  x: u16,
  y: u16,
}

impl Cell {
  pub fn new((grid_id, grid, tool): (usize, Grid, CellTool)) ->
    (Cell, Pixel) {
      match tool {
        CellTool::PixelBrush(pixel, x , y) => return (Cell {
            grid_id: grid_id,
            grid: grid,
            x: x,
            y: y,
          }, Pixel::Full(pixel)),
        CellTool::PixelEraser(x, y) => return (Cell {
            grid_id: grid_id,
            grid: grid,
            x: x,
            y: y,
          }, Pixel::Empty),
      }
  }

  /// Returns a new Cell object with a new grid id and other fields cell
  /// caller
  pub fn set_grid_id(&self, new_grid_id: usize) -> Cell {
    Cell {
      grid_id: new_grid_id,
      grid: self.grid,
      x: self.x,
      y: self.y,
    }
  }

  pub fn get_grid_id(&self) -> usize {
    self.grid_id
  }

  pub fn get_grid(&self) -> Grid {
    self.grid
  }

  pub fn get_x(&self) -> u16 {
    self.x
  }

  pub fn get_y(&self) -> u16 {
    self.y
  }
}