Class: VectorSalad::StandardShapes::Clip
- Inherits:
-
BasicShape
- Object
- BasicShape
- VectorSalad::StandardShapes::Clip
- Includes:
- VectorSalad::StandardShapes
- Defined in:
- lib/vector_salad/standard_shapes/clip.rb
Overview
Perform a clipping operation on the contained paths or shapes. It's easier to use one of the subclasses; (see Difference, Intersection, Union, Exclusion).
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BasicShape
Instance Method Summary collapse
-
#canvas ⇒ Object
The canvas the clipping is done on.
-
#initialize(operation, **options, &block) ⇒ Clip
constructor
A new instance of Clip.
-
#to_path ⇒ Object
Convert the shape to a path.
Methods inherited from BasicShape
#flip, #flip_x, #flip_y, #jitter, #move, #rotate, #scale, #to_a, #to_bezier_path, #to_cubic_path, #to_multi_path, #to_simple_path, #to_svg
Constructor Details
#initialize(operation, **options, &block) ⇒ Clip
Returns a new instance of Clip.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vector_salad/standard_shapes/clip.rb', line 19 def initialize(operation, **, &block) instance_eval(&block) # canvas is populated clipper = Clipper::Clipper.new i = 0 canvas.each do |shape| method = i == 0 ? "subject" : "clip" path = shape.to_simple_path.to_a if path[0][0].instance_of? Array # MultiPath clipper.send("add_#{method}_polygons".to_sym, path) else # Path clipper.send("add_#{method}_polygon".to_sym, path) end i += 1 end @path = MultiPath.new( *clipper.send(operation, :non_zero, :non_zero), ** ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VectorSalad::DSL
Instance Method Details
#canvas ⇒ Object
The canvas the clipping is done on.
42 43 44 |
# File 'lib/vector_salad/standard_shapes/clip.rb', line 42 def canvas @canvas ||= VectorSalad::Canvas.new end |
#to_path ⇒ Object
Convert the shape to a path
47 48 49 |
# File 'lib/vector_salad/standard_shapes/clip.rb', line 47 def to_path @path end |