Class: VectorSalad::Canvas
- Inherits:
-
Object
- Object
- VectorSalad::Canvas
- Includes:
- Enumerable
- Defined in:
- lib/vector_salad/canvas.rb
Overview
All shapes must be added to the global canvas for export, and block transform shapes like StandardShapes::Union or StandardShapes::Move have an internal canvas that shapes must be added to.
In most cases you'll want to use the DSL which abstracts away the canvas so you don't have to think about it.
Instance Method Summary (collapse)
-
- (Object) <<(shape)
Add a shape to the canvas.
-
- (Object) [](i)
Access a specific shape in the canvas.
-
- (Object) each(&_)
Loop over the shapes in the canvas.
-
- (Canvas) initialize
constructor
A new instance of Canvas.
-
- (Object) length
Count of how many shapes are on the canvas.
Constructor Details
- (Canvas) initialize
Returns a new instance of Canvas
17 18 19 |
# File 'lib/vector_salad/canvas.rb', line 17 def initialize @canvas = [] end |
Instance Method Details
- (Object) <<(shape)
Add a shape to the canvas
22 23 24 |
# File 'lib/vector_salad/canvas.rb', line 22 def <<(shape) @canvas << shape end |
- (Object) [](i)
Access a specific shape in the canvas. Often used to get the first shape [0] for situations where only a single shape is allowed.
51 52 53 |
# File 'lib/vector_salad/canvas.rb', line 51 def [](i) to_shape @canvas[i] end |
- (Object) each(&_)
Loop over the shapes in the canvas.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vector_salad/canvas.rb', line 27 def each(&_) @canvas.each do |shape| shape = to_shape(shape) next if shape.class == VectorSalad::StandardShapes::Custom || !shape.is_a?(VectorSalad::StandardShapes::BasicShape) if shape.is_a?(VectorSalad::StandardShapes::Group) || (shape.is_a?(VectorSalad::StandardShapes::Custom) && shape.to_path.class == VectorSalad::StandardShapes::Group) shape.canvas.each { |s| yield(s) } else yield(shape) end end end |
- (Object) length
Count of how many shapes are on the canvas
44 45 46 |
# File 'lib/vector_salad/canvas.rb', line 44 def length @canvas.length end |