Class: Sevgi::Sundries::Grid
Overview
Builds a tile-like grid from horizontal and vertical rulers.
Axis names describe line direction, not the coordinate used to place a
line: grid.x produces horizontal lines whose y positions come from the
vertical ruler; grid.y produces vertical lines whose x positions come
from the horizontal ruler. Each query can return geometry lines, Point
endpoint pairs, or plain coordinate pairs for different consumers.
Defined Under Namespace
Instance Attribute Summary collapse
-
#x ⇒ Sevgi::Sundries::Grid::X
readonly
Returns the horizontal-line axis and its ruler queries.
-
#y ⇒ Sevgi::Sundries::Grid::Y
readonly
Returns the vertical-line axis and its ruler queries.
Attributes inherited from Tile
Class Method Summary collapse
-
.[](x, y) ⇒ Sevgi::Sundries::Grid
Builds a grid using bracket syntax.
Instance Method Summary collapse
-
#canvas ⇒ Sevgi::Graphics::Canvas
Returns a graphics canvas matching the ruler spans and fitted margins.
-
#height ⇒ Float
Returns the fitted grid height.
-
#initialize(x:, y:, canvas: nil) ⇒ void
constructor
Creates a grid from horizontal and vertical rulers.
-
#width ⇒ Float
Returns the fitted grid width.
Methods inherited from Tile
#[], #box, #cell, #col, #colbox, #cols, #each, #each_col, #row, #rowbox, #rows
Constructor Details
#initialize(x:, y:, canvas: nil) ⇒ void
Creates a grid from horizontal and vertical rulers.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sevgi/sundries/grid.rb', line 62 def initialize(x:, y:, canvas: nil) validate_axes(x, y) validate_canvas(canvas, x, y) @source = canvas @x = X.send(:new, x, y) @y = Y.send(:new, x, y) super(Geometry::Rect[@x.u, @y.u], nx: @x.n, ny: @y.n) end |
Instance Attribute Details
#x ⇒ Sevgi::Sundries::Grid::X (readonly)
Returns the horizontal-line axis and its ruler queries. Line positions are supplied by the vertical ruler.
47 48 49 |
# File 'lib/sevgi/sundries/grid.rb', line 47 def x @x end |
#y ⇒ Sevgi::Sundries::Grid::Y (readonly)
Returns the vertical-line axis and its ruler queries. Line positions are supplied by the horizontal ruler.
52 53 54 |
# File 'lib/sevgi/sundries/grid.rb', line 52 def y @y end |
Class Method Details
.[](x, y) ⇒ Sevgi::Sundries::Grid
Builds a grid using bracket syntax.
42 |
# File 'lib/sevgi/sundries/grid.rb', line 42 def self.[](x, y) = new(x:, y:) |
Instance Method Details
#canvas ⇒ Sevgi::Graphics::Canvas
Returns a graphics canvas matching the ruler spans and fitted margins. Horizontal ruler margins become the canvas left/right margins; vertical ruler margins become its top/bottom margins.
86 87 88 89 90 91 92 93 94 |
# File 'lib/sevgi/sundries/grid.rb', line 86 def canvas margins = [y.start, x.finish, y.finish, x.start] return @source.with(margins:) if @source Graphics::Canvas.new( **Graphics::Paper[x.brut, y.brut].to_h, margins: ) end |
#height ⇒ Float
Returns the fitted grid height.
98 |
# File 'lib/sevgi/sundries/grid.rb', line 98 def height = y.d |
#width ⇒ Float
Returns the fitted grid width.
102 |
# File 'lib/sevgi/sundries/grid.rb', line 102 def width = x.d |