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.



125
126
127
128
129
# File 'lib/drawable.rb', line 125

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.



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

def line_type=(value)
  @line_type = value
end

Instance Method Details

#add_pair(p) ⇒ Object



131
132
133
134
# File 'lib/drawable.rb', line 131

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



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

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

#cloneObject



173
174
175
176
177
178
# File 'lib/drawable.rb', line 173

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

#compileObject



165
166
167
168
169
170
171
# File 'lib/drawable.rb', line 165

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



160
161
162
163
# File 'lib/drawable.rb', line 160

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



148
149
150
151
# File 'lib/drawable.rb', line 148

def reverse
  @p = @p.reverse
  self
end

#straightObject

set the path to have straight line segments



154
155
156
157
# File 'lib/drawable.rb', line 154

def straight
  @line_type = '--'
  self
end