Class: Rubyvis::SvgScene::PathBasis

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyvis/scene/svg_curve.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p0, p1, p2, p3) ⇒ PathBasis

Returns a new instance of PathBasis.



3
4
5
6
7
8
# File 'lib/rubyvis/scene/svg_curve.rb', line 3

def initialize(p0,p1,p2,p3)
  @p0=p0
  @p1=p1
  @p2=p2
  @p3=p3
end

Instance Attribute Details

#p0 ⇒ Object

Returns the value of attribute p0.



9
10
11
# File 'lib/rubyvis/scene/svg_curve.rb', line 9

def p0
  @p0
end

#p1 ⇒ Object

Returns the value of attribute p1.



9
10
11
# File 'lib/rubyvis/scene/svg_curve.rb', line 9

def p1
  @p1
end

#p2 ⇒ Object

Returns the value of attribute p2.



9
10
11
# File 'lib/rubyvis/scene/svg_curve.rb', line 9

def p2
  @p2
end

#p3 ⇒ Object

Returns the value of attribute p3.



9
10
11
# File 'lib/rubyvis/scene/svg_curve.rb', line 9

def p3
  @p3
end

Instance Method Details

#basis ⇒ Object

Matrix to transform basis (b-spline) control points to bezier control points. Derived from FvD 11.2.8.



16
17
18
19
20
21
22
23
# File 'lib/rubyvis/scene/svg_curve.rb', line 16

def basis
  [
  [ 1/6.0, 2/3.0, 1/6.0,   0 ],
  [   0, 2/3.0, 1/3.0,   0 ],
  [   0, 1/3.0, 2/3.0,   0 ],
  [   0, 1/6.0, 2/3.0, 1/6.0 ]
  ]
end

#convert ⇒ Object



33
34
35
36
37
38
# File 'lib/rubyvis/scene/svg_curve.rb', line 33

def convert
  b1 = weight(basis[1])
  b2 = weight(basis[2])
  b3 = weight(basis[3])
  "C#{b1.x},#{b1.y},#{b2.x},#{b2.y },#{b3.x},#{b3.y}"
end

#segment ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rubyvis/scene/svg_curve.rb', line 42

def segment
  b0 = weight(basis[0])
  b1 = weight(basis[1])
  b2 = weight(basis[2])
  b3 = weight(basis[3])
  "M#{b0.x},#{b0.y}C#{b1.x},#{b1.y},#{b2.x},#{b2.y},#{b3.x},#{b3.y}"
end

#to_s ⇒ Object



39
40
41
# File 'lib/rubyvis/scene/svg_curve.rb', line 39

def to_s
  convert
end

#weight(w) ⇒ Object

Returns the point that is the weighted sum of the specified control points, using the specified weights. This method requires that there are four weights and four control points.



27
28
29
30
31
32
# File 'lib/rubyvis/scene/svg_curve.rb', line 27

def weight(w)
  OpenStruct.new({
  :x=> w[0] * p0.left + w[1] * p1.left + w[2] * p2.left + w[3] * p3.left,
  :y=> w[0] * p0.top  + w[1] * p1.top  + w[2] * p2.top  + w[3] * p3.top
  })
end