Class: XRVG::Line
Overview
Instance Method Summary collapse
-
#acc(abscissa, container = nil) ⇒ Object
acc V2D.O.
-
#init_tangents ⇒ Object
:nodoc:.
-
#initialize(*args) ⇒ Line
constructor
:nodoc:.
-
#length ⇒ Object
return the total length of the polyline.
-
#point(abscissa, container = nil) ⇒ Object
(also: #apply_sample)
compute line point at abscissa Line[ :points, [V2D::O, V2D::X] ].point( 0.3 ) => V2D.
-
#points(arg = nil) ⇒ Object
redefining to discriminate between @points and map.point.
-
#reverse ⇒ Object
reverse a line.
-
#svg ⇒ Object
return line svg description.
-
#tangent(abscissa, container = nil) ⇒ Object
compute line tangent at abscissa.
-
#translate(v) ⇒ Object
translate a line of v offset, v being a vector.
-
#viewbox ⇒ Object
compute viewbox of the line.
Methods included from Samplable
#apply_samples, build, #mean, #sample, #samples
Methods included from FloatFunctor
#addfilter, #alternate, #apply, #applyhash, #compute, #filter, #generate, #geo, #geofull, #modify, #process, #random, #shuffle, #sin, #ssort, #transform, #transforms, #trigger
Methods inherited from Curve
#acc_normal, #curvature, #default_style, #frame, #frames, #framev, #normal, #normals, #rotation, #scale, #tangent0, #tangent0_angle, #tangent0_length, #tangents
Methods inherited from Shape
#contour, #default_style, #size, #surface
Constructor Details
#initialize(*args) ⇒ Line
:nodoc:
228 229 230 231 |
# File 'lib/shape.rb', line 228 def initialize (*args) #:nodoc: super( *args ) self.init_tangents end |
Instance Method Details
#acc(abscissa, container = nil) ⇒ Object
acc V2D.O
286 287 288 289 290 |
# File 'lib/shape.rb', line 286 def acc( abscissa, container=nil ) container ||= V2D[] container.xy = [0.0,0.0] return container end |
#init_tangents ⇒ Object
:nodoc:
233 234 235 236 237 238 239 240 |
# File 'lib/shape.rb', line 233 def init_tangents #:nodoc: index = 0 @tangents = Array.new @points.pairs { |p1, p2| @tangents[ index ] = (p2-p1).norm index += 1 } end |
#length ⇒ Object
return the total length of the polyline
243 244 245 246 247 248 249 250 251 |
# File 'lib/shape.rb', line 243 def length if not @length @length = 0.0 @points.pairs do |p1, p2| @length += (p1 - p2).r end end return @length end |
#point(abscissa, container = nil) ⇒ Object Also known as: apply_sample
255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/shape.rb', line 255 def point (abscissa, container=nil) container ||= V2D[] piece1 = abscissa.to_int if piece1 == @points.size - 1 container.xy = @points[-1] else abscissa -= piece1 cpoints = @points.slice( piece1, 2 ) container.xy = [(cpoints[0].x..cpoints[1].x).sample( abscissa ), (cpoints[0].y..cpoints[1].y).sample( abscissa )] end return container end |
#points(arg = nil) ⇒ Object
redefining to discriminate between @points and map.point
270 271 272 273 274 275 276 |
# File 'lib/shape.rb', line 270 def points(arg=nil) if not arg return @points else super(arg) end end |
#reverse ⇒ Object
reverse a line
return a new line with :points reversed
309 310 311 |
# File 'lib/shape.rb', line 309 def reverse return Line[ :points, @points.reverse ] end |
#svg ⇒ Object
return line svg description
314 315 316 317 318 319 320 |
# File 'lib/shape.rb', line 314 def svg path = "M #{points[0].x} #{points[0].y} " @points[1..-1].each { |p| path += "L #{p.x} #{p.y}" } return "<path d=\"" + path + "\"/>" end |
#tangent(abscissa, container = nil) ⇒ Object
compute line tangent at abscissa
279 280 281 282 283 |
# File 'lib/shape.rb', line 279 def tangent (abscissa, container=nil) container ||= V2D[] container.xy = @tangents[abscissa.to_int] return container end |
#translate(v) ⇒ Object
translate a line of v offset, v being a vector
return a new line with every point of :points translated
302 303 304 |
# File 'lib/shape.rb', line 302 def translate( v ) return Line[ :points, @points.map {|ext| ext + v } ] end |