Class: VectorBeWinding::Path

Inherits:
Shape
  • Object
show all
Includes:
SpatialTree
Defined in:
lib/vector_be_winding/path.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SpatialTree

#children, #depth, #dump, #each, #insert_to_tree

Methods inherited from Shape

#containingness, #contains?, #intersectedness, #intersects?

Constructor Details

#initialize(sub_paths, is_tree = false) ⇒ Path

Returns a new instance of Path.



16
17
18
19
20
21
22
23
24
25
# File 'lib/vector_be_winding/path.rb', line 16

def initialize(sub_paths, is_tree = false)
  if is_tree
    @children = sub_paths
    @sub_paths = []
    children.each {|root| root.each { |subpath| @sub_paths << subpath }}
  else
    @sub_paths = sub_paths
    sub_paths.each {|p| insert_to_tree(p)}
  end
end

Instance Attribute Details

#sub_pathsObject (readonly)

Returns the value of attribute sub_paths.



5
6
7
# File 'lib/vector_be_winding/path.rb', line 5

def sub_paths
  @sub_paths
end

Class Method Details

.with_string(path_string) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/vector_be_winding/path.rb', line 7

def self.with_string(path_string)
  begin
    svg_path = Savage::Parser.parse(path_string)
  rescue => e
    raise ArgumentError, "Possibly wrong path string \"#{path_string}\""
  end
  Path.new(svg_path.subpaths.map { |svg_subpath| SubPath.with_svg(svg_subpath) })
end

Instance Method Details

#areaObject



31
32
33
# File 'lib/vector_be_winding/path.rb', line 31

def area
  sub_paths.map(&:area).reduce(:+)
end

#be_windingObject



43
44
45
46
# File 'lib/vector_be_winding/path.rb', line 43

def be_winding()
  wounds = children.map(&:be_winding)
  Path.new(wounds, true)
end

#bounding_rectObject



27
28
29
# File 'lib/vector_be_winding/path.rb', line 27

def bounding_rect
  @bounding_rect ||= @sub_paths.map(&:bounding_rect).reduce(:|)
end

#inspectObject



35
36
37
# File 'lib/vector_be_winding/path.rb', line 35

def inspect
  "#<Path>"
end

#is_winding(sign = 1) ⇒ Object



39
40
41
# File 'lib/vector_be_winding/path.rb', line 39

def is_winding(sign = 1)
  children.all? { |c| c.is_winding }
end

#to_commandObject



48
49
50
# File 'lib/vector_be_winding/path.rb', line 48

def to_command
  sub_paths.map(&:to_command).join
end