rays 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,8 @@ require_relative 'helper'
6
6
 
7
7
  class TestColorSpace < Test::Unit::TestCase
8
8
 
9
- def cs (*args)
10
- Rays::ColorSpace.new *args
9
+ def cs(*args)
10
+ Rays::ColorSpace.new(*args)
11
11
  end
12
12
 
13
13
  TYPES = %w[
@@ -35,7 +35,7 @@ class TestColorSpace < Test::Unit::TestCase
35
35
  alias bgra_f bgra_float
36
36
  alias abgr_f abgr_float
37
37
 
38
- def all ()
38
+ def all()
39
39
  [
40
40
  gray, alpha,
41
41
  rgb, bgr, rgba, bgra, rgbx, bgrx, argb, abgr, xrgb, xbgr,
@@ -43,49 +43,49 @@ class TestColorSpace < Test::Unit::TestCase
43
43
  ]
44
44
  end
45
45
 
46
- def test_gray? ()
46
+ def test_gray?()
47
47
  grays = [gray]
48
48
  others = all - grays
49
49
  grays .each {|t| assert_equal true, t.gray?}
50
50
  others.each {|t| assert_equal false, t.gray?}
51
51
  end
52
52
 
53
- def test_alpha? ()
53
+ def test_alpha?()
54
54
  alphas = [alpha]
55
55
  others = all - alphas
56
56
  alphas.each {|t| assert_equal true, t.alpha?}
57
57
  others.each {|t| assert_equal false, t.alpha?}
58
58
  end
59
59
 
60
- def test_rgb? ()
60
+ def test_rgb?()
61
61
  rgbs = [rgb, rgba, rgbx, argb, xrgb, rgb_f, rgba_f, argb_f]
62
62
  others = all - rgbs
63
63
  rgbs .each {|t| assert_equal true, t.rgb?}
64
64
  others.each {|t| assert_equal false, t.rgb?}
65
65
  end
66
66
 
67
- def test_bgr? ()
67
+ def test_bgr?()
68
68
  bgrs = [bgr, bgra, bgrx, abgr, xbgr, bgr_f, bgra_f, abgr_f]
69
69
  others = all - bgrs
70
70
  bgrs .each {|t| assert_equal true, t.bgr?}
71
71
  others.each {|t| assert_equal false, t.bgr?}
72
72
  end
73
73
 
74
- def test_float? ()
74
+ def test_float?()
75
75
  floats = [rgb_f, rgba_f, argb_f, bgr_f, bgra_f, abgr_f]
76
76
  others = all - floats
77
77
  floats.each {|t| assert_equal true, t.float?}
78
78
  others.each {|t| assert_equal false, t.float?}
79
79
  end
80
80
 
81
- def test_has_alpha? ()
81
+ def test_has_alpha?()
82
82
  alphas = [alpha, rgba, argb, bgra, abgr, rgba_f, argb_f, bgra_f, abgr_f]
83
83
  others = all - alphas
84
84
  alphas.each {|t| assert_equal true, t.has_alpha?}
85
85
  others.each {|t| assert_equal false, t.has_alpha?}
86
86
  end
87
87
 
88
- def test_has_skip? ()
88
+ def test_has_skip?()
89
89
  skips = [rgbx, xrgb, bgrx, xbgr]
90
90
  others = all - skips
91
91
  skips.each {|t| assert_equal true, t.has_skip?}
data/test/test_font.rb CHANGED
@@ -6,26 +6,26 @@ require_relative 'helper'
6
6
 
7
7
  class TestFont < Test::Unit::TestCase
8
8
 
9
- def font (*args)
10
- Rays::Font.new *args
9
+ def font(*args)
10
+ Rays::Font.new(*args)
11
11
  end
12
12
 
13
- def test_name ()
13
+ def test_name()
14
14
  assert_kind_of String, font.name
15
15
  end
16
16
 
17
- def test_size ()
17
+ def test_size()
18
18
  assert_kind_of Numeric, font.size
19
19
  assert_equal 32, font(nil, 32).size
20
20
  end
21
21
 
22
- def test_width ()
22
+ def test_width()
23
23
  assert_equal 0, font.width('')
24
24
  w = font.width 'X'
25
25
  assert_equal w * 2, font.width('XX')
26
26
  end
27
27
 
28
- def test_height ()
28
+ def test_height()
29
29
  f = font
30
30
  assert_equal f.height, f.ascent + f.descent + f.leading
31
31
  end
data/test/test_image.rb CHANGED
@@ -9,24 +9,24 @@ class TestImage < Test::Unit::TestCase
9
9
  W = 10
10
10
  H = 10
11
11
 
12
- def image (w = W, h = H, *args)
12
+ def image(w = W, h = H, *args)
13
13
  Rays::Image.new w, h, *args
14
14
  end
15
15
 
16
- def color (r = 0, g = 0, b = 0, a = 0)
16
+ def color(r = 0, g = 0, b = 0, a = 0)
17
17
  Rays::Color.new r, g, b, a
18
18
  end
19
19
 
20
- def bounds (*args)
21
- Rays::Bounds.new *args
20
+ def bounds(*args)
21
+ Rays::Bounds.new(*args)
22
22
  end
23
23
 
24
- def test_initialize ()
24
+ def test_initialize()
25
25
  assert_equal W, image.width
26
26
  assert_equal H, image.height
27
27
  end
28
28
 
29
- def test_dup ()
29
+ def test_dup()
30
30
  o = image
31
31
  assert_equal color(0, 0, 0, 0), o[0, 0]
32
32
  o[0, 0] = color(1, 0, 0, 0)
@@ -38,12 +38,12 @@ class TestImage < Test::Unit::TestCase
38
38
  assert_equal color(1, 0, 0, 0), o[0, 0]
39
39
  end
40
40
 
41
- def test_bitmap ()
41
+ def test_bitmap()
42
42
  assert_equal W, image.bitmap.width
43
43
  assert_equal H, image.bitmap.height
44
44
  end
45
45
 
46
- def test_painter ()
46
+ def test_painter()
47
47
  pa = image.painter
48
48
  assert_equal color(0, 0, 0, 0), pa.background
49
49
  assert_equal color(1, 1, 1, 1), pa.fill
@@ -52,17 +52,17 @@ class TestImage < Test::Unit::TestCase
52
52
  assert_equal Rays::Font.new, pa.font
53
53
  end
54
54
 
55
- def test_paint ()
56
- def paint (&block)
57
- Rays::Image.new(10, 10).paint &block
55
+ def test_paint()
56
+ def paint(&block)
57
+ Rays::Image.new(10, 10).paint(&block)
58
58
  end
59
- def fill (&block)
59
+ def fill(&block)
60
60
  paint {|p| p.fill 1, 0, 0; p.stroke nil; block.call p}
61
61
  end
62
- def stroke (&block)
62
+ def stroke(&block)
63
63
  paint {|p| p.fill nil; p.stroke 1, 0, 0; block.call p}
64
64
  end
65
- def drawn (&block)
65
+ def drawn(&block)
66
66
  fill(&block).bitmap.to_a.reject {|o| o.transparent?}.uniq.size > 0
67
67
  end
68
68
 
data/test/test_matrix.rb CHANGED
@@ -6,41 +6,41 @@ require_relative 'helper'
6
6
 
7
7
  class TestMatrix < Test::Unit::TestCase
8
8
 
9
- def matrix (*args)
10
- Rays::Matrix.new *args
9
+ def matrix(*args)
10
+ Rays::Matrix.new(*args)
11
11
  end
12
12
 
13
- def mat_str (str)
14
- matrix *str.split(/\s*/).map(&:to_f)
13
+ def mat_str(str)
14
+ matrix(*str.split(/\s*/).map(&:to_f))
15
15
  end
16
16
 
17
- def translate (*args)
18
- Rays::Matrix.translate *args
17
+ def translate(*args)
18
+ Rays::Matrix.translate(*args)
19
19
  end
20
20
 
21
- def scale (*args)
22
- Rays::Matrix.scale *args
21
+ def scale(*args)
22
+ Rays::Matrix.scale(*args)
23
23
  end
24
24
 
25
- def rotate (*args)
26
- Rays::Matrix.rotate *args
25
+ def rotate(*args)
26
+ Rays::Matrix.rotate(*args)
27
27
  end
28
28
 
29
- def point (*args)
30
- Rays::Point.new *args
29
+ def point(*args)
30
+ Rays::Point.new(*args)
31
31
  end
32
32
 
33
- def test_initialize ()
33
+ def test_initialize()
34
34
  assert_equal mat_str('1000 0100 0010 0001'), matrix
35
35
  assert_equal mat_str('0000 0000 0000 0000'), matrix(0)
36
36
  assert_equal mat_str('2000 0200 0020 0002'), matrix(2)
37
37
  assert_equal mat_str('1234 5678 9876 5432'), matrix(1,2,3,4,5,6,7,8,9,8,7,6,5,4,3,2)
38
38
  (2..15).each do |n|
39
- assert_raise(ArgumentError) {matrix *[0] * n}
39
+ assert_raise(ArgumentError) {matrix(*[0] * n)}
40
40
  end
41
41
  end
42
42
 
43
- def test_dup ()
43
+ def test_dup()
44
44
  o = matrix
45
45
  assert_equal mat_str('1000 0100 0010 0001'), o
46
46
  o[0, 0] = 9
@@ -52,7 +52,7 @@ class TestMatrix < Test::Unit::TestCase
52
52
  assert_equal mat_str('9000 0100 0010 0001'), o
53
53
  end
54
54
 
55
- def test_mult ()
55
+ def test_mult()
56
56
  assert_equal point(2, 3), scale(2, 3) * point(1, 1)
57
57
 
58
58
  assert_kind_of Rays::Point, matrix * point
@@ -68,20 +68,20 @@ class TestMatrix < Test::Unit::TestCase
68
68
  end
69
69
  end
70
70
 
71
- def test_get_at ()
71
+ def test_get_at()
72
72
  o = mat_str '1234 5678 9876 5432'
73
73
  assert_equal 1, o[0, 0]
74
74
  assert_equal 2, o[0, 1]
75
75
  end
76
76
 
77
- def test_set_at ()
77
+ def test_set_at()
78
78
  o = mat_str '1234 5678 9876 5432'
79
79
  assert_equal 1, o[0, 0]
80
80
  o[0, 0] = 10
81
81
  assert_equal 10, o[0, 0]
82
82
  end
83
83
 
84
- def test_compare ()
84
+ def test_compare()
85
85
  o = matrix 1
86
86
  assert o == mat_str('1000 0100 0010 0001')
87
87
  assert_not o != mat_str('1000 0100 0010 0001')
@@ -90,7 +90,7 @@ class TestMatrix < Test::Unit::TestCase
90
90
  assert o > matrix(0)
91
91
  end
92
92
 
93
- def test_transform ()
93
+ def test_transform()
94
94
  assert_equal mat_str('1001 0102 0013 0001'), translate(1, 2, 3)
95
95
  assert_equal mat_str('2000 0300 0040 0001'), scale(2, 3, 4)
96
96
 
data/test/test_painter.rb CHANGED
@@ -6,23 +6,23 @@ require_relative 'helper'
6
6
 
7
7
  class TestPainter < Test::Unit::TestCase
8
8
 
9
- def painter ()
9
+ def painter()
10
10
  Rays::Painter.new
11
11
  end
12
12
 
13
- def font (name = nil, size = nil)
13
+ def font(name = nil, size = nil)
14
14
  Rays::Font.new name, size
15
15
  end
16
16
 
17
- def color (*args)
18
- Rays::Color.new *args
17
+ def color(*args)
18
+ Rays::Color.new(*args)
19
19
  end
20
20
 
21
- def setup ()
21
+ def setup()
22
22
  Rays::Color.set_palette_color :rgb001, color(0, 0, 1)
23
23
  end
24
24
 
25
- def test_background_accessor ()
25
+ def test_background_accessor()
26
26
  pa = painter
27
27
  pa.background = 1
28
28
  assert_equal color(1, 1, 1, 1), pa.background
@@ -36,7 +36,7 @@ class TestPainter < Test::Unit::TestCase
36
36
  assert_equal color(1, 1, 1, 1), pa.background
37
37
  end
38
38
 
39
- def test_fill_accessor ()
39
+ def test_fill_accessor()
40
40
  pa = painter
41
41
  pa.fill = 1
42
42
  assert_equal color(1, 1, 1, 1), pa.fill
@@ -50,7 +50,7 @@ class TestPainter < Test::Unit::TestCase
50
50
  assert_equal color(1, 1, 1, 1), pa.fill
51
51
  end
52
52
 
53
- def test_stroke_accessor ()
53
+ def test_stroke_accessor()
54
54
  pa = painter
55
55
  pa.stroke = 1
56
56
  assert_equal color(1, 1, 1, 1), pa.stroke
@@ -64,7 +64,7 @@ class TestPainter < Test::Unit::TestCase
64
64
  assert_equal color(1, 1, 1, 1), pa.stroke
65
65
  end
66
66
 
67
- def test_stroke_width_accessor ()
67
+ def test_stroke_width_accessor()
68
68
  pa = painter
69
69
  assert_equal 0, pa.stroke_width
70
70
  pa.stroke_width = 1
@@ -79,7 +79,7 @@ class TestPainter < Test::Unit::TestCase
79
79
  assert_equal 2, pa.stroke_width
80
80
  end
81
81
 
82
- def test_stroke_cap_accessor ()
82
+ def test_stroke_cap_accessor()
83
83
  pa = painter
84
84
  assert_equal :butt, pa.stroke_cap
85
85
  pa.stroke_cap = :round
@@ -95,7 +95,7 @@ class TestPainter < Test::Unit::TestCase
95
95
  assert_raise(ArgumentError) {pa.stroke_cap Rays::CAP_BUTT}# ToDo: accept this
96
96
  end
97
97
 
98
- def test_stroke_join_accessor ()
98
+ def test_stroke_join_accessor()
99
99
  pa = painter
100
100
  assert_equal :miter, pa.stroke_join
101
101
  pa.stroke_join = :round
@@ -111,7 +111,7 @@ class TestPainter < Test::Unit::TestCase
111
111
  assert_raise(ArgumentError) {pa.stroke_join Rays::JOIN_MITER}# ToDo: accept this
112
112
  end
113
113
 
114
- def test_miter_limit_accessor ()
114
+ def test_miter_limit_accessor()
115
115
  pa = painter
116
116
  assert_equal 2, pa.miter_limit
117
117
  pa.miter_limit = 3
@@ -124,7 +124,7 @@ class TestPainter < Test::Unit::TestCase
124
124
  assert_equal 4, pa.miter_limit
125
125
  end
126
126
 
127
- def test_clip_accessor ()
127
+ def test_clip_accessor()
128
128
  pa = painter
129
129
  pa.clip = [1, 2, 3, 4]
130
130
  assert_equal [1, 2, 3, 4], pa.clip.to_a
@@ -138,7 +138,7 @@ class TestPainter < Test::Unit::TestCase
138
138
  assert_equal [1, 2, 3, 4], pa.clip.to_a
139
139
  end
140
140
 
141
- def test_font_accessor ()
141
+ def test_font_accessor()
142
142
  pa = painter
143
143
  f10, f20 = font(nil, 10), font(nil, 20)
144
144
  pa.font = f10
@@ -153,7 +153,7 @@ class TestPainter < Test::Unit::TestCase
153
153
  assert_equal f10, pa.font
154
154
  end
155
155
 
156
- def test_font_name_size ()
156
+ def test_font_name_size()
157
157
  pa = painter
158
158
  pa.font "Menlo", 10
159
159
  assert_equal "Menlo Regular", pa.font.name
@@ -164,7 +164,7 @@ class TestPainter < Test::Unit::TestCase
164
164
  assert_equal 20, pa.font.size
165
165
  end
166
166
 
167
- def test_color_by_name ()
167
+ def test_color_by_name()
168
168
  pa = painter
169
169
  pa.fill = :rgb001
170
170
  assert_equal color(0, 0, 1), pa.fill
@@ -182,7 +182,7 @@ class TestPainter < Test::Unit::TestCase
182
182
  assert_equal color(0, 1, 0), pa.fill
183
183
  end
184
184
 
185
- def test_push ()
185
+ def test_push()
186
186
  pa = painter
187
187
  pa.fill = [1, 0, 0]
188
188
  assert_equal color(1, 0, 0), pa.fill
@@ -223,7 +223,7 @@ class TestPainter < Test::Unit::TestCase
223
223
  assert_equal color(0, 1, 0), pa.fill
224
224
  end
225
225
 
226
- def test_shader ()
226
+ def test_shader()
227
227
  img = Rays::Image.new(10, 10).paint {
228
228
  shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
229
229
  fill 1, 0, 0
@@ -6,19 +6,19 @@ require_relative 'helper'
6
6
 
7
7
  class TestPainterShape < Test::Unit::TestCase
8
8
 
9
- def color (*args)
10
- Rays::Color.new *args
9
+ def color(*args)
10
+ Rays::Color.new(*args)
11
11
  end
12
12
 
13
- def image (fill = 1, stroke = 0, pixel_density = 1, &block)
13
+ def image(fill = 1, stroke = 0, pixel_density = 1, &block)
14
14
  Rays::Image.new(100, 100, Rays::RGBA, pixel_density).paint {|p|
15
15
  p.fill fill > 0 ? color(fill) : nil
16
16
  p.stroke stroke > 0 ? color(stroke) : nil
17
- p.instance_eval &block if block
17
+ p.instance_eval(&block) if block
18
18
  }
19
19
  end
20
20
 
21
- def test_line ()
21
+ def test_line()
22
22
  img = image(0, 1) {line 1, 1, 98, 98}
23
23
  assert_equal 0, img[ 0, 0].a
24
24
  assert_equal 1, img[ 1, 1].a
@@ -26,7 +26,7 @@ class TestPainterShape < Test::Unit::TestCase
26
26
  assert_equal 0, img[99, 99].a
27
27
  end
28
28
 
29
- def test_curve ()
29
+ def test_curve()
30
30
  =begin
31
31
  img = image(0, 1) {curve 1, 1, 98, 1, 98, 98, 1, 98}
32
32
  assert_equal 0, img[ 0, 0].a
@@ -49,7 +49,7 @@ class TestPainterShape < Test::Unit::TestCase
49
49
  assert_raise(ArgumentError) {image {curve 0, 1, 2, 3, 4, 5, 6, 7, 8}}
50
50
  end
51
51
 
52
- def test_bezier ()
52
+ def test_bezier()
53
53
  =begin
54
54
  img = image(0, 1) {bezier 1, 1, 98, 1, 98, 98, 1, 98}
55
55
  assert_equal 0, img[ 0, 0].a
@@ -72,7 +72,7 @@ class TestPainterShape < Test::Unit::TestCase
72
72
  assert_raise(ArgumentError) {image {bezier 0, 1, 2, 3, 4, 5, 6, 7, 8}}
73
73
  end
74
74
 
75
- def test_rect ()
75
+ def test_rect()
76
76
  img = image {rect 1, 1, 98, 98}
77
77
  assert_equal 0, img[ 0, 0].a
78
78
  assert_equal 1, img[ 1, 1].a
@@ -80,7 +80,7 @@ class TestPainterShape < Test::Unit::TestCase
80
80
  assert_equal 0, img[99, 99].a
81
81
  end
82
82
 
83
- def test_rect_rounded ()
83
+ def test_rect_rounded()
84
84
  img = image {rect 1, 1, 98, 98, 10, 10, 10, 10}
85
85
  assert_equal 0, img[ 0, 0].a
86
86
  assert_equal 0, img[ 1, 1].a
@@ -90,7 +90,7 @@ class TestPainterShape < Test::Unit::TestCase
90
90
  assert_equal 0, img[99, 99].a
91
91
  end
92
92
 
93
- def test_ellipse ()
93
+ def test_ellipse()
94
94
  img = image {ellipse 1, 1, 98, 98}
95
95
  assert_equal 0, img[ 0, 0].a
96
96
  assert_equal 1, img[50, 1].a