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.


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

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

Instance Attribute Details

#current_pointObject

Returns the value of attribute current_point


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

def current_point
  @current_point
end

#segmentsObject (readonly)

Returns the value of attribute segments


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

def segments
  @segments
end

Instance Method Details

#add_segment(seg) ⇒ Object

Raises:


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

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

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

#close!Object


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

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

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

#is_closed?Boolean

Returns:


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

def is_closed?
    @closed
end