Class: Sevgi::Sundries::Grid

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

Overview

Builds a tile-like grid from horizontal and vertical rulers.

Defined Under Namespace

Classes: Axis, X, Y

Instance Attribute Summary collapse

Attributes inherited from Tile

#element, #nx, #ny, #position

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tile

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

Constructor Details

#initialize(x:, y:) ⇒ void

Creates a grid from horizontal and vertical rulers.

Parameters:

Raises:

  • (Sevgi::ArgumentError)

    when either argument is not a ruler



27
28
29
30
31
32
33
34
# File 'lib/sevgi/sundries/grid.rb', line 27

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

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

  super(Geometry::Rect[@x.u, @y.u], nx: @x.n, ny: @y.n)
end

Instance Attribute Details

#xSevgi::Sundries::Grid::X (readonly)

Returns horizontal axis ruler and line queries.

Returns:



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

attr_reader :x, :y

Class Method Details

.[](x, y) ⇒ Sevgi::Sundries::Grid

Builds a grid using bracket syntax.

Parameters:

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when either argument is not a ruler



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

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

Instance Method Details

#canvasSevgi::Graphics::Canvas

Returns a graphics canvas matching the rulers and computed margins.

Returns:

  • (Sevgi::Graphics::Canvas)


38
39
40
41
42
43
# File 'lib/sevgi/sundries/grid.rb', line 38

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

#heightFloat

Returns the fitted grid height.

Returns:

  • (Float)


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

def height = y.d

#widthFloat

Returns the fitted grid width.

Returns:

  • (Float)


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

def width = x.d