Class: XRVG::Curve

Inherits:
Shape show all
Defined in:
lib/shape.rb

Overview

Curve abstract interface

Intro

To define a set of services a curve class must provide

Direct Known Subclasses

Bezier, Circle, GSpiral, Line

Instance Method Summary collapse

Methods inherited from Shape

#contour, #size, #surface, #svg, #viewbox

Methods included from Attributable

included, #initialize

Instance Method Details

#acc(abscissa, container = nil) ⇒ Object

must compute the acceleration at curve abscissa

abstract

must be defined

Raises:

  • (NotImplementedError)


96
97
98
# File 'lib/shape.rb', line 96

def acc( abscissa, container=nil )
  raise NotImplementedError.new("#{self.class.name}#acc is an abstract method.")
end

#acc_normal(t) ⇒ Object

compute normal acceleration at abscissa t



178
179
180
181
182
# File 'lib/shape.rb', line 178

def acc_normal( t )
  normal = self.normal( t ).norm
  result = self.acc( t ).inner_product( normal )
  return result
end

#curvature(t) ⇒ Object

compute curvature at abscissa t



185
186
187
188
189
190
191
# File 'lib/shape.rb', line 185

def curvature( t )
  acc_normal = self.acc_normal( t )
  if acc_normal == 0.0
    return 0.0
  end
  return 1.0 / (self.tangent( t ).r / acc_normal )
end

#default_styleObject

default style of a curve, as stroked with stroke width 1% of length



110
111
112
# File 'lib/shape.rb', line 110

def default_style
  return Style[ :stroke, Color.black, :strokewidth, self.length / 100.0 ]
end

#frame(t) ⇒ Object

compute frame at abscissa t



165
166
167
168
# File 'lib/shape.rb', line 165

def frame( t )
  point, tangent = self.framev( t )
  return Frame[ :center, point, :vector, tangent, :rotation, self.rotation( nil, tangent ), :scale, self.scale( nil, tangent ) ]
end

#frames(abscissas) ⇒ Object

shortcut method to map frames from abscissas



194
195
196
# File 'lib/shape.rb', line 194

def frames (abscissas)
  return abscissas.map { |abscissa| self.frame( abscissa ) }
end

#framev(t) ⇒ Object

compute frame vector at abscissa t, that is [curve.point( t ), curve.tangent( t ) ]



160
161
162
# File 'lib/shape.rb', line 160

def framev( t )
  return [self.point( t ), self.tangent( t ) ]
end

#length(abscissa = nil) ⇒ Object

must return the length at abscissa, or total length if abscissa nil

abstract

must be defined

Raises:

  • (NotImplementedError)


105
106
107
# File 'lib/shape.rb', line 105

def length(abscissa=nil)
  raise NotImplementedError.new("#{self.class.name}#length is an abstract method.")
end

#normal(t) ⇒ Object

compute normal at abscissa t

do tangent.ortho



173
174
175
# File 'lib/shape.rb', line 173

def normal( t )
  return self.tangent( t ).ortho
end

#normals(indexes) ⇒ Object

shortcut method, map of normal



210
211
212
# File 'lib/shape.rb', line 210

def normals( indexes )
  return indexes.map {|i| self.normal( i )}
end

#point(abscissa, container = nil) ⇒ Object

must compute the point at curve abscissa

abstract

must be defined

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/shape.rb', line 78

def point( abscissa, container=nil )
  raise NotImplementedError.new("#{self.class.name}#curve is an abstract method.")
end

#points(abscissas) ⇒ Object

shortcut method to map points from abscissas



199
200
201
202
# File 'lib/shape.rb', line 199

def points (abscissas)
  result = abscissas.map { |abscissa| self.point( abscissa ) }
  return result
end

#rotation(abscissa, tangent = nil) ⇒ Object

compute the rotation at curve abscissa, or directly from tangent (for frame computation speed up), as angle between tangent0 angle and tangent( abscissa ) (or tangent) angle



116
117
118
119
120
121
# File 'lib/shape.rb', line 116

def rotation( abscissa, tangent=nil )
  if not tangent
    tangent = self.tangent( abscissa )
  end
  return (tangent.angle - self.tangent0_angle)
end

#scale(abscissa, tangent = nil) ⇒ Object

must compute the scale at curve abscissa, or directly from tangent (for frame computation speed up) as ratio between tangent0 size and tangent( abscissa ) (or tangent) size



125
126
127
128
129
130
131
132
133
134
# File 'lib/shape.rb', line 125

def scale( abscissa, tangent=nil )
  if not tangent
    tangent = self.tangent( abscissa )
  end
  result = 0.0
  if not self.tangent0_length == 0.0
    result = (tangent.r / self.tangent0_length)
  end
  return result
end

#tangent(abscissa, container = nil) ⇒ Object

must compute the tangent at curve abscissa

abstract

must be defined

Raises:

  • (NotImplementedError)


87
88
89
# File 'lib/shape.rb', line 87

def tangent( abscissa, container=nil )
  raise NotImplementedError.new("#{self.class.name}#tangent is an abstract method.")
end

#tangent0Object



136
137
138
139
140
141
# File 'lib/shape.rb', line 136

def tangent0
  if not @tangent0
    @tangent0 = self.tangent( 0.0 )
  end
  return @tangent0
end

#tangent0_angleObject

TODO : must be cached in vector



144
145
146
147
148
149
# File 'lib/shape.rb', line 144

def tangent0_angle
  if not @tangent0_angle
    @tangent0_angle = self.tangent0.angle
  end
  return @tangent0_angle
end

#tangent0_lengthObject

TODO : must be cached in vector



152
153
154
155
156
157
# File 'lib/shape.rb', line 152

def tangent0_length
  if not @tangent0_length
    @tangent0_length = self.tangent0.r
  end
  return @tangent0_length
end

#tangents(abscissas) ⇒ Object

shortcut method to map tangents from abscissas



205
206
207
# File 'lib/shape.rb', line 205

def tangents (abscissas)
  return abscissas.map { |abscissa| self.tangent( abscissa ) }
end