xrvg 0.0.8 → 0.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,6 +1,12 @@
1
1
  = CHANGES
2
2
 
3
- == 0.0.8 (2008.08.26)
3
+ == 0.0.81 (2008.08.26)
4
+ === Content
5
+ - tutorials updated with the new SyncS
6
+ - spiral class considered as curve, to redefine point and tangent computation, and to provide access to parameters
7
+ - debug unitary tests
8
+
9
+ == 0.0.8 (2008.08.25)
4
10
  === Content
5
11
  - unitary tests completion
6
12
  - new spiral builder from tangent (spiral refactoring to be committed soon...)
data/Rakefile CHANGED
@@ -212,6 +212,7 @@ task "gen-website" do
212
212
  Rake::Task["muse"].invoke
213
213
  Rake::Task["examples"].invoke
214
214
  Rake::Task["rdoc"].invoke
215
+ Rake::Task["coverage"].invoke
215
216
  Rake::Task["finish"].invoke
216
217
  end
217
218
 
@@ -292,6 +293,17 @@ task "muse" do
292
293
  sh "emacs -u \"\" g:/emacs/emacs/plans/xrvgwebsite.muse -l g:/emacs/emacs/perso/xrvg-publish-exe.el -kill", :verbose => true
293
294
  end
294
295
 
296
+ #---
297
+ # The "coverage" task generates html coverage testing
298
+ desc "Do test coverage, and copy it into web directory for uploading"
299
+ task "coverage" do
300
+ system %{rcov test_*.rb}
301
+ remove_dir "#{WEBSITE_DIR}/coverage"
302
+ mkdir "#{WEBSITE_DIR}/coverage"
303
+ FileList["coverage/*.html"].to_a.each {|fn| cp( fn, "#{WEBSITE_DIR}/coverage" ) }
304
+ end
305
+
306
+
295
307
  #---
296
308
  # The "finish" task removes some generated files
297
309
  task "finish" do
@@ -33,6 +33,7 @@ module ParametricLength
33
33
  previous = nil
34
34
  self.parameter_range.samples( ParametricLength::NSAMPLES ) do |abs|
35
35
  self.pointfromparameter( abs, new )
36
+ # Trace("compute_length_interpolator: abs #{abs} point #{new.inspect}")
36
37
  if previous
37
38
  sum+= (new - previous).r
38
39
  samplelist += [sum, abs]
@@ -44,6 +45,7 @@ module ParametricLength
44
45
  end
45
46
  @length = samplelist[-2]
46
47
 
48
+ # Trace("compute_length_interpolator: samplelist #{samplelist.inspect}")
47
49
  length_interpolator = nil
48
50
  if @length == 0.0
49
51
  newsamplelist = [0.0,0.0,0.0,1.0]
@@ -82,6 +84,7 @@ module ParametricLength
82
84
 
83
85
  def parameterfromlength( lvalue ) #:nodoc:
84
86
  result = self.length_interpolator.interpolate( lvalue )
87
+ # Trace("parameterfromlength lvalue #{lvalue} result #{result}")
85
88
  return result
86
89
  end
87
90
  end
data/lib/samplation.rb CHANGED
@@ -201,6 +201,15 @@ module Samplable
201
201
  return self.apply( self.modify( [abs], type ), type ).pop
202
202
  end
203
203
 
204
+ def rand(nsamples=1,&block)#:nodoc:
205
+ self.random()
206
+ if nsamples == 1
207
+ return sample( 0.0 )
208
+ else
209
+ return samples( nsamples, &block )
210
+ end
211
+ end
212
+
204
213
  # alias for sample( 0.5 )
205
214
  def mean()
206
215
  return self.sample( 0.5 )
@@ -504,7 +513,7 @@ class ShuffleFilter < Filter
504
513
  end
505
514
 
506
515
  def transforms( inputs, type ) #:nodoc:
507
- return inputs.sort_by { rand }
516
+ return inputs.shuffle
508
517
  end
509
518
  end
510
519
 
@@ -549,11 +558,6 @@ class Roller
549
558
  return result
550
559
  end
551
560
 
552
- # TODO : must be generalized
553
- def rand() #:nodoc:
554
- return @items.choice
555
- end
556
-
557
561
  def next()
558
562
  return transform( 0.0 )
559
563
  end
data/lib/spiral.rb CHANGED
@@ -10,39 +10,111 @@ module XRVG
10
10
  # abstract class to define spiral types
11
11
  #
