Class: VectorSalad::StandardShapes::MultiPath

Inherits:
BasicShape
  • Object
show all
Defined in:
lib/vector_salad/standard_shapes/multi_path.rb,
lib/vector_salad/exporters/svg_exporter.rb

Overview

MultiPath shape is a collection of Paths. It is mainly to store the result of Clip operations.

Instance Attribute Summary collapse

Attributes inherited from BasicShape

#options

Instance Method Summary collapse

Methods inherited from BasicShape

#flip, #flip_x, #flip_y, #jitter

Constructor Details

#initialize(*paths, closed: true, **options) ⇒ MultiPath

Returns a new instance of MultiPath.



25
26
27
28
29
30
31
32
33
34
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 25

def initialize(*paths, closed: true, **options)
  paths.each do |path|
    path = path.instance_of?(Array) ? Path.new(*path) : path
    @paths = Array(@paths) << path
  end

  @closed = closed
  @options = options
  self
end

Instance Attribute Details

#closedObject (readonly)

Returns the value of attribute closed.



10
11
12
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 10

def closed
  @closed
end

#pathsObject (readonly)

Returns the value of attribute paths.



10
11
12
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 10

def paths
  @paths
end

Instance Method Details

#[](x, y) ⇒ Object



38
39
40
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 38

def [](x, y)
  each_send(:[], x, y)
end

#move(x, y) ⇒ Object



44
45
46
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 44

def move(x, y)
  each_send(:move, x, y)
end

#rotate(angle) ⇒ Object



50
51
52
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 50

def rotate(angle)
  each_send(:rotate, angle)
end

#scale(multiplier) ⇒ Object



56
57
58
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 56

def scale(multiplier)
  each_send(:scale, multiplier)
end

#to_aObject

Return an array of paths that are and array of node coordinates.



86
87
88
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 86

def to_a
  @paths.map(&:to_a)
end

#to_bezier_pathObject

Convert the complex paths in the MultiPath to bezier paths.



66
67
68
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 66

def to_bezier_path
  self.class.new(*@paths.map(&:to_bezier_path), **@options)
end

#to_cubic_pathObject

Convert the complex paths in the MultiPath to cubic bezier paths only.



71
72
73
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 71

def to_cubic_path
  self.class.new(*@paths.map(&:to_cubic_path), **@options)
end

#to_multi_pathObject

Returns self



81
82
83
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 81

def to_multi_path
  self
end

#to_pathObject

Convert the shape to a path



61
62
63
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 61

def to_path
  self
end

#to_simple_pathObject

Convert the complex paths in the MultiPath to simple paths.



76
77
78
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 76

def to_simple_path
  self.class.new(*@paths.map(&:to_simple_path), **@options)
end

#to_svgObject

Export the shape to an svg string



90
91
92
93
94
95
96
97
98
# File 'lib/vector_salad/exporters/svg_exporter.rb', line 90

def to_svg
  svg = '<path d="'
  paths.each do |path|
    svg << " #{path.to_svg_d_attribute}"
  end
  svg << '"'
  svg << VectorSalad::Exporters::SvgExporter.options(@options)
  svg << "/>"
end