Class: Sevgi::Geometry::Grid

Inherits:
Tile show all
Defined in:
lib/sevgi/geometry/sundries/grid.rb

Defined Under Namespace

Classes: Axis, X, Y

Instance Attribute Summary collapse

Attributes inherited from Tile

#element, #nx, #ny

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tile

#[], #box, #cell, #col, #colbox, #cols, #each, #each_col, #row, #rowbox, #rows

Methods inherited from Element

#at, #bh, #box, #bw, #ignorable?, #position, #position!, #translate

Constructor Details

#initialize(x:, y:) ⇒ Grid

Returns a new instance of Grid.



11
12
13
14
15
16
17
18
# File 'lib/sevgi/geometry/sundries/grid.rb', line 11

def initialize(x:, y:)
  ArgumentError.("Arguments must be Ruler objects") unless [ x, y ].all? { _1.is_a?(Ruler) }

  @x = X.new(x, y)
  @y = Y.new(x, y)

  super(Rect.new(width: @x.u, height: @y.u), nx: @x.n, ny: @y.n)
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



9
10
11
# File 'lib/sevgi/geometry/sundries/grid.rb', line 9

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



9
10
11
# File 'lib/sevgi/geometry/sundries/grid.rb', line 9

def y
  @y
end

Class Method Details

.[](x, y) ⇒ Object



75
# File 'lib/sevgi/geometry/sundries/grid.rb', line 75

def [](x, y) = new(x:, y:)

Instance Method Details

#canvasObject



20
# File 'lib/sevgi/geometry/sundries/grid.rb', line 20

def canvas = Graphics::Canvas.new(**Dim[x.brut, y.brut].to_h, margins: Margin[y.margin, x.margin].to_a)

#heightObject



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

def height = y.d

#widthObject



24
# File 'lib/sevgi/geometry/sundries/grid.rb', line 24

def width  = x.d