Class: Sevgi::Sundries::Tile

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sevgi/sundries/tile.rb

Direct Known Subclasses

Grid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, position: Geometry::Origin, nx: 1, ny: 1) ⇒ Tile

Returns a new instance of Tile.

Raises:

  • (ArgumentError)


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

#elementObject (readonly)

Returns the value of attribute element.



8
9
10
# File 'lib/sevgi/sundries/tile.rb', line 8

def element
  @element
end

#nxObject (readonly)

Returns the value of attribute nx.



8
9
10
# File 'lib/sevgi/sundries/tile.rb', line 8

def nx
  @nx
end

#nyObject (readonly)

Returns the value of attribute ny.



8
9
10
# File 'lib/sevgi/sundries/tile.rb', line 8

def ny
  @ny
end

#positionObject (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]

#boxObject



22
# File 'lib/sevgi/sundries/tile.rb', line 22

def box = @box ||= Geometry::Rect[nx * element.box.width, ny * element.box.height, position:]

#cellObject



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)]

#colsObject



28
# File 'lib/sevgi/sundries/tile.rb', line 28

def cols = @cols ||= rows.transpose

#eachObject Also known as: each_row



32
# File 'lib/sevgi/sundries/tile.rb', line 32

def each(...) = rows.each(...)

#each_colObject



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)]

#rowsObject



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)) } }