Class: Knot::Grid
- Inherits:
-
Matrix
- Object
- Matrix
- Knot::Grid
- Defined in:
- lib/knot/grid.rb
Overview
The grid is a Matrix of cells (arranged as rows and columns.)
Instance Attribute Summary collapse
-
#position(i, j) ⇒ Object
readonly
The grid can be navigated with absolute coordinates i, j.
Instance Method Summary collapse
- #e ⇒ Object
- #e2 ⇒ Object
- #n ⇒ Object
- #n2 ⇒ Object
- #ne ⇒ Object
- #ne2 ⇒ Object
- #nw ⇒ Object
- #nw2 ⇒ Object
-
#rel(i, j) ⇒ Object
Nearby cells accessed relatively with i, j.
- #s ⇒ Object
- #s2 ⇒ Object
- #se ⇒ Object
- #se2 ⇒ Object
- #sw ⇒ Object
- #sw2 ⇒ Object
- #w ⇒ Object
- #w2 ⇒ Object
Instance Attribute Details
#position(i, j) ⇒ Object (readonly)
The grid can be navigated with absolute coordinates i, j.
11 12 13 |
# File 'lib/knot/grid.rb', line 11 def position @position end |
Instance Method Details
#e ⇒ Object
29 30 31 |
# File 'lib/knot/grid.rb', line 29 def e rel 0, 1 end |
#e2 ⇒ Object
61 62 63 |
# File 'lib/knot/grid.rb', line 61 def e2 rel 0, 2 end |
#n ⇒ Object
21 22 23 |
# File 'lib/knot/grid.rb', line 21 def n rel -1, 0 end |
#n2 ⇒ Object
53 54 55 |
# File 'lib/knot/grid.rb', line 53 def n2 rel -2, 0 end |
#ne ⇒ Object
25 26 27 |
# File 'lib/knot/grid.rb', line 25 def ne rel -1, 1 end |
#ne2 ⇒ Object
57 58 59 |
# File 'lib/knot/grid.rb', line 57 def ne2 rel -2, 2 end |
#nw ⇒ Object
49 50 51 |
# File 'lib/knot/grid.rb', line 49 def nw rel -1, -1 end |
#nw2 ⇒ Object
81 82 83 |
# File 'lib/knot/grid.rb', line 81 def nw2 rel -2, -2 end |
#rel(i, j) ⇒ Object
Nearby cells accessed relatively with i, j.
17 18 19 |
# File 'lib/knot/grid.rb', line 17 def rel i, j self[*@position + Vector[i, j]] end |
#s ⇒ Object
37 38 39 |
# File 'lib/knot/grid.rb', line 37 def s rel 1, 0 end |
#s2 ⇒ Object
69 70 71 |
# File 'lib/knot/grid.rb', line 69 def s2 rel 2, 0 end |
#se ⇒ Object
33 34 35 |
# File 'lib/knot/grid.rb', line 33 def se rel 1, 1 end |
#se2 ⇒ Object
65 66 67 |
# File 'lib/knot/grid.rb', line 65 def se2 rel 2, 2 end |
#sw ⇒ Object
41 42 43 |
# File 'lib/knot/grid.rb', line 41 def sw rel 1, -1 end |
#sw2 ⇒ Object
73 74 75 |
# File 'lib/knot/grid.rb', line 73 def sw2 rel 2, -2 end |
#w ⇒ Object
45 46 47 |
# File 'lib/knot/grid.rb', line 45 def w rel 0, -1 end |
#w2 ⇒ Object
77 78 79 |
# File 'lib/knot/grid.rb', line 77 def w2 rel 0, -2 end |