Class: RubyPost::Path
Overview
sequence of pairs connected as a metapost path
Direct Known Subclasses
Instance Attribute Summary collapse
-
#line_type ⇒ Object
writeonly
Sets the attribute line_type.
Instance Method Summary collapse
- #add_pair(p) ⇒ Object
-
#center(p) ⇒ Object
returns a pair that is the centroid of the pairs of this path.
- #clone ⇒ Object
- #compile ⇒ Object
-
#curved ⇒ Object
set the path to have curved line segments.
-
#initialize ⇒ Path
constructor
A new instance of Path.
-
#reverse ⇒ Object
reverse the path.
-
#straight ⇒ Object
set the path to have straight line segments.
Constructor Details
#initialize ⇒ Path
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
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 |
#clone ⇒ Object
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 |
#compile ⇒ Object
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 |
#curved ⇒ Object
set the path to have curved line segments
160 161 162 163 |
# File 'lib/drawable.rb', line 160 def curved @line_type = '..' self end |
#reverse ⇒ Object
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 |
#straight ⇒ Object
set the path to have straight line segments
154 155 156 157 |
# File 'lib/drawable.rb', line 154 def straight @line_type = '--' self end |