Class: Postsvg::Visitors::PsVisitor::PathState
- Inherits:
-
Object
- Object
- Postsvg::Visitors::PsVisitor::PathState
- Defined in:
- lib/postsvg/visitors/ps_visitor.rb
Overview
Path state: list of accumulated path commands and the current pen position. Kept as a separate inner class so the visitor body stays focused on dispatch + state mutations, not on path geometry bookkeeping.
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#current_x ⇒ Object
readonly
Returns the value of attribute current_x.
-
#current_y ⇒ Object
readonly
Returns the value of attribute current_y.
Instance Method Summary collapse
- #arc_to(rx, ry, x_axis_rotation, large_arc, sweep, x, y) ⇒ Object
- #close ⇒ Object
- #curve_to(x1, y1, x2, y2, x3, y3) ⇒ Object
- #curve_to_rel(dx1, dy1, dx2, dy2, dx3, dy3) ⇒ Object
- #empty? ⇒ Boolean
- #fmt(value) ⇒ Object
-
#initialize ⇒ PathState
constructor
A new instance of PathState.
- #line_to(x, y) ⇒ Object
- #line_to_rel(dx, dy) ⇒ Object
- #move_to(x, y) ⇒ Object
- #move_to_rel(dx, dy) ⇒ Object
- #reset ⇒ Object
- #to_path_d ⇒ Object
Constructor Details
#initialize ⇒ PathState
Returns a new instance of PathState.
120 121 122 123 124 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 120 def initialize @commands = [] @current_x = 0.0 @current_y = 0.0 end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
118 119 120 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 118 def commands @commands end |
#current_x ⇒ Object (readonly)
Returns the value of attribute current_x.
118 119 120 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 118 def current_x @current_x end |
#current_y ⇒ Object (readonly)
Returns the value of attribute current_y.
118 119 120 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 118 def current_y @current_y end |
Instance Method Details
#arc_to(rx, ry, x_axis_rotation, large_arc, sweep, x, y) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 166 def arc_to(rx, ry, x_axis_rotation, large_arc, sweep, x, y) @commands << "A #{fmt(rx)} #{fmt(ry)} #{fmt(x_axis_rotation)} " \ "#{large_arc ? 1 : 0} #{sweep ? 1 : 0} #{fmt(x)} #{fmt(y)}" @current_x = x.to_f @current_y = y.to_f end |
#close ⇒ Object
173 174 175 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 173 def close @commands << "Z" end |
#curve_to(x1, y1, x2, y2, x3, y3) ⇒ Object
154 155 156 157 158 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 154 def curve_to(x1, y1, x2, y2, x3, y3) @commands << "C #{fmt(x1)} #{fmt(y1)} #{fmt(x2)} #{fmt(y2)} #{fmt(x3)} #{fmt(y3)}" @current_x = x3.to_f @current_y = y3.to_f end |
#curve_to_rel(dx1, dy1, dx2, dy2, dx3, dy3) ⇒ Object
160 161 162 163 164 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 160 def curve_to_rel(dx1, dy1, dx2, dy2, dx3, dy3) @commands << "c #{fmt(dx1)} #{fmt(dy1)} #{fmt(dx2)} #{fmt(dy2)} #{fmt(dx3)} #{fmt(dy3)}" @current_x += dx3.to_f @current_y += dy3.to_f end |
#empty? ⇒ Boolean
126 127 128 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 126 def empty? @commands.empty? end |
#fmt(value) ⇒ Object
187 188 189 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 187 def fmt(value) FormatNumber.call(value) end |
#line_to(x, y) ⇒ Object
142 143 144 145 146 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 142 def line_to(x, y) @commands << "L #{fmt(x)} #{fmt(y)}" @current_x = x.to_f @current_y = y.to_f end |
#line_to_rel(dx, dy) ⇒ Object
148 149 150 151 152 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 148 def line_to_rel(dx, dy) @commands << "l #{fmt(dx)} #{fmt(dy)}" @current_x += dx.to_f @current_y += dy.to_f end |
#move_to(x, y) ⇒ Object
130 131 132 133 134 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 130 def move_to(x, y) @commands << "M #{fmt(x)} #{fmt(y)}" @current_x = x.to_f @current_y = y.to_f end |
#move_to_rel(dx, dy) ⇒ Object
136 137 138 139 140 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 136 def move_to_rel(dx, dy) @commands << "m #{fmt(dx)} #{fmt(dy)}" @current_x += dx.to_f @current_y += dy.to_f end |
#reset ⇒ Object
177 178 179 180 181 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 177 def reset @commands = [] @current_x = 0.0 @current_y = 0.0 end |
#to_path_d ⇒ Object
183 184 185 |
# File 'lib/postsvg/visitors/ps_visitor.rb', line 183 def to_path_d @commands.join(" ") end |