12
12
  # use compute_radius to compute nsamples reference points, before interpolating with SimpleBezier
13
- class GSpiral < BezierBuilder
13
+ class GSpiral < Curve
14
+ extend Forwardable
15
+
14
16
  attribute :center, V2D::O, V2D
15
17
  attribute :ext, V2D::O + V2D::X, V2D
16
18
  attribute :curvature, 1.0
17
19
  attribute :nsamples, 100
18
20
  attribute :sens, 1.0
21
+
22
+ attr_accessor :angle0, :r0, :maxangle
23
+
24
+ # setup prefered interface, enq() and deq()...
25
+ # def_delegator :@q, :push, :enq
26
+
27
+ # delegate interfaces unknown for spiral to bezier
28
+ # :length is computed by ParametricLength
29
+ def_delegators :bezier, :contour, :svg, :viewbox, :acc
30
+
31
+ def initialize( *args )
32
+ super( *args )
33
+ @r0, @angle0 = (@ext - @center).coords(:polar)
34
+ end
35
+
36
+ include ParametricLength
37
+ def parameter_range
38
+ return (self.angle0..self.sens * self.maxangle)
39
+ end
40
+
41
+ def maxangle
42
+ if not @maxangle
43
+ @maxangle = self.compute_maxangle( @r0, @angle0, @curvature )
44
+ end
45
+ return @maxangle
46
+ end
47
+
48
+ def pointfromparameter( parameter, container )
49
+ r = self.compute_radius( @r0, @angle0, @curvature, parameter )
50
+ if not container
51
+ container = V2D[ 0.0, 0.0]
52
+ end
53
+ container.xy = V2D.polar( r, parameter ).coords
54
+ # Trace("parameter #{parameter} container #{container.inspect}")
55
+ return container
56
+ end
57
+
58
+ # compute a point at curviligne abscissa
59
+ #
60
+ # curve method redefinition
61
+ def point( l, container=nil )
62
+ # Trace("point parameter #{l}")
63
+ return pointfromparameter( parameterfromlength(l), container )
64
+ end
19
65
 
66
+ # compute tangent at curviligne abscissa
67
+ #
68
+ # curve method redefinition
69
+ def tangent ( l, container=nil )
70
+ raise NotImplementedError.new("#{self.class.name}#tangent is an abstract method.")
71
+ end
72
+
20
73
  def compute_radius( r0, angle0, curvature, angle )
21
74
  raise NotImplementedError.new("#{self.class.name}#compute_radius is an abstract method.")
22
75
  end
23
76
 
24
- def maxangle( r0, angle0, curvature )
25
- raise NotImplementedError.new("#{self.class.name}#maxangle is an abstract method.")
77
+ def compute_maxangle( r0, angle0, curvature )
78
+ raise NotImplementedError.new("#{self.class.name}#compute_maxangle is an abstract method.")
79
+ end
80
+
81
+ def compute_bezier()
82
+ return SimpleBezier.build( :support, self.refpoints )
83
+ end
84
+
85
+ def bezier
86
+ if not @bezier
87
+ @bezier = self.compute_bezier
88
+ end
89
+ return @bezier
26
90
  end
27
91
 
28
- def compute()
92
+ def refpoints
29
93
  points = []
30
- r0, angle0 = (@ext - @center).coords(:polar)
31
- maxangle = self.maxangle( r0, angle0, @curvature )
32
- SyncS[(r0..0.0), (angle0..self.sens * maxangle)].samples( self.nsamples ) do |radius, angle|
94
+ self.parameter_range.samples( self.nsamples ) do |angle|
33
95
  r = self.compute_radius( r0, angle0, @curvature, angle )
34
96
  point = V2D.polar( r, angle )
35
97
  points.push( @center + point )
36
98
  end
37
- return SimpleBezier.build( :support, points ).data
99
+ return points
38
100
  end
101
+
102
+ # -------------------------------------------------------------
103
+ # sampler computation
104
+ # -------------------------------------------------------------
105
+ include Samplable
106
+ include Splittable
107
+
108
+ alias apply_sample point
109
+
110
+
39
111
  end
40
112
 
41
113
  # at angle angle0, r = r0
42
114
  # at angle angle0 + curvature, r = 0.0
43
115
  class SpiralLinear < GSpiral
44
116
 
45
- def maxangle( r0, angle0, curvature )
117
+ def compute_maxangle( r0, angle0, curvature )
46
118
  return (angle0 + curvature)
47
119
  end
48
120
 
