Class: VectorSalad::StandardShapes::MultiPath
- Inherits:
-
BasicShape
- Object
- BasicShape
- VectorSalad::StandardShapes::MultiPath
- 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
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Attributes inherited from BasicShape
Instance Method Summary collapse
- #[](x, y) ⇒ Object
-
#initialize(*paths, closed: true, **options) ⇒ MultiPath
constructor
A new instance of MultiPath.
- #move(x, y) ⇒ Object
- #rotate(angle) ⇒ Object
- #scale(multiplier) ⇒ Object
-
#to_a ⇒ Object
Return an array of paths that are and array of node coordinates.
-
#to_bezier_path ⇒ Object
Convert the complex paths in the MultiPath to bezier paths.
-
#to_cubic_path ⇒ Object
Convert the complex paths in the MultiPath to cubic bezier paths only.
-
#to_multi_path ⇒ Object
Returns self.
-
#to_path ⇒ Object
Convert the shape to a path.
-
#to_simple_path ⇒ Object
Convert the complex paths in the MultiPath to simple paths.
-
#to_svg ⇒ Object
Export the shape to an svg string.
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, **) paths.each do |path| path = path.instance_of?(Array) ? Path.new(*path) : path @paths = Array(@paths) << path end @closed = closed = self end |
Instance Attribute Details
#closed ⇒ Object (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 |
#paths ⇒ Object (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_a ⇒ Object
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_path ⇒ Object
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), **) end |
#to_cubic_path ⇒ Object
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), **) end |
#to_multi_path ⇒ Object
Returns self
81 82 83 |
# File 'lib/vector_salad/standard_shapes/multi_path.rb', line 81 def to_multi_path self end |
#to_path ⇒ Object
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_path ⇒ Object
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), **) end |
#to_svg ⇒ Object
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.() svg << "/>" end |