xrvg 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,17 @@
1
1
  = CHANGES
2
2
 
3
+ == 0.0.8 (2008.08.26) (Future)
4
+ - INCOMPATIBLE modifs:
5
+ - Array is no longer SAMPLABLE => you must remplace "[].geo(5.0).samples" by "SyncS[].geo( 5.0 )"
6
+ this has been done to avoid conflicts between Array and Samplation interface, namely .rand method,
7
+ but also to clean semantic of the operation
8
+ and to be able to upgrade SyncS operations (with .split operator,...)
9
+ == 0.0.7 (2008.08.24) (New)
10
+ === Content
11
+ - Add color services (hsv, hsl, ...)
12
+ - Add intersection services (Beta for the moment, must be consolidated)
13
+ - .random has again its "notsorted" behavior: if you want random to sort its results, you can use .random(:sort, true)
14
+
3
15
  == 0.0.6 (2008.03.24)
4
16
  === Content
5
17
  - Add Spiral classes
@@ -7,7 +19,6 @@
7
19
  - refactor Ondulation bezier builder
8
20
  - WARNING: random() filter now always sort its result => Shuffle filter is created. Moreover, .rand method is now only on Random, and not in Samplable interface (due to overloading Array method when using sort_by {rand, which is no good)
9
21
 
10
-
11
22
  == 0.0.5 (2008.03.22)
12
23
  === Content
13
24
  - Add GeoVariety classes
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
+ # To publish project:
2
+ # - without doc: prepare-release
3
+ # - with doc : publish
4
+ # It is better to do first operation alone, to check if everything is OK, then to do publish
5
+
1
6
  # Rakefile
2
7
  require "rake/testtask"
3
8
  require "rake/clean"
@@ -63,7 +68,7 @@ RDOC_FILES = FileList["README", "CHANGES"]
63
68
 
64
69
  # Ruby library code.
65
70
  LIB_DIR = "lib"
66
- PRE_LIB_FILES = FileList["trace.rb", "samplation.rb", "interpolation.rb", "parametriclength.rb", "utils.rb", "geometry2D.rb", "color.rb", "frame.rb", "shape.rb", "render.rb", "shape.rb", "style.rb", "bezier.rb", "bezierspline.rb", "fitting.rb", "bezierbuilders.rb", "beziermotifs.rb", "beziertools.rb", "interbezier.rb", "geovariety.rb", "spiral.rb", "xrvg.rb"]
71
+ PRE_LIB_FILES = FileList["trace.rb", "samplation.rb", "interpolation.rb", "parametriclength.rb", "utils.rb", "geometry2D.rb", "intersection.rb", "color.rb", "frame.rb", "shape.rb", "render.rb", "shape.rb", "style.rb", "bezier.rb", "bezierspline.rb", "fitting.rb", "bezierbuilders.rb", "beziermotifs.rb", "beziertools.rb", "interbezier.rb", "geovariety.rb", "spiral.rb", "xrvg.rb"]
67
72
  LIB_FILES = FileList["#{LIB_DIR}/*.rb"]
68
73
 
69
74
  # Example code.
@@ -204,8 +209,8 @@ end
204
209
  desc "Regenerate website"
205
210
  task "gen-website" do
206
211
  Rake::Task["clobber"].invoke
207
- # Rake::Task["muse"].invoke
208
- # Rake::Task["examples"].invoke
212
+ Rake::Task["muse"].invoke
213
+ Rake::Task["examples"].invoke
209
214
  Rake::Task["rdoc"].invoke
210
215
  Rake::Task["finish"].invoke
211
216
  end
@@ -217,7 +222,7 @@ task "publish-website" do
217
222
  # sh "scp -r #{WEBSITE_DIR}/* " +
218
223
  # "#{RUBYFORGE_USER}@rubyforge.org:#{rubyforge_path}",
219
224
  # :verbose => true
220
- # Commented because must be triggered explictely as very long: Rake::Task["gen-website"].invoke
225
+ Rake::Task["gen-website"].invoke
221
226
  Rake::Task["upload-website"].invoke
222
227
  end
223
228
 
@@ -306,6 +311,9 @@ desc "Copy example source files to create ./examples directory"
306
311
  task "examples" => ["muse"] do
307
312
  remove_dir EXAMPLE_DIR
308
313
  mkdir EXAMPLE_DIR
314
+ if File.exist?("#{WEBSITE_DIR}/images")
315
+ remove_dir "#{WEBSITE_DIR}/images"
316
+ end
309
317
  mkdir "#{WEBSITE_DIR}/images"
310
318
  require 'www/example_list'
311
319
  example_list.each do |fn|
@@ -316,10 +324,24 @@ task "examples" => ["muse"] do
316
324
  png = String.new(fn)
317
325
  png["\.rb"] = ".png"
318
326
  cp( fn, EXAMPLE_DIR )
319
- sh "ruby #{fn}"
320
- if File.exist?(svg)
321
- sh "ruby svg2png.rb #{svg} 2.0"
322
- cp( png, WEBSITE_DIR_IMAGES )
327
+
328
+ togenerate = true
329
+ if File.exist?(png)
330
+ if File.mtime(png) > File.mtime(source)
331
+ puts "no need to generate #{fn} ..."
332
+ togenerate = false
333
+ end
334
+ end
335
+
336
+ if togenerate
337
+ sh "ruby #{fn}"
338
+ if File.exist?(svg)
339
+ sh "ruby svg2png.rb #{svg} 2.0"
340
+ end
341
+ end
342
+
343
+ if File.exist?(png)
344
+ cp( png, WEBSITE_DIR_IMAGES )
323
345
  end
324
346
  end
325
347
  end
data/lib/samplation.rb CHANGED
@@ -348,6 +348,7 @@ class RandomFilter < Filter
348
348
  include Attributable
349
349
  attribute :mindiff, 0.0
350
350
  attribute :sort, false
351
+ attribute :withboundaries, false
351
352
 
352
353
  # make sampling by trying to check :mindiff constraint
353
354
  #
@@ -413,6 +414,10 @@ class RandomFilter < Filter
413
414
  result = result.shuffle
414
415
  end
415
416
  end
417
+ if self.withboundaries
418
+ result[0] = inputs[0]
419
+ result[-1] = inputs[-1]
420
+ end
416
421
  return result
417
422
  end
418
423
  end
@@ -503,8 +508,11 @@ class Roller
503
508
 
504
509
  # TODO : must be generalized
505
510
  def rand() #:nodoc:
506
- index = (0.0..@items.size).rand.to_i
507
- return @items[index]
511
+ return @items.choice
512
+ end
513
+
514
+ def next()
515
+ return transform( 0.0 )
508
516
  end
509
517
  end
510
518
 
data/lib/trace.rb CHANGED
@@ -25,6 +25,7 @@ end
25
25
  def Trace(string)
26
26
  if Trace.active?
27
27
  puts string
28
+ STDOUT.flush
28
29
  end
29
30
  end
30
31
  end
data/lib/utils.rb CHANGED
@@ -59,7 +59,8 @@ class Range
59
59
  # (1.0..2.0).complement( 1.3 ) => 1.7
60
60
  def complement( value )
61
61
  diff = value - self.begin
62
- return (self.end - diff)
62
+ result = (self.end - diff)
63
+ return result
63
64
  end
64
65
 
65
66
  # utilitary method to force value to be in range
@@ -320,6 +321,28 @@ class Array
320
321
  return self[Kernel::rand(self.size)]
321
322
  end
322
323
 
324
+ # return an array with same elements as self, but rotated
325
+ def rotate(sens=:right)
326
+ result = []
327
+ if sens == :right
328
+ result = [self[-1]] + self[0..-2]
329
+ else
330
+ result = self[1..-1] + [self[0]]
331
+ end
332
+ return result
333
+ end
334
+
335
+ # generate every rotation for the array, with as first element self
336
+ def rotations(sens=:right)
337
+ result = [self]
338
+ current = self
339
+ (self.size-1).times do
340
+ result << current.rotate(sens)
341
+ current = result[-1]
342
+ end
343
+ return result
344
+ end
345
+
323
346
  # compute range of an array by returning (min..max)
324
347
  # [1.0, 3.0, 2.0].range => (1.0..3.0)
325
348
  # if proc supplied, use it to return range of subvalues
data/test/test_color.rb CHANGED
@@ -43,25 +43,27 @@ class ColorTest < Test::Unit::TestCase
43
43
  black = Color[0.0, 0.0, 0.0, 1.0]
44
44
  white = Color[1.0, 1.0, 1.0, 1.0]
45
45
  red = Color[1.0, 0.0, 0.0, 1.0]
46
- assert_equal( black, Color.hsv( 0.0, 0.0, 0.0, 1.0 ) )
47
- assert_equal( white, Color.hsv( 0.0, 0.0, 1.0, 1.0 ) )
48
- assert_equal( red, Color.hsv( 0.0, 1.0, 1.0, 1.0 ) )
49
- assert_equal( black, Color.hsv( 0.2, 1.0, 0.0, 1.0 ) )
50
- assert_equal( black, Color.hsv( 0.4, 1.0, 0.0, 1.0 ) )
51
- assert_equal( black, Color.hsv( 0.6, 1.0, 0.0, 1.0 ) )
52
- assert_equal( black, Color.hsv( 0.8, 1.0, 0.0, 1.0 ) )
53
- assert_equal( black, Color.hsv( 1.0, 1.0, 0.0, 1.0 ) )
46
+ assert_equal( black, Color.hsva( 0.0, 0.0, 0.0, 1.0 ) )
47
+ assert_equal( white, Color.hsva( 0.0, 0.0, 1.0, 1.0 ) )
48
+ assert_equal( red, Color.hsva( 0.0, 1.0, 1.0, 1.0 ) )
49
+ assert_equal( black, Color.hsva( 0.2, 1.0, 0.0, 1.0 ) )
50
+ assert_equal( black, Color.hsva( 0.4, 1.0, 0.0, 1.0 ) )
51
+ assert_equal( black, Color.hsva( 0.6, 1.0, 0.0, 1.0 ) )
52
+ assert_equal( black, Color.hsva( 0.8, 1.0, 0.0, 1.0 ) )
53
+ assert_equal( black, Color.hsva( 1.0, 1.0, 0.0, 1.0 ) )
54
+ assert_equal( [0.0, 0.0, 0.0, 1.0], black.hsva )
54
55
  end
55
56
 
56
57
  def test_hsl
57
58
  black = Color[0.0, 0.0, 0.0, 1.0]
58
59
  white = Color[1.0, 1.0, 1.0, 1.0]
59
60
  red = Color[1.0, 0.0, 0.0, 1.0]
60
- assert_equal( black, Color.hsl( 0.0, 0.0, 0.0, 1.0 ) )
61
- assert_equal( white, Color.hsl( 0.0, 0.0, 1.0, 1.0 ) )
62
- assert_equal( white, Color.hsl( 0.0, 1.0, 1.0, 1.0 ) )
63
- assert_equal( white, Color.hsl( 2.0, 1.0, 1.0, 1.0 ) )
64
- assert_equal( white, Color.hsl( 0.6, 1.0, 1.0, 1.0 ) )
61
+ assert_equal( black, Color.hsla( 0.0, 0.0, 0.0, 1.0 ) )
62
+ assert_equal( white, Color.hsla( 0.0, 0.0, 1.0, 1.0 ) )
63
+ assert_equal( white, Color.hsla( 0.0, 1.0, 1.0, 1.0 ) )
64
+ assert_equal( white, Color.hsla( 2.0, 1.0, 1.0, 1.0 ) )
65
+ assert_equal( white, Color.hsla( 0.6, 1.0, 1.0, 1.0 ) )
66
+ assert_equal( [0.0, 0.0, 0.0, 1.0], black.hsla )
65
67
  end
66
68
 
67
69
 
@@ -86,6 +88,10 @@ class ColorTest < Test::Unit::TestCase
86
88
  assert_equal( [25,25,25,25], Color[0.1,0.1,0.1,0.1].format255 )
87
89
  end
88
90
 
91
+ def test_complement
92
+ assert_equal( Color[ 0.0, 1.0, 1.0, 0.5], Color.red(0.5).complement )
93
+ end
94
+
89
95
  def test_operators
90
96
  assert_equal( Color[0.2, 0.4, 0.6, 1.0], Color[0.1, 0.2, 0.3, 0.5 ] + Color[0.1, 0.2, 0.3, 0.5 ] )
91
97
  assert_equal( Color[0.2, 0.4, 0.6, 1.0], Color[0.1, 0.2, 0.3, 0.5 ] * 2.0 )
data/test/test_utils.rb CHANGED
@@ -130,6 +130,16 @@ class ArrayTest < Test::Unit::TestCase
130
130
  assert_equal( 0.0, [0.0,0.0,0.0].choice )
131
131
  end
132
132
 
133
+ def test_rotate
134
+ assert_equal( [3,1,2], [1,2,3].rotate(:right) )
135
+ assert_equal( [2,3,1], [1,2,3].rotate(:left) )
136
+ end
137
+
138
+ def test_rotations
139
+ assert_equal( [[1,2,3],[2,3,1],[3,1,2]], [1,2,3].rotations(:left) )
140
+ assert_equal( [[1,2,3],[3,1,2],[2,3,1]], [1,2,3].rotations(:right) )
141
+ end
142
+
133
143
  def test_shuffle
134
144
  assert_not_equal( [0.0, 0.1, 0.2, 0.5, 1.0], [0.0,0.1, 0.2, 0.5,1.0].shuffle )
135
145
  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.6
7
- date: 2008-08-06 00:00:00 +02:00
6
+ version: 0.0.7
7
+ date: 2008-08-24 00:00:00 +02:00
8
8
  summary: Ruby vector graphics library
9
9
  require_paths:
10
10
  - lib
@@ -31,27 +31,12 @@ authors:
31
31
  files:
32
32
  - Rakefile
33
33
  - LICENCE
34
- - lib/bezier.rb
35
- - lib/bezierbuilders.rb
36
- - lib/beziermotifs.rb
37
- - lib/bezierspline.rb
38
- - lib/beziertools.rb
39
- - lib/color.rb
40
- - lib/fitting.rb
41
- - lib/frame.rb
42
34
  - lib/geometry2D.rb
43
- - lib/geovariety.rb
44
- - lib/interbezier.rb
45
35
  - lib/interpolation.rb
46
36
  - lib/parametriclength.rb
47
- - lib/render.rb
48
37
  - lib/samplation.rb
49
- - lib/shape.rb
50
- - lib/spiral.rb
51
- - lib/style.rb
52
38
  - lib/trace.rb
53
39
  - lib/utils.rb
54
- - lib/xrvg.rb
55
40
  - examples/arciterate1.rb
56
41
  - examples/arcrecurse1.rb
57
42
  - examples/arcrecurse2.rb