Class: DXF::SplineParser
- Inherits:
-
EntityParser
- Object
- EntityParser
- DXF::SplineParser
- Defined in:
- lib/dxf/parser.rb
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#degree ⇒ Object
readonly
Returns the value of attribute degree.
-
#knots ⇒ Object
readonly
Returns the value of attribute knots.
-
#linear ⇒ Object
readonly
Returns the value of attribute linear.
-
#periodic ⇒ Object
readonly
Returns the value of attribute periodic.
-
#planar ⇒ Object
readonly
Returns the value of attribute planar.
-
#points ⇒ Array
Points.
-
#rational ⇒ Object
readonly
Returns the value of attribute rational.
Attributes inherited from EntityParser
Instance Method Summary collapse
-
#initialize ⇒ SplineParser
constructor
A new instance of SplineParser.
- #parse_pair(code, value) ⇒ Object
- #to_entity ⇒ Object
Constructor Details
#initialize ⇒ SplineParser
Returns a new instance of SplineParser.
191 192 193 194 195 196 197 198 |
# File 'lib/dxf/parser.rb', line 191 def initialize super 'SPLINE' @fit_points = [] @knots = [] @weights = [] @fit_point_index = Hash.new {|h,k| h[k] = 0} end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
187 188 189 |
# File 'lib/dxf/parser.rb', line 187 def closed @closed end |
#degree ⇒ Object (readonly)
Returns the value of attribute degree.
188 189 190 |
# File 'lib/dxf/parser.rb', line 188 def degree @degree end |
#knots ⇒ Object (readonly)
Returns the value of attribute knots.
189 190 191 |
# File 'lib/dxf/parser.rb', line 189 def knots @knots end |
#linear ⇒ Object (readonly)
Returns the value of attribute linear.
187 188 189 |
# File 'lib/dxf/parser.rb', line 187 def linear @linear end |
#periodic ⇒ Object (readonly)
Returns the value of attribute periodic.
187 188 189 |
# File 'lib/dxf/parser.rb', line 187 def periodic @periodic end |
#planar ⇒ Object (readonly)
Returns the value of attribute planar.
187 188 189 |
# File 'lib/dxf/parser.rb', line 187 def planar @planar end |
#points ⇒ Array
Returns points.
185 186 187 |
# File 'lib/dxf/parser.rb', line 185 def points @points end |
#rational ⇒ Object (readonly)
Returns the value of attribute rational.
187 188 189 |
# File 'lib/dxf/parser.rb', line 187 def rational @rational end |
Instance Method Details
#parse_pair(code, value) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/dxf/parser.rb', line 200 def parse_pair(code, value) case code when 11, 21, 31 k = Parser.code_to_symbol(code) i = @fit_point_index[k] @fit_points[i] = Parser.update_point(@fit_points[i], k => value) @fit_point_index[k] += 1 when 12, 22, 32 then @start_tangent = update_point(@start_tangent, Parser.code_to_symbol(code) => value) when 13, 23, 33 then @end_tangent = update_point(@end_tangent, Parser.code_to_symbol(code) => value) when 40 then knots.push value.to_f when 41 then @weights.push value when 42 then @knot_tolerance = value when 43 then @control_tolerance = value when 44 then @fit_tolerance = value when 70 value = value.to_i @closed = value[0].zero? ? nil : true @periodic = value[1].zero? ? nil : true @rational = value[2].zero? ? nil : true @planar = value[3].zero? ? nil : true @linear = value[4].zero? ? nil : true when 71 then @degree = value when 72 then @num_knots = value when 73 then @num_control_points = value when 74 then @num_fit_points = value else super end end |
#to_entity ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/dxf/parser.rb', line 230 def to_entity raise ParseError, "Wrong number of control points" unless points.size == @num_control_points # If all of the points lie in the XY plane, remove the Z component from each point if planar && points.all? {|a| a.z.zero?} @points.map! {|a| Geometry::Point[a[0, 2]]} end if knots.size == 2*points.size # Bezier? if knots[0,points.size].all?(&:zero?) && (knots[-points.size,points.size].uniq.size==1) Bezier.new *points end else Spline.new degree:degree, knots:knots, points:points end end |