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.



71
72
73
74
75
# File 'lib/origami/graphics/path.rb', line 71

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

Instance Attribute Details

#current_pointObject

Returns the value of attribute current_point.



68
69
70
# File 'lib/origami/graphics/path.rb', line 68

def current_point
  @current_point
end

#segmentsObject (readonly)

Returns the value of attribute segments.



69
70
71
# File 'lib/origami/graphics/path.rb', line 69

def segments
  @segments
end

Instance Method Details

#add_segment(seg) ⇒ Object

Raises:



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

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

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

#close!Object



81
82
83
84
85
86
87
88
# File 'lib/origami/graphics/path.rb', line 81

def close!
  from = @current_point
  to = @segments.first.from

  @segments << Line.new(from, to)
  @segments.freeze
  @closed = true
end

#is_closed?Boolean

Returns:



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

def is_closed?
  @closed
end