@@ -57,17 +129,22 @@ end
57
129
  class SpiralLog < GSpiral
58
130
 
59
131
  def nsamples
60
- return (curvature * 15.0).to_i
132
+ return (self.curvature * 15.0).to_i
61
133
  end
62
134
 
63
135
  def compute_radius( r0, angle0, curvature, angle )
64
136
  return r0 * Math.exp( - self.sens * (angle - angle0) / curvature )
65
137
  end
66
138
 
67
- def maxangle( r0, angle0, curvature )
139
+ def compute_maxangle( r0, angle0, curvature )
68
140
  return angle0 - curvature * Math.log( 0.001 )
69
141
  end
70
142
 
143
+ # method redefinition from GSpiral from Curve
144
+ def tangent( length, container=nil )
145
+ container = SpiralLog.tangent( self.center, self.point( length ), self.curvature )
146
+ end
147
+
71
148
  def SpiralLog.tangent( center, ext, curvature )
72
149
  return (center - ext).rotate( -Math.atan( curvature ) )
73
150
  end
data/lib/xrvg.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Please refer to README for XRVG introduction
4
4
 
5
5
  # XRVG version (used in rakefile)
6
- XRVG_VERSION = "0.0.8"
6
+ XRVG_VERSION = "0.0.81"
7
7
 
8
8
  # XRVG namespace
9
9
  module XRVG
data/test/test_sample.rb CHANGED
@@ -44,8 +44,13 @@ class RollerTest < Test::Unit::TestCase
44
44
  def test_roller
45
45
  assert_equal( ["a", "b", "a"], Roller["a","b"].samples(3))
46
46
 
47
- rand = Roller["a","b"].rand
48
- assert( ["a","b"].include?( rand ) )
47
+ randresult = Roller["a","b"].rand
48
+ assert( ["a","b"].include?( randresult ) )
49
+
50
+ randresult = Roller["a","b"].rand(2)
51
+ randresult.each do |value|
52
+ assert( ["a","b"].include?( value ) )
53
+ end
49
54
  end
50
55
 
51
56
  def test_next
data/test/test_spiral.rb CHANGED
@@ -4,9 +4,20 @@ require 'test/unit'
4
4
 
5
5
  class SpiralTest < Test::Unit::TestCase
6
6
 
7
- def test_abstract
7
+ def test_abstract1
8
8
  assert_raise(NotImplementedError) {GSpiral.new.compute_radius( 0.0,0.0,0.0,0.0)}
9
9
  end
10
+
11
+ def test_abstract2
12
+ assert_raise(NotImplementedError) {GSpiral.new.tangent( 0.0 )}
13
+ end
14
+
15
+ def test_bezier
16
+ spiral = SpiralLog[]
17
+ assert_equal( spiral.point( 0.0 ), spiral.bezier.point( 0.0 ) )
18
+ assert_equal( spiral.point( 1.0 ), spiral.bezier.point( 1.0 ) )
19
+ end
20
+
10
21
 
11
22
  def test_all
12
23
  spiral = SpiralLog[]
@@ -15,13 +26,13 @@ class SpiralTest < Test::Unit::TestCase
15
26
  spiral = SpiralLinear[]
16
27
  assert_equal( V2D::X, spiral.point( 0.0 ) )
17
28
 
18
- assert_raise(NotImplementedError) {GSpiral.new.maxangle( 0.0,0.0,0.0)}
29
+ assert_raise(NotImplementedError) {GSpiral.new.compute_maxangle( 0.0,0.0,0.0)}
19
30
  end
20
31
 
21
32
  def test_tangent
22
33
  spiral = SpiralLog[]
23
- tangent = SpiralLog.tangent( V2D::O, V2D::X, 1.0 )
24
- newspiral = SpiralLog.fromtangent( tangent, V2D::X, 1.0 )
34
+ tangent = spiral.tangent( 0.0 )
35
+ newspiral = SpiralLog.fromtangent( tangent, spiral.ext, spiral.curvature )
25
36
  assert_equal( spiral.point( 0.0 ), newspiral.point( 0.0 ) )
26
37
  assert_equal( spiral.point( 1.0 ), newspiral.point( 1.0 ) )
27
38
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: xrvg
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.8
7
- date: 2008-08-25 00:00:00 +02:00
6
+ version: 0.0.81
7
+ date: 2008-08-26 00:00:00 +02:00
8
8
  summary: Ruby vector graphics library
9
9
  require_paths:
10
10
  - lib