Class: XRVG::InterBezier

Inherits:
Object
  • Object
show all
Includes:
Attributable, GeoVariety, Interpolation, Samplable
Defined in:
lib/geovariety.rb,
lib/interbezier.rb

Overview

InterBezier GeoVariety implementation

Principle

InterBezier defines a surface by the set of every possible curve sample from one interpolated curve to the other. Geodesic corresponds then to one interpolated result, and point to a point of this curve

Direct Known Subclasses

GradientBezier

Instance Method Summary collapse

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 included from Interpolation

#compute_simplebezier, #getcurve, #interpoltype, #linear, #samplelist, #simplebezier

Methods included from GeoVariety

#bezier

Constructor Details

#initialize(*args) ⇒ InterBezier

Returns a new instance of InterBezier.



10
11
12
13
# File 'lib/interbezier.rb', line 10

def initialize( *args )
  super( *args )
  self.init_interpolation_structures
end

Instance Method Details

#init_interpolation_structuresObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/interbezier.rb', line 15

def init_interpolation_structures
  beziers = []
  indexes = []
  @bezierlist.foreach do |index, bezier| 
    beziers.push( bezier )
    indexes.push( index )
  end

  lengthH = {}
  alllengths = []
  beziers.each do |bezier|
    lengths = bezier.piecelengths
    Trace("bezier lengths #{lengths.inspect}")
    lengthH[ bezier ] = lengths
    alllengths += lengths
  end
  alllengths = Float.sort_float_list( alllengths )
  Trace("alllengths #{alllengths.inspect}")
  
  newbezierlist = []
  beziers.each do |bezier|
    newpieces = []
    initlengths = lengthH[ bezier ]
    alllengths.pairs do |l1, l2| 
	newpieces += bezier.subbezier( l1, l2 ).pieces
    end
    newbezier = Bezier[ :pieces, newpieces ]
    newbezierlist << newbezier
  end

  Trace("newbezierlist #{newbezierlist.length}")
  beziers = newbezierlist
  bezierpointlists = beziers.map {|bezier| bezier.pointlist(:vector) }
  Trace("bezierpointlists #{bezierpointlists.map {|list| list.length}.inspect}")
  pointsequencelist = bezierpointlists.forzip
  @interpolatorlist = []
  pointsequencelist.foreach(beziers.size) do |pointsequence|
    interlist = [indexes, pointsequence].forzip
    @interpolatorlist.push( Interpolator.new( :samplelist, interlist ) )
  end
end

#interpolate(abs, container = nil) ⇒ Object Also known as: apply_sample



57
58
59
60
61
62
63
64
# File 'lib/interbezier.rb', line 57

def interpolate( abs, container=nil )
  pieces = []
  @interpolatorlist.foreach(4) do |interpiece|
    piece = interpiece.map {|inter| inter.interpolate( abs )}
    pieces.push( [:vector] + piece )
  end
  return Bezier.multi( pieces )    
end

#line(x1, x2, y) ⇒ Object

Compute the geodesic subcurve with y coord between x1 and x2



54
55
56
57
58
59
60
# File 'lib/geovariety.rb', line 54

def line( x1, x2, y )
  # Trace("interbezier line x1 #{x1} x2 #{x2} y #{y}")
  curve = self.sample( y )
  result = curve.apply_split( x1, x2 )
  # Trace("interbezier line result #{result.inspect}")
  return result
end

#point(point) ⇒ Object

Compute the geodesic curve by doing self.sample with y coord, and then compute point of this curve with length “x”



48
49
50
51
# File 'lib/geovariety.rb', line 48

def point( point )
  curve = self.sample( point.y )
  return curve.point( point.x )
end