Class: Origami::Graphics::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/graphics/path.rb

Defined Under Namespace

Modules: Segment Classes: Line

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePath

Returns a new instance of Path.



77
78
79
80
81
# File 'lib/origami/graphics/path.rb', line 77

def initialize
  @segments = []
  @current_point = nil
  @closed = false
end

Instance Attribute Details

#current_pointObject

Returns the value of attribute current_point.



74
75
76
# File 'lib/origami/graphics/path.rb', line 74

def current_point
  @current_point
end

#segmentsObject (readonly)

Returns the value of attribute segments.



75
76
77
# File 'lib/origami/graphics/path.rb', line 75

def segments
  @segments
end

Instance Method Details

#add_segment(seg) ⇒ Object

Raises:



96
97
98
99
100
101
# File 'lib/origami/graphics/path.rb', line 96

def add_segment(seg)
  raise GraphicsStateError, "Cannot modify closed subpath" if is_closed?

  @segments << seg
  @current_point = seg.to
end

#close!Object



87
88
89
90
91
92
93
94
# File 'lib/origami/graphics/path.rb', line 87

def close!
  from = @current_point
  to = @segments.first.from
  
  @segments << Line.new(from, to)
  @segments.freeze
  @closed = true
end

#is_closed?Boolean

Returns:



83
84
85
# File 'lib/origami/graphics/path.rb', line 83

def is_closed?
  @closed
end