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.
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
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 |
#clone ⇒ Object
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 |
#compile ⇒ Object
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 |
#curved ⇒ Object
set the path to have curved line segments
150 151 152 153 |
# File 'lib/drawable.rb', line 150 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
138 139 140 141 |
# File 'lib/drawable.rb', line 138 def reverse @p = @p.reverse self end |
#straight ⇒ Object
set the path to have straight line segments
144 145 146 147 |
# File 'lib/drawable.rb', line 144 def straight @line_type = '--' self end |