xrvg 0.0.7 → 0.0.8
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 +10 -2
- data/examples/arcrecurse2.rb +1 -1
- data/examples/gradientgeo.rb +1 -1
- data/examples/hellocrown2.rb +1 -1
- data/examples/palette_circle.rb +1 -1
- data/examples/sample.rb +1 -1
- data/lib/bezier.rb +588 -0
- data/lib/bezierbuilders.rb +210 -0
- data/lib/beziermotifs.rb +121 -0
- data/lib/bezierspline.rb +235 -0
- data/lib/beziertools.rb +245 -0
- data/lib/color.rb +567 -0
- data/lib/fitting.rb +203 -0
- data/lib/frame.rb +33 -0
- data/lib/geovariety.rb +128 -0
- data/lib/interbezier.rb +87 -0
- data/lib/intersection.rb +89 -0
- data/lib/render.rb +266 -0
- data/lib/samplation.rb +44 -1
- data/lib/shape.rb +421 -0
- data/lib/spiral.rb +89 -0
- data/lib/style.rb +76 -0
- data/lib/utils.rb +1 -17
- data/lib/xrvg.rb +47 -0
- data/test/test_attributable.rb +19 -0
- data/test/test_bezier.rb +7 -0
- data/test/test_color.rb +36 -1
- data/test/test_intersection.rb +42 -0
- data/test/test_sample.rb +56 -5
- data/test/test_spiral.rb +8 -0
- data/test/test_utils.rb +1 -32
- metadata +19 -2
data/test/test_color.rb
CHANGED
@@ -10,6 +10,23 @@ class ColorTest < Test::Unit::TestCase
|
|
10
10
|
assert_equal( 0.2, color.g )
|
11
11
|
assert_equal( 0.3, color.b )
|
12
12
|
assert_equal( 0.4, color.a )
|
13
|
+
|
14
|
+
assert_equal( Color[0.5, 0.2, 0.3, 0.4], color.r(0.5) )
|
15
|
+
assert_equal( Color[0.1, 0.5, 0.3, 0.4], color.g(0.5) )
|
16
|
+
assert_equal( Color[0.1, 0.2, 0.5, 0.4], color.b(0.5) )
|
17
|
+
assert_equal( Color[0.1, 0.2, 0.3, 0.5], color.a(0.5) )
|
18
|
+
|
19
|
+
assert_equal( 0.0, Color.red.hue )
|
20
|
+
assert_equal( Color.hsva( 0.1, 1.0, 1.0, 1.0 ), Color.red.hue( 0.1 ) )
|
21
|
+
|
22
|
+
assert_equal( 1.0, Color.red.saturation )
|
23
|
+
assert_equal( Color.hsva( 0.0, 0.1, 1.0, 1.0 ), Color.red.saturation( 0.1 ) )
|
24
|
+
|
25
|
+
assert_equal( 1.0, Color.red.value )
|
26
|
+
assert_equal( Color.hsva( 0.0, 1.0, 0.1, 1.0 ), Color.red.value( 0.1 ) )
|
27
|
+
|
28
|
+
assert_equal( 0.5, Color.red.lightness )
|
29
|
+
assert_equal( Color.hsla( 0.0, 1.0, 0.1, 1.0 ), Color.red.lightness( 0.1 ) )
|
13
30
|
end
|
14
31
|
|
15
32
|
def test_colors
|
@@ -52,6 +69,8 @@ class ColorTest < Test::Unit::TestCase
|
|
52
69
|
assert_equal( black, Color.hsva( 0.8, 1.0, 0.0, 1.0 ) )
|
53
70
|
assert_equal( black, Color.hsva( 1.0, 1.0, 0.0, 1.0 ) )
|
54
71
|
assert_equal( [0.0, 0.0, 0.0, 1.0], black.hsva )
|
72
|
+
assert_equal( [2.0/3.0, 1.0, 1.0, 1.0], Color.blue.hsva )
|
73
|
+
assert_equal( [1.0/3.0, 1.0, 1.0, 1.0], Color.green.hsva )
|
55
74
|
end
|
56
75
|
|
57
76
|
def test_hsl
|
@@ -64,6 +83,7 @@ class ColorTest < Test::Unit::TestCase
|
|
64
83
|
assert_equal( white, Color.hsla( 2.0, 1.0, 1.0, 1.0 ) )
|
65
84
|
assert_equal( white, Color.hsla( 0.6, 1.0, 1.0, 1.0 ) )
|
66
85
|
assert_equal( [0.0, 0.0, 0.0, 1.0], black.hsla )
|
86
|
+
assert_equal( 0.0, Color[0.9,0.8,0.8,1.0].hsla[0] )
|
67
87
|
end
|
68
88
|
|
69
89
|
|
@@ -119,7 +139,22 @@ class PaletteTest < Test::Unit::TestCase
|
|
119
139
|
palette.interpoltype = :linear
|
120
140
|
assert_equal( :linear, palette.interpoltype )
|
121
141
|
end
|
122
|
-
|
142
|
+
|
143
|
+
def test_hsv
|
144
|
+
palette = Palette[ :colorlist, [ 0.0, Color.hsva( 0.5, 0.5, 0.5, 0.5), 1.0, Color.hsva( 0.6, 0.6, 0.6, 0.6 ) ], :interpoldomain, :hsv ]
|
145
|
+
assert_equal( Color.hsva( 0.55, 0.55, 0.55, 0.55), palette.sample( 0.5 ) )
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_hsl
|
149
|
+
palette = Palette[ :colorlist, [ 0.0, Color.hsla( 0.5, 0.5, 0.5, 0.5), 1.0, Color.hsla( 0.6, 0.6, 0.6, 0.6 ) ], :interpoldomain, :hsl ]
|
150
|
+
assert_equal( Color.hsla( 0.55, 0.55, 0.55, 0.55), palette.sample( 0.5 ) )
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_error
|
154
|
+
assert_raise(RuntimeError) {Palette[ :colorlist, [ 0.0, Color.hsla( 0.5, 0.5, 0.5, 0.5), 1.0, Color.hsla( 0.6, 0.6, 0.6, 0.6 ) ], :interpoldomain, :toto ]}
|
155
|
+
end
|
156
|
+
|
157
|
+
|
123
158
|
end
|
124
159
|
|
125
160
|
class GradientTest < Test::Unit::TestCase
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'xrvg'
|
3
|
+
include XRVG
|
4
|
+
|
5
|
+
|
6
|
+
class V2DExtTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_isLeft
|
9
|
+
p0 = V2D::O
|
10
|
+
p1 = V2D::X
|
11
|
+
assert_equal( :on, V2D[ 0.5, 0.0].isLeft( p0, p1 ) )
|
12
|
+
assert_equal( :left, V2D[ 0.5, 0.1].isLeft( p0, p1 ) )
|
13
|
+
assert_equal( :right, V2D[ 0.5, -0.1].isLeft( p0, p1 ) )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
class V2DSTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_intersect
|
21
|
+
assert_equal( true, V2DS[ V2D[ 0.0, 0.5 ], V2D[ 1.0, -0.5 ] ].intersect?( V2DS[ V2D::X, V2D::O ] ))
|
22
|
+
assert_equal( false, V2DS[ V2D[ 0.0, 0.5 ], V2D[ 1.0, -0.5 ] ].intersect?( V2DS[V2D[ 0.0, 1.0 ], V2D[ 1.0, 1.0 ] ]) )
|
23
|
+
assert_equal( true, V2DS[ V2D::X, V2D::O ].intersect?( V2DS[ V2D::X, V2D::O ] ) )
|
24
|
+
assert_equal( true, V2DS[ V2D::X, V2D::O ].intersect?( V2DS[ V2D::Y, V2D::O ] ) )
|
25
|
+
assert_equal( false, V2DS[ V2D::X, V2D::O ].intersect?( V2DS[ V2D::Y + V2D::X, V2D::O + V2D::Y ] ) )
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_intersection
|
29
|
+
assert_equal( nil, V2DS[ V2D[ 0.0, 0.5 ], V2D[ 1.0, -0.5 ] ].intersection( V2DS[V2D[ 0.0, 1.0 ], V2D[ 1.0, 1.0 ] ]) )
|
30
|
+
assert_equal( V2D[0.5,0.0], V2DS[ V2D[ 0.0, 0.5 ], V2D[ 1.0, -0.5 ] ].intersection( V2DS[ V2D::X, V2D::O ] ))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_intersections
|
34
|
+
c1 = Bezier.raw( V2D[0.0, 0.0], V2D[1.0, 0.0], V2D[0.0, 1.0], V2D[1.0, 1.0] )
|
35
|
+
c2 = LinearBezier[:support, [V2D::O + V2D::Y, V2D::X]]
|
36
|
+
[[0.5, 0.5], Bezier.intersections( c1, c2 )].forzip do |ve, vr|
|
37
|
+
assert( ve.fequal?( vr ) )
|
38
|
+
end
|
39
|
+
c2 = LinearBezier[:support, [V2D::O, V2D::X + V2D::Y]]
|
40
|
+
# assert_equal( [0.0, 0.0, 0.5, 0.5, 1.0, 1.0], Bezier.intersections( c1, c2 ) )
|
41
|
+
end
|
42
|
+
end
|
data/test/test_sample.rb
CHANGED
@@ -4,11 +4,6 @@ include XRVG
|
|
4
4
|
|
5
5
|
class STest < Test::Unit::TestCase
|
6
6
|
|
7
|
-
def test_sample
|
8
|
-
# assert_equal( [0.0, 0.571428571428571, 0.857142857142857, 1.0], (0.0..1.0).geofull(2.0).samples( 4 ) )
|
9
|
-
assert_equal( [0.0, 0.5, 0.75], [(0.0..0.75)].geofull(2.0).samples( 3 ) )
|
10
|
-
end
|
11
|
-
|
12
7
|
def test_sin
|
13
8
|
[[0.0,0.0], (0.0..1.0).sin().samples( 2 )].forzip do |exp, real|
|
14
9
|
assert( exp.fequal?( real ) )
|
@@ -25,4 +20,60 @@ class STest < Test::Unit::TestCase
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
23
|
+
class SyncTest < Test::Unit::TestCase
|
24
|
+
|
25
|
+
def test_samples
|
26
|
+
assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], SyncS[(0.0..1.0), (1.0..0.0)].samples(3))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_samples2
|
30
|
+
result = []
|
31
|
+
SyncS[(0.0..1.0), (1.0..0.0)].samples(3) {|v1,v2| result += [v1,v2] }
|
32
|
+
assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], result )
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_sample
|
36
|
+
assert_equal( [0.0, 0.5, 0.75], SyncS[(0.0..0.75)].geofull(2.0).samples( 3 ) )
|
37
|
+
assert_equal( [0,1,0], SyncS[ [0,1] ].samples( 3 ) )
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
class RollerTest < Test::Unit::TestCase
|
43
|
+
|
44
|
+
def test_roller
|
45
|
+
assert_equal( ["a", "b", "a"], Roller["a","b"].samples(3))
|
46
|
+
|
47
|
+
rand = Roller["a","b"].rand
|
48
|
+
assert( ["a","b"].include?( rand ) )
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_next
|
52
|
+
roller = Roller[0,1]
|
53
|
+
result = []
|
54
|
+
3.times do
|
55
|
+
result << roller.next
|
56
|
+
end
|
57
|
+
assert_equal( [0,1,0], result )
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
class RandomTest < Test::Unit::TestCase
|
63
|
+
|
64
|
+
def test_random
|
65
|
+
result = Range.O.random(:mindiff,0.0).samples( 3 )
|
66
|
+
# what kinf of test ?
|
67
|
+
assert_raise(RuntimeError) {Range.O.random(:mindiff,6.0).samples( 3 )}
|
68
|
+
assert_equal( [0.0,1.0,2.0], (0.0..2.0).random(:mindiff,0.5,:sort,true).samples( 3 ) )
|
69
|
+
assert_not_equal( [0.0, 1.0], (0.0..1.0).random.samples(2))
|
70
|
+
assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).random(:mindiff,0.5,:sort,true).samples(3))
|
71
|
+
assert_raise(RuntimeError) {(0.0..1.0).random(:mindiff,0.6).samples(3)}
|
72
|
+
|
73
|
+
result = Range.O.random(:mindiff,0.0, :withboundaries, true).samples( 3 )
|
74
|
+
assert_equal( 0.0, result[0] )
|
75
|
+
assert_equal( 1.0, result[-1] )
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
28
79
|
|
data/test/test_spiral.rb
CHANGED
@@ -18,5 +18,13 @@ class SpiralTest < Test::Unit::TestCase
|
|
18
18
|
assert_raise(NotImplementedError) {GSpiral.new.maxangle( 0.0,0.0,0.0)}
|
19
19
|
end
|
20
20
|
|
21
|
+
def test_tangent
|
22
|
+
spiral = SpiralLog[]
|
23
|
+
tangent = SpiralLog.tangent( V2D::O, V2D::X, 1.0 )
|
24
|
+
newspiral = SpiralLog.fromtangent( tangent, V2D::X, 1.0 )
|
25
|
+
assert_equal( spiral.point( 0.0 ), newspiral.point( 0.0 ) )
|
26
|
+
assert_equal( spiral.point( 1.0 ), newspiral.point( 1.0 ) )
|
27
|
+
end
|
28
|
+
|
21
29
|
end
|
22
30
|
|
data/test/test_utils.rb
CHANGED
@@ -17,16 +17,6 @@ end
|
|
17
17
|
|
18
18
|
class ArrayTest < Test::Unit::TestCase
|
19
19
|
|
20
|
-
def test_samples
|
21
|
-
assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], [(0.0..1.0), (1.0..0.0)].samples(3))
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_samples2
|
25
|
-
result = []
|
26
|
-
[(0.0..1.0), (1.0..0.0)].samples(3) {|v1,v2| result += [v1,v2] }
|
27
|
-
assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], result )
|
28
|
-
end
|
29
|
-
|
30
20
|
def test_pairs
|
31
21
|
a = [ 1, 2, 3]
|
32
22
|
b = Array.new
|
@@ -122,10 +112,6 @@ class ArrayTest < Test::Unit::TestCase
|
|
122
112
|
assert_equal( (1.0..2.0), [V2D[2.0,1.0], V2D[1.0,2.0]].range( :x ) )
|
123
113
|
end
|
124
114
|
|
125
|
-
def test_sample
|
126
|
-
assert_equal( [0.0, 0.5, 0.75], [(0.0..0.75)].geofull(2.0).samples( 3 ) )
|
127
|
-
end
|
128
|
-
|
129
115
|
def test_choice
|
130
116
|
assert_equal( 0.0, [0.0,0.0,0.0].choice )
|
131
117
|
end
|
@@ -187,16 +173,6 @@ class RangeTest < Test::Unit::TestCase
|
|
187
173
|
assert_not_equal( [0.0, 1.0], (0.0..1.0).ssort.random.samples(2))
|
188
174
|
end
|
189
175
|
|
190
|
-
def test_random
|
191
|
-
result = Range.O.random(:mindiff,0.0).samples( 3 )
|
192
|
-
# what kinf of test ?
|
193
|
-
assert_raise(RuntimeError) {Range.O.random(:mindiff,6.0).samples( 3 )}
|
194
|
-
assert_equal( [0.0,1.0,2.0], (0.0..2.0).random(:mindiff,0.5,:sort,true).samples( 3 ) )
|
195
|
-
assert_not_equal( [0.0, 1.0], (0.0..1.0).random.samples(2))
|
196
|
-
assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).random(:mindiff,0.5,:sort,true).samples(3))
|
197
|
-
assert_raise(RuntimeError) {(0.0..1.0).random(:mindiff,0.6).samples(3)}
|
198
|
-
end
|
199
|
-
|
200
176
|
def test_shuffle
|
201
177
|
assert_not_equal( [0.0, 0.25, 0.5, 0.75, 1.0], (0.0..1.0).shuffle.samples(5))
|
202
178
|
assert_equal( [0.0, 0.25, 0.5, 0.75, 1.0], (0.0..1.0).ssort.shuffle.samples(5))
|
@@ -342,14 +318,7 @@ class SampleTest < Test::Unit::TestCase
|
|
342
318
|
|
343
319
|
def test_class_sample
|
344
320
|
s = SampleClass.new
|
345
|
-
assert_equal( ["a0.0", "b0.0", "a0.5", "b0.5", "a1.0", "b1.0"], [s.filter(:sampleA), s.filter(:sampleB)].samples(3))
|
346
|
-
end
|
347
|
-
|
348
|
-
def test_roller
|
349
|
-
assert_equal( ["a", "b", "a"], Roller["a","b"].samples(3))
|
350
|
-
|
351
|
-
rand = Roller["a","b"].rand
|
352
|
-
assert( ["a","b"].include?( rand ) )
|
321
|
+
assert_equal( ["a0.0", "b0.0", "a0.5", "b0.5", "a1.0", "b1.0"], SyncS[s.filter(:sampleA), s.filter(:sampleB)].samples(3))
|
353
322
|
end
|
354
323
|
|
355
324
|
def test_random_split
|
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.
|
7
|
-
date: 2008-08-
|
6
|
+
version: 0.0.8
|
7
|
+
date: 2008-08-25 00:00:00 +02:00
|
8
8
|
summary: Ruby vector graphics library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -31,12 +31,28 @@ 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
|
34
42
|
- lib/geometry2D.rb
|
43
|
+
- lib/geovariety.rb
|
44
|
+
- lib/interbezier.rb
|
35
45
|
- lib/interpolation.rb
|
46
|
+
- lib/intersection.rb
|
36
47
|
- lib/parametriclength.rb
|
48
|
+
- lib/render.rb
|
37
49
|
- lib/samplation.rb
|
50
|
+
- lib/shape.rb
|
51
|
+
- lib/spiral.rb
|
52
|
+
- lib/style.rb
|
38
53
|
- lib/trace.rb
|
39
54
|
- lib/utils.rb
|
55
|
+
- lib/xrvg.rb
|
40
56
|
- examples/arciterate1.rb
|
41
57
|
- examples/arcrecurse1.rb
|
42
58
|
- examples/arcrecurse2.rb
|
@@ -88,6 +104,7 @@ test_files:
|
|
88
104
|
- test/test_geovariety.rb
|
89
105
|
- test/test_interbezier.rb
|
90
106
|
- test/test_interpolation.rb
|
107
|
+
- test/test_intersection.rb
|
91
108
|
- test/test_parametric_length.rb
|
92
109
|
- test/test_render.rb
|
93
110
|
- test/test_sample.rb
|