Class: RubyPost::Path

Inherits:
Drawable show all
Defined in:
lib/drawable.rb

Overview

sequence of pairs connected as a metapost path

Direct Known Subclasses

Square

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePath

Returns a new instance of Path.



115
116
117
118
119
# File 'lib/drawable.rb', line 115

def initialize
  super()
  @p = Array.new
  straight
end

Instance Attribute Details

#line_type=(value) ⇒ Object (writeonly)

Sets the attribute line_type

Parameters:

  • value

    the value to set the attribute line_type to.



113
114
115
# File 'lib/drawable.rb', line 113

def line_type=(value)
  @line_type = value
end

Instance Method Details

#add_pair(p) ⇒ Object



121
122
123
124
# File 'lib/drawable.rb', line 121

def add_pair(p)
  @p.push(p)
  self
end

#center(p) ⇒ Object

returns a pair that is the centroid of the pairs of this path



128
129
130
131
132
# File 'lib/drawable.rb', line 128

def center(p)
  ret = Pair.new
  @p.each { |p| ret = ret + p }
  return ret/p.length
end

#cloneObject



163
164
165
166
167
168
# File 'lib/drawable.rb', line 163

def clone
  c = Path.new
  @p.each{ |i| c.add_pair(i) }
  c.line_type = @line_type
  c
end

#compileObject



155
156
157
158
159
160
161
# File 'lib/drawable.rb', line 155

def compile
  str = '('
  (@p.length-1).times do |i|
    str = str + @p[i].compile + @line_type
  end
  str + @p[-1].compile + ')'
end

#curvedObject

set the path to have curved line segments



150
151
152
153
# File 'lib/drawable.rb', line 150

def curved
  @line_type = '..'
  self
end

#reverseObject

reverse the path.
Note, this reverses the pairs that have so far been added. Anything added after calling reverse will be appended to the end of the array as usual



138
139
140
141
# File 'lib/drawable.rb', line 138

def reverse
  @p = @p.reverse
  self
end

#straightObject

set the path to have straight line segments



144
145
146
147
# File 'lib/drawable.rb', line 144

def straight
  @line_type = '--'
  self
end