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