Class: VectorSalad::StandardShapes::MultiPath

Inherits:
BasicShape
  • Object
show all
Includes:
Mixins::Transforms
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)

Instance Method Summary (collapse)

Constructor Details

- (MultiPath) initialize(*paths, closed: true, **options)

See Path for details on constructing paths.

Examples:

new(
  Path.n([0,0], [0,300], [300,300], [300,0], [0,0]),
  Path.n([100,100], [200,100], [200,200], [100,200], [100,100])
)
new(
  [[0,0], [0,300], [300,300], [300,0], [0,0]],
  [[100,100], [200,100], [200,200], [100,200], [100,100]]
)

Parameters:

  • paths (Args[Or[Array, Path])
  • closed ([])
  • options ([])


28
29
30
31
32
33
34
35
36
37
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 28

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

- (Object) closed (readonly)

Returns the value of attribute closed



13
14
15
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 13

def closed
  @closed
end

- (Object) options Originally defined in class BasicShape

Returns the value of attribute options

- (Object) paths (readonly)

Returns the value of attribute paths



13
14
15
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 13

def paths
  @paths
end

Instance Method Details

- (Any) [](x, y) Originally defined in module Mixins::Transforms

Move the shape absolutely.

Parameters:

  • x (Num)
  • y (Num)

Returns:

  • (Any)

- (Any) move(x, y) Originally defined in module Mixins::Transforms

Move the shape relatively.

Parameters:

  • x (Num)
  • y (Num)

Returns:

  • (Any)

- (Any) rotate(angle) Originally defined in module Mixins::Transforms

Rotates the shape by the specified angle about the origin.

Parameters:

  • angle (Num)

Returns:

  • (Any)

- (Any) scale(multiplier) Originally defined in module Mixins::Transforms

Scale a shape by multiplier about the origin.

Parameters:

  • multiplier (Num)

Returns:

  • (Any)

- (Object) to_a

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



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

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

- (Object) to_bezier_path

Convert the complex paths in the MultiPath to bezier paths.



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

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

- (Object) to_cubic_path

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



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

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

- (Object) to_multi_path

Returns self



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

def to_multi_path
  self
end

- (Object) to_path

Convert the shape to a path



40
41
42
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 40

def to_path
  self
end

- (Object) to_simple_path

Convert the complex paths in the MultiPath to simple paths.



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

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

- (Object) to_svg

Export the shape to an svg string



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

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