Class: Sevgi::Sundries::Tile
- Inherits:
-
Object
- Object
- Sevgi::Sundries::Tile
- Includes:
- Enumerable
- Defined in:
- lib/sevgi/sundries/tile.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#element ⇒ Object
readonly
Returns the value of attribute element.
-
#nx ⇒ Object
readonly
Returns the value of attribute nx.
-
#ny ⇒ Object
readonly
Returns the value of attribute ny.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #box ⇒ Object
- #cell ⇒ Object
- #col(i = 0) ⇒ Object
- #colbox(i = 0) ⇒ Object
- #cols ⇒ Object
- #each ⇒ Object (also: #each_row)
- #each_col ⇒ Object
-
#initialize(element, position: Geometry::Origin, nx: 1, ny: 1) ⇒ Tile
constructor
A new instance of Tile.
- #row(i = 0) ⇒ Object
- #rowbox(i = 0) ⇒ Object
- #rows ⇒ Object
Constructor Details
#initialize(element, position: Geometry::Origin, nx: 1, ny: 1) ⇒ Tile
Returns a new instance of Tile.
10 11 12 13 14 15 16 17 18 |
# File 'lib/sevgi/sundries/tile.rb', line 10 def initialize(element, position: Geometry::Origin, nx: 1, ny: 1) raise ArgumentError, "Must be an Element object: #{element}" unless element.is_a?(Geometry::Element) @element = element @position = position @nx = nx @ny = ny end |
Instance Attribute Details
#element ⇒ Object (readonly)
Returns the value of attribute element.
8 9 10 |
# File 'lib/sevgi/sundries/tile.rb', line 8 def element @element end |
#nx ⇒ Object (readonly)
Returns the value of attribute nx.
8 9 10 |
# File 'lib/sevgi/sundries/tile.rb', line 8 def nx @nx end |
#ny ⇒ Object (readonly)
Returns the value of attribute ny.
8 9 10 |
# File 'lib/sevgi/sundries/tile.rb', line 8 def ny @ny end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
8 9 10 |
# File 'lib/sevgi/sundries/tile.rb', line 8 def position @position end |
Instance Method Details
#[](i) ⇒ Object
20 |
# File 'lib/sevgi/sundries/tile.rb', line 20 def [](i) = rows[i] |
#box ⇒ Object
22 |
# File 'lib/sevgi/sundries/tile.rb', line 22 def box = @box ||= Geometry::Rect[nx * element.box.width, ny * element.box.height, position:] |
#cell ⇒ Object
24 |
# File 'lib/sevgi/sundries/tile.rb', line 24 def cell = row.first |
#col(i = 0) ⇒ Object
30 |
# File 'lib/sevgi/sundries/tile.rb', line 30 def col(i = 0) = cols[i] |
#colbox(i = 0) ⇒ Object
26 |
# File 'lib/sevgi/sundries/tile.rb', line 26 def colbox(i = 0) = Geometry::Rect[element.box.width, box.height, position: coordinate(0, i)] |
#cols ⇒ Object
28 |
# File 'lib/sevgi/sundries/tile.rb', line 28 def cols = @cols ||= rows.transpose |
#each ⇒ Object Also known as: each_row
32 |
# File 'lib/sevgi/sundries/tile.rb', line 32 def each(...) = rows.each(...) |
#each_col ⇒ Object
34 |
# File 'lib/sevgi/sundries/tile.rb', line 34 def each_col(...) = cols.each(...) |
#row(i = 0) ⇒ Object
36 |
# File 'lib/sevgi/sundries/tile.rb', line 36 def row(i = 0) = rows[i] |
#rowbox(i = 0) ⇒ Object
38 |
# File 'lib/sevgi/sundries/tile.rb', line 38 def rowbox(i = 0) = Geometry::Rect[box.width, element.box.height, position: coordinate(i)] |
#rows ⇒ Object
40 |
# File 'lib/sevgi/sundries/tile.rb', line 40 def rows = @rows ||= (0...ny).map { |i| (0...nx).map { |j| element.at(coordinate(i, j)) } } |