rays 0.1.12 → 0.1.13

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.
Files changed (155) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/color.cpp +224 -45
  5. data/.doc/ext/rays/color_space.cpp +137 -45
  6. data/.doc/ext/rays/defs.cpp +183 -0
  7. data/.doc/ext/rays/font.cpp +39 -21
  8. data/.doc/ext/rays/image.cpp +26 -37
  9. data/.doc/ext/rays/matrix.cpp +186 -29
  10. data/.doc/ext/rays/native.cpp +12 -6
  11. data/.doc/ext/rays/noise.cpp +53 -0
  12. data/.doc/ext/rays/painter.cpp +120 -308
  13. data/.doc/ext/rays/point.cpp +82 -77
  14. data/.doc/ext/rays/polygon.cpp +287 -0
  15. data/.doc/ext/rays/polygon_line.cpp +96 -0
  16. data/.doc/ext/rays/polyline.cpp +161 -0
  17. data/.doc/ext/rays/rays.cpp +0 -13
  18. data/.doc/ext/rays/shader.cpp +83 -9
  19. data/README.md +1 -1
  20. data/Rakefile +21 -9
  21. data/VERSION +1 -1
  22. data/ext/rays/bitmap.cpp +22 -80
  23. data/ext/rays/bounds.cpp +100 -128
  24. data/ext/rays/color.cpp +232 -51
  25. data/ext/rays/color_space.cpp +140 -46
  26. data/ext/rays/defs.cpp +183 -0
  27. data/ext/rays/defs.h +26 -2
  28. data/ext/rays/extconf.rb +1 -2
  29. data/ext/rays/font.cpp +39 -22
  30. data/ext/rays/image.cpp +27 -39
  31. data/ext/rays/matrix.cpp +198 -30
  32. data/ext/rays/native.cpp +12 -6
  33. data/ext/rays/noise.cpp +55 -0
  34. data/ext/rays/painter.cpp +129 -315
  35. data/ext/rays/point.cpp +89 -81
  36. data/ext/rays/polygon.cpp +301 -0
  37. data/ext/rays/polygon_line.cpp +99 -0
  38. data/ext/rays/polyline.cpp +170 -0
  39. data/ext/rays/rays.cpp +0 -14
  40. data/ext/rays/shader.cpp +84 -9
  41. data/include/rays.h +10 -2
  42. data/include/rays/bitmap.h +14 -26
  43. data/include/rays/bounds.h +21 -4
  44. data/include/rays/color.h +25 -14
  45. data/include/rays/color_space.h +11 -8
  46. data/include/rays/coord.h +114 -0
  47. data/include/rays/debug.h +22 -0
  48. data/include/rays/defs.h +3 -0
  49. data/include/rays/font.h +4 -4
  50. data/include/rays/image.h +11 -17
  51. data/include/rays/matrix.h +50 -24
  52. data/include/rays/noise.h +42 -0
  53. data/include/rays/opengl.h +2 -50
  54. data/include/rays/painter.h +57 -99
  55. data/include/rays/point.h +44 -51
  56. data/include/rays/polygon.h +164 -0
  57. data/include/rays/polyline.h +65 -0
  58. data/include/rays/rays.h +3 -0
  59. data/include/rays/ruby.h +7 -1
  60. data/include/rays/ruby/bounds.h +1 -1
  61. data/include/rays/ruby/color.h +1 -1
  62. data/include/rays/ruby/color_space.h +1 -1
  63. data/include/rays/ruby/font.h +1 -1
  64. data/include/rays/ruby/matrix.h +1 -1
  65. data/include/rays/ruby/point.h +1 -1
  66. data/include/rays/ruby/polygon.h +52 -0
  67. data/include/rays/ruby/polyline.h +41 -0
  68. data/include/rays/ruby/shader.h +1 -1
  69. data/include/rays/shader.h +36 -8
  70. data/lib/rays.rb +6 -1
  71. data/lib/rays/bitmap.rb +0 -15
  72. data/lib/rays/bounds.rb +17 -23
  73. data/lib/rays/color.rb +20 -47
  74. data/lib/rays/color_space.rb +13 -13
  75. data/lib/rays/image.rb +2 -6
  76. data/lib/rays/matrix.rb +28 -0
  77. data/lib/rays/module.rb +4 -19
  78. data/lib/rays/painter.rb +60 -97
  79. data/lib/rays/point.rb +13 -21
  80. data/lib/rays/polygon.rb +50 -0
  81. data/lib/rays/polygon_line.rb +36 -0
  82. data/lib/rays/polyline.rb +32 -0
  83. data/lib/rays/shader.rb +20 -1
  84. data/rays.gemspec +5 -7
  85. data/src/bitmap.h +36 -0
  86. data/src/bounds.cpp +74 -11
  87. data/src/color.cpp +58 -23
  88. data/src/color_space.cpp +50 -32
  89. data/src/color_space.h +22 -0
  90. data/src/coord.cpp +170 -0
  91. data/src/coord.h +35 -0
  92. data/src/font.cpp +118 -0
  93. data/src/font.h +64 -0
  94. data/src/frame_buffer.cpp +37 -71
  95. data/src/frame_buffer.h +4 -4
  96. data/src/image.cpp +171 -97
  97. data/src/image.h +25 -0
  98. data/src/ios/bitmap.mm +107 -105
  99. data/src/ios/font.mm +48 -60
  100. data/src/ios/helper.h +2 -2
  101. data/src/ios/opengl.mm +19 -4
  102. data/src/ios/rays.mm +3 -0
  103. data/src/matrix.cpp +111 -26
  104. data/src/matrix.h +30 -0
  105. data/src/noise.cpp +74 -0
  106. data/src/opengl.cpp +9 -27
  107. data/src/opengl.h +37 -0
  108. data/src/osx/bitmap.mm +111 -106
  109. data/src/osx/font.mm +48 -61
  110. data/src/osx/helper.h +2 -2
  111. data/src/osx/opengl.mm +19 -83
  112. data/src/osx/rays.mm +3 -0
  113. data/src/painter.cpp +780 -696
  114. data/src/painter.h +24 -0
  115. data/src/point.cpp +140 -119
  116. data/src/polygon.cpp +1100 -0
  117. data/src/polygon.h +32 -0
  118. data/src/polyline.cpp +158 -0
  119. data/src/polyline.h +67 -0
  120. data/src/render_buffer.cpp +11 -4
  121. data/src/render_buffer.h +2 -2
  122. data/src/shader.cpp +163 -106
  123. data/src/shader.h +38 -0
  124. data/src/shader_program.cpp +533 -0
  125. data/src/{program.h → shader_program.h} +28 -16
  126. data/src/shader_source.cpp +140 -0
  127. data/src/shader_source.h +52 -0
  128. data/src/texture.cpp +136 -160
  129. data/src/texture.h +65 -0
  130. data/src/win32/bitmap.cpp +62 -52
  131. data/src/win32/font.cpp +11 -13
  132. data/src/win32/font.h +24 -0
  133. data/src/win32/gdi.h +6 -6
  134. data/test/helper.rb +0 -3
  135. data/test/test_bitmap.rb +31 -7
  136. data/test/test_bounds.rb +36 -0
  137. data/test/test_color.rb +59 -19
  138. data/test/test_color_space.rb +95 -0
  139. data/test/test_image.rb +24 -20
  140. data/test/test_matrix.rb +106 -0
  141. data/test/test_painter.rb +92 -46
  142. data/test/test_painter_shape.rb +57 -0
  143. data/test/test_point.rb +21 -0
  144. data/test/test_polygon.rb +234 -0
  145. data/test/test_polygon_line.rb +167 -0
  146. data/test/test_polyline.rb +145 -0
  147. data/test/test_shader.rb +9 -9
  148. metadata +88 -67
  149. data/.doc/ext/rays/texture.cpp +0 -138
  150. data/ext/rays/texture.cpp +0 -149
  151. data/include/rays/ruby/texture.h +0 -41
  152. data/include/rays/texture.h +0 -71
  153. data/lib/rays/texture.rb +0 -24
  154. data/src/program.cpp +0 -648
  155. data/test/test_texture.rb +0 -27
@@ -10,12 +10,12 @@ class TestColor < Test::Unit::TestCase
10
10
  Rays::Color.new *args
11
11
  end
12
12
 
13
- def color8 (r, g, b, a, div = 255)
13
+ def color8 (r, g, b, a = 255, div = 255)
14
14
  color *[r, g, b, a].map {|n| n / div.to_f}
15
15
  end
16
16
 
17
- def to_color (*args)
18
- Rays::Color.color *args
17
+ def hsv (*args)
18
+ Rays::Color.hsv *args
19
19
  end
20
20
 
21
21
  def test_initialize ()
@@ -28,22 +28,34 @@ class TestColor < Test::Unit::TestCase
28
28
  assert_raise(ArgumentError) {color(1, 2, 3, 4, 5)}
29
29
  end
30
30
 
31
- def test_color ()
32
- assert_equal color(0, 0, 0, 1), to_color('#000')
33
- assert_equal color(0, 0, 0, 1), to_color('#000000')
34
- assert_equal color(0, 0, 0, 0), to_color('#0000')
35
- assert_equal color(0, 0, 0, 0), to_color('#00000000')
36
- assert_equal color8(0x01, 0x23, 0x45, 0x67), to_color('#01234567')
37
- assert_equal color8(0x89, 0xab, 0xcd, 0xef), to_color('#89abcdef')
38
- assert_equal color8(0x0, 0x2, 0x4, 0x6, 15), to_color('#0246')
39
- assert_equal color8(0x9, 0xb, 0xd, 0xf, 15), to_color('#9bdf')
40
- assert_equal color(0, 0, 0, 1), to_color(' #000 ')
41
- assert_raise(ArgumentError) {to_color '#'}
42
- assert_raise(ArgumentError) {to_color '000'}
43
- assert_raise(ArgumentError) {to_color '#0'}
44
- assert_raise(ArgumentError) {to_color '#00'}
45
- assert_raise(ArgumentError) {to_color '#00000'}
46
- assert_raise(ArgumentError) {to_color '#0000000'}
31
+ def test_initialize_with_string ()
32
+ assert_equal color(0, 0, 0, 1), color('#000')
33
+ assert_equal color(0, 0, 0, 1), color('#000000')
34
+ assert_equal color(0, 0, 0, 0), color('#0000')
35
+ assert_equal color(0, 0, 0, 0), color('#00000000')
36
+ assert_equal color8(0x01, 0x23, 0x45, 0x67), color('#01234567')
37
+ assert_equal color8(0x89, 0xab, 0xcd, 0xef), color('#89abcdef')
38
+ assert_equal color8(0x0, 0x2, 0x4, 0x6, 15), color('#0246')
39
+ assert_equal color8(0x9, 0xb, 0xd, 0xf, 15), color('#9bdf')
40
+ assert_equal color(0, 0, 0, 1), color(' #000 ')
41
+ assert_raise(ArgumentError) {color '#'}
42
+ assert_raise(ArgumentError) {color '000'}
43
+ assert_raise(ArgumentError) {color '#0'}
44
+ assert_raise(ArgumentError) {color '#00'}
45
+ assert_raise(ArgumentError) {color '#00000'}
46
+ assert_raise(ArgumentError) {color '#0000000'}
47
+ end
48
+
49
+ def test_dup ()
50
+ o = color
51
+ assert_equal color(0, 0, 0), o
52
+ o.red = 1
53
+ assert_equal color(1, 0, 0), o
54
+ x = o.dup
55
+ assert_equal color(1, 0, 0), x
56
+ x.red = 2
57
+ assert_equal color(2, 0, 0), x
58
+ assert_equal color(1, 0, 0), o
47
59
  end
48
60
 
49
61
  def test_get_rgb ()
@@ -112,4 +124,32 @@ class TestColor < Test::Unit::TestCase
112
124
  assert o > color(1, 2, 3, 3)
113
125
  end
114
126
 
127
+ def test_hsv_hue ()
128
+ assert_equal color(0.5, 0, 1), hsv(-0.25, 1, 1)
129
+ assert_equal color(1, 0, 0), hsv( 0, 1, 1)
130
+ assert_equal color(0.5, 1, 0), hsv( 0.25, 1, 1)
131
+ assert_equal color(0, 1, 1), hsv( 0.5, 1, 1)
132
+ assert_equal color(0.5, 0, 1), hsv( 0.75, 1, 1)
133
+ assert_equal color(1, 0, 0), hsv( 1, 1, 1)
134
+ assert_equal color(0.5, 1, 0), hsv( 1.25, 1, 1)
135
+ end
136
+
137
+ def test_hsv_saturation ()
138
+ assert_equal color(1, 1, 1), hsv(1, 0, 1)
139
+ assert_equal color(1, 0.5, 0.5), hsv(1, 0.5, 1)
140
+ assert_equal color(1, 0, 0), hsv(1, 1, 1)
141
+ end
142
+
143
+ def test_hsv_value ()
144
+ assert_equal color(0, 0, 0), hsv(1, 1, 0)
145
+ assert_equal color(0.5, 0, 0), hsv(1, 1, 0.5)
146
+ assert_equal color(1, 0, 0), hsv(1, 1, 1)
147
+ end
148
+
149
+ def test_hsv_alpha ()
150
+ assert_equal color(1, 0, 0, 0), hsv(1, 1, 1, 0)
151
+ assert_equal color(1, 0, 0, 0.5), hsv(1, 1, 1, 0.5)
152
+ assert_equal color(1, 0, 0, 1), hsv(1, 1, 1, 1)
153
+ end
154
+
115
155
  end# TestColor
@@ -0,0 +1,95 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestColorSpace < Test::Unit::TestCase
8
+
9
+ def cs (*args)
10
+ Rays::ColorSpace.new *args
11
+ end
12
+
13
+ TYPES = %w[
14
+ gray alpha
15
+ rgb bgr
16
+ rgba bgra
17
+ rgbx bgrx
18
+ argb abgr
19
+ xrgb xbgr
20
+ rgb_float bgr_float
21
+ rgba_float bgra_float
22
+ argb_float abgr_float
23
+ ]
24
+
25
+ TYPES.each do |type|
26
+ define_method type do
27
+ cs type
28
+ end
29
+ end
30
+
31
+ alias rgb_f rgb_float
32
+ alias rgba_f rgba_float
33
+ alias argb_f argb_float
34
+ alias bgr_f bgr_float
35
+ alias bgra_f bgra_float
36
+ alias abgr_f abgr_float
37
+
38
+ def all ()
39
+ [
40
+ gray, alpha,
41
+ rgb, bgr, rgba, bgra, rgbx, bgrx, argb, abgr, xrgb, xbgr,
42
+ rgb_f, bgr_f, rgba_f, bgra_f, argb_f, abgr_f
43
+ ]
44
+ end
45
+
46
+ def test_gray? ()
47
+ grays = [gray]
48
+ others = all - grays
49
+ grays .each {|t| assert_equal true, t.gray?}
50
+ others.each {|t| assert_equal false, t.gray?}
51
+ end
52
+
53
+ def test_alpha? ()
54
+ alphas = [alpha]
55
+ others = all - alphas
56
+ alphas.each {|t| assert_equal true, t.alpha?}
57
+ others.each {|t| assert_equal false, t.alpha?}
58
+ end
59
+
60
+ def test_rgb? ()
61
+ rgbs = [rgb, rgba, rgbx, argb, xrgb, rgb_f, rgba_f, argb_f]
62
+ others = all - rgbs
63
+ rgbs .each {|t| assert_equal true, t.rgb?}
64
+ others.each {|t| assert_equal false, t.rgb?}
65
+ end
66
+
67
+ def test_bgr? ()
68
+ bgrs = [bgr, bgra, bgrx, abgr, xbgr, bgr_f, bgra_f, abgr_f]
69
+ others = all - bgrs
70
+ bgrs .each {|t| assert_equal true, t.bgr?}
71
+ others.each {|t| assert_equal false, t.bgr?}
72
+ end
73
+
74
+ def test_float? ()
75
+ floats = [rgb_f, rgba_f, argb_f, bgr_f, bgra_f, abgr_f]
76
+ others = all - floats
77
+ floats.each {|t| assert_equal true, t.float?}
78
+ others.each {|t| assert_equal false, t.float?}
79
+ end
80
+
81
+ def test_has_alpha? ()
82
+ alphas = [alpha, rgba, argb, bgra, abgr, rgba_f, argb_f, bgra_f, abgr_f]
83
+ others = all - alphas
84
+ alphas.each {|t| assert_equal true, t.has_alpha?}
85
+ others.each {|t| assert_equal false, t.has_alpha?}
86
+ end
87
+
88
+ def test_has_skip? ()
89
+ skips = [rgbx, xrgb, bgrx, xbgr]
90
+ others = all - skips
91
+ skips.each {|t| assert_equal true, t.has_skip?}
92
+ others.each {|t| assert_equal false, t.has_skip?}
93
+ end
94
+
95
+ end# TestColorSpace
@@ -9,11 +9,11 @@ class TestImage < Test::Unit::TestCase
9
9
  W = 10
10
10
  H = 10
11
11
 
12
- def img (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 rgb (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
 
@@ -22,25 +22,32 @@ class TestImage < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_initialize ()
25
- assert_equal W, img.width
26
- assert_equal H, img.height
25
+ assert_equal W, image.width
26
+ assert_equal H, image.height
27
27
  end
28
28
 
29
- def test_bitmap ()
30
- assert_equal W, img.bitmap.width
31
- assert_equal H, img.bitmap.height
29
+ def test_dup ()
30
+ o = image
31
+ assert_equal color(0, 0, 0, 0), o[0, 0]
32
+ o[0, 0] = color(1, 0, 0, 0)
33
+ assert_equal color(1, 0, 0, 0), o[0, 0]
34
+ x = o.dup
35
+ assert_equal color(1, 0, 0, 0), x[0, 0]
36
+ x[0, 0] = color(0, 1, 0, 0)
37
+ assert_equal color(0, 1, 0, 0), x[0, 0]
38
+ assert_equal color(1, 0, 0, 0), o[0, 0]
32
39
  end
33
40
 
34
- def test_texture ()
35
- assert_equal W, img.texture.width
36
- assert_equal H, img.texture.height
41
+ def test_bitmap ()
42
+ assert_equal W, image.bitmap.width
43
+ assert_equal H, image.bitmap.height
37
44
  end
38
45
 
39
46
  def test_painter ()
40
- pa = img.painter
41
- assert_equal rgb(0, 0, 0, 0), pa.background
42
- assert_equal rgb(1, 1, 1, 1), pa.fill
43
- assert_equal rgb(1, 1, 1, 0), pa.stroke
47
+ pa = image.painter
48
+ assert_equal color(0, 0, 0, 0), pa.background
49
+ assert_equal color(1, 1, 1, 1), pa.fill
50
+ assert_equal color(1, 1, 1, 0), pa.stroke
44
51
  assert_equal bounds(0, 0, -1, -1), pa.clip
45
52
  assert_equal Rays::Font.new, pa.font
46
53
  end
@@ -59,14 +66,11 @@ class TestImage < Test::Unit::TestCase
59
66
  fill(&block).bitmap.to_a.reject {|o| o.transparent?}.uniq.size > 0
60
67
  end
61
68
 
62
- assert_equal rgb(0, 0, 0, 0), fill {|p| p.rect 1, 1, 8, 8}[0, 0]
63
- assert_equal rgb(1, 0, 0, 1), fill {|p| p.rect 1, 1, 8, 8}[1, 1]
64
- assert_equal rgb(1, 0, 0, 1), stroke {|p| p.line 0, 0, 1, 1}[0, 0]
69
+ assert_equal color(0, 0, 0, 0), fill {|p| p.rect 1, 1, 8, 8}[0, 0]
70
+ assert_equal color(1, 0, 0, 1), fill {|p| p.rect 1, 1, 8, 8}[1, 1]
71
+ assert_equal color(1, 0, 0, 1), stroke {|p| p.line 0, 0, 1, 1}[0, 0]
65
72
 
66
73
  assert drawn {|p| p.text "a"}
67
74
  end
68
75
 
69
- def test_dirty ()
70
- end
71
-
72
76
  end# TestImage
@@ -0,0 +1,106 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ require_relative 'helper'
5
+
6
+
7
+ class TestMatrix < Test::Unit::TestCase
8
+
9
+ def matrix (*args)
10
+ Rays::Matrix.new *args
11
+ end
12
+
13
+ def mat_str (str)
14
+ matrix *str.split(/\s*/).map(&:to_f)
15
+ end
16
+
17
+ def translate (*args)
18
+ Rays::Matrix.translate *args
19
+ end
20
+
21
+ def scale (*args)
22
+ Rays::Matrix.scale *args
23
+ end
24
+
25
+ def rotate (*args)
26
+ Rays::Matrix.rotate *args
27
+ end
28
+
29
+ def point (*args)
30
+ Rays::Point.new *args
31
+ end
32
+
33
+ def test_initialize ()
34
+ assert_equal mat_str('1000 0100 0010 0001'), matrix
35
+ assert_equal mat_str('0000 0000 0000 0000'), matrix(0)
36
+ assert_equal mat_str('2000 0200 0020 0002'), matrix(2)
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
+ (2..15).each do |n|
39
+ assert_raise(ArgumentError) {matrix *[0] * n}
40
+ end
41
+ end
42
+
43
+ def test_dup ()
44
+ o = matrix
45
+ assert_equal mat_str('1000 0100 0010 0001'), o
46
+ o[0, 0] = 9
47
+ assert_equal mat_str('9000 0100 0010 0001'), o
48
+ x = o.dup
49
+ assert_equal mat_str('9000 0100 0010 0001'), x
50
+ x[0, 0] = 5
51
+ assert_equal mat_str('5000 0100 0010 0001'), x
52
+ assert_equal mat_str('9000 0100 0010 0001'), o
53
+ end
54
+
55
+ def test_mult ()
56
+ assert_equal point(2, 3), scale(2, 3) * point(1, 1)
57
+
58
+ assert_kind_of Rays::Point, matrix * point
59
+ assert_kind_of Rays::Point, matrix * [1]
60
+ assert_kind_of Rays::Point, matrix * [1, 2]
61
+ assert_kind_of Rays::Point, matrix * [1, 2, 3]
62
+
63
+ assert_kind_of Rays::Matrix, matrix * matrix
64
+ assert_kind_of Rays::Matrix, matrix * ([0] * 16)
65
+
66
+ (4..15).each do |narg|
67
+ assert_raise(ArgumentError) {matrix * ([0] * narg)}
68
+ end
69
+ end
70
+
71
+ def test_get_at ()
72
+ o = mat_str '1234 5678 9876 5432'
73
+ assert_equal 1, o[0, 0]
74
+ assert_equal 2, o[0, 1]
75
+ end
76
+
77
+ def test_set_at ()
78
+ o = mat_str '1234 5678 9876 5432'
79
+ assert_equal 1, o[0, 0]
80
+ o[0, 0] = 10
81
+ assert_equal 10, o[0, 0]
82
+ end
83
+
84
+ def test_compare ()
85
+ o = matrix 1
86
+ assert o == mat_str('1000 0100 0010 0001')
87
+ assert_not o != mat_str('1000 0100 0010 0001')
88
+
89
+ assert o < matrix(2)
90
+ assert o > matrix(0)
91
+ end
92
+
93
+ def test_transform ()
94
+ assert_equal mat_str('1001 0102 0013 0001'), translate(1, 2, 3)
95
+ assert_equal mat_str('2000 0300 0040 0001'), scale(2, 3, 4)
96
+
97
+ assert_equal point(2, 3, 3), translate(1, 2, 3) * point(1, 1)
98
+ assert_equal point(2, 2, 0), scale(2, 2) * point(1, 1)
99
+
100
+ assert (rotate(90) * point(1, 0, 0)).y > 0.99
101
+ assert (rotate(90, 0, 0, 1) * point(1, 0, 0)).y > 0.99
102
+ assert (rotate(90, 0, 1, 0) * point(0, 0, 1)).x > 0.99
103
+ assert (rotate(90, 1, 0, 0) * point(0, 1, 0)).z > 0.99
104
+ end
105
+
106
+ end# TestMatrix
@@ -14,50 +14,54 @@ class TestPainter < Test::Unit::TestCase
14
14
  Rays::Font.new name, size
15
15
  end
16
16
 
17
- def rgb (*args)
17
+ def color (*args)
18
18
  Rays::Color.new *args
19
19
  end
20
20
 
21
+ def setup ()
22
+ Rays::Color.set_palette_color :rgb001, color(0, 0, 1)
23
+ end
24
+
21
25
  def test_background_accessor ()
22
26
  pa = painter
23
27
  pa.background = 1
24
- assert_equal rgb(1, 1, 1, 1), pa.background
28
+ assert_equal color(1, 1, 1, 1), pa.background
25
29
  pa.background = 0
26
- assert_equal rgb(0, 0, 0, 1), pa.background
30
+ assert_equal color(0, 0, 0, 1), pa.background
27
31
  pa.background 1
28
- assert_equal rgb(1, 1, 1, 1), pa.background
29
- assert_equal rgb(1, 1, 1, 1), pa.background(0) {|_|
30
- assert_equal rgb(0, 0, 0, 1), pa.background
31
- }
32
- assert_equal rgb(1, 1, 1, 1), pa.background
32
+ assert_equal color(1, 1, 1, 1), pa.background
33
+ pa.push background: 0 do |_|
34
+ assert_equal color(0, 0, 0, 1), pa.background
35
+ end
36
+ assert_equal color(1, 1, 1, 1), pa.background
33
37
  end
34
38
 
35
39
  def test_fill_accessor ()
36
40
  pa = painter
37
41
  pa.fill = 1
38
- assert_equal rgb(1, 1, 1, 1), pa.fill
42
+ assert_equal color(1, 1, 1, 1), pa.fill
39
43
  pa.fill = 0
40
- assert_equal rgb(0, 0, 0, 1), pa.fill
44
+ assert_equal color(0, 0, 0, 1), pa.fill
41
45
  pa.fill 1
42
- assert_equal rgb(1, 1, 1, 1), pa.fill
43
- assert_equal rgb(1, 1, 1, 1), pa.fill(0) {|_|
44
- assert_equal rgb(0, 0, 0, 1), pa.fill
45
- }
46
- assert_equal rgb(1, 1, 1, 1), pa.fill
46
+ assert_equal color(1, 1, 1, 1), pa.fill
47
+ pa.push fill: 0 do |_|
48
+ assert_equal color(0, 0, 0, 1), pa.fill
49
+ end
50
+ assert_equal color(1, 1, 1, 1), pa.fill
47
51
  end
48
52
 
49
53
  def test_stroke_accessor ()
50
54
  pa = painter
51
55
  pa.stroke = 1
52
- assert_equal rgb(1, 1, 1, 1), pa.stroke
56
+ assert_equal color(1, 1, 1, 1), pa.stroke
53
57
  pa.stroke = 0
54
- assert_equal rgb(0, 0, 0, 1), pa.stroke
58
+ assert_equal color(0, 0, 0, 1), pa.stroke
55
59
  pa.stroke 1
56
- assert_equal rgb(1, 1, 1, 1), pa.stroke
57
- assert_equal rgb(1, 1, 1, 1), pa.stroke(0) {|_|
58
- assert_equal rgb(0, 0, 0, 1), pa.stroke
59
- }
60
- assert_equal rgb(1, 1, 1, 1), pa.stroke
60
+ assert_equal color(1, 1, 1, 1), pa.stroke
61
+ pa.push stroke: 0 do |_|
62
+ assert_equal color(0, 0, 0, 1), pa.stroke
63
+ end
64
+ assert_equal color(1, 1, 1, 1), pa.stroke
61
65
  end
62
66
 
63
67
  def test_clip_accessor ()
@@ -68,9 +72,9 @@ class TestPainter < Test::Unit::TestCase
68
72
  assert_equal [5, 6, 7, 8], pa.clip.to_a
69
73
  pa.clip 1, 2, 3, 4
70
74
  assert_equal [1, 2, 3, 4], pa.clip.to_a
71
- assert_equal [1, 2, 3, 4], pa.clip(5, 6, 7, 8) {|_|
75
+ pa.push clip: [5, 6, 7, 8] do |_|
72
76
  assert_equal [5, 6, 7, 8], pa.clip.to_a
73
- }.to_a
77
+ end
74
78
  assert_equal [1, 2, 3, 4], pa.clip.to_a
75
79
  end
76
80
 
@@ -83,9 +87,9 @@ class TestPainter < Test::Unit::TestCase
83
87
  assert_equal f20, pa.font
84
88
  pa.font f10
85
89
  assert_equal f10, pa.font
86
- assert_equal f10, pa.font(f20) {|_|
90
+ pa.push font: f20 do |_|
87
91
  assert_equal f20, pa.font
88
- }
92
+ end
89
93
  assert_equal f10, pa.font
90
94
  end
91
95
 
@@ -100,30 +104,72 @@ class TestPainter < Test::Unit::TestCase
100
104
  assert_equal 20, pa.font.size
101
105
  end
102
106
 
103
- def test_color_accessor ()
107
+ def test_color_by_name ()
104
108
  pa = painter
105
- f1, f2, s1, s2 = rgb(1, 0, 0), rgb(0, 1, 0), rgb(1, 0, 1), rgb(0, 1, 1)
106
- pa.color f1, s1
107
- assert_equal f1, pa.fill
108
- assert_equal s1, pa.stroke
109
- assert_equal [f1, s1], pa.color(f2, s2) {|_|
110
- assert_equal f2, pa.fill
111
- assert_equal s2, pa.stroke
112
- }
113
- assert_equal f1, pa.fill
114
- assert_equal s1, pa.stroke
109
+ pa.fill = :rgb001
110
+ assert_equal color(0, 0, 1), pa.fill
111
+ pa.fill = [1, 0, 0]
112
+ assert_equal color(1, 0, 0), pa.fill
113
+ pa.fill 0, 1, 0
114
+ assert_equal color(0, 1, 0), pa.fill
115
+ pa.fill = '#f00'
116
+ assert_equal color(1, 0, 0), pa.fill
117
+ pa.fill '#0f0'
118
+ assert_equal color(0, 1, 0), pa.fill
119
+ pa.fill = '#ff0000'
120
+ assert_equal color(1, 0, 0), pa.fill
121
+ pa.fill '#00ff00'
122
+ assert_equal color(0, 1, 0), pa.fill
115
123
  end
116
124
 
117
- def test_color_by_name ()
125
+ def test_push ()
118
126
  pa = painter
119
- pa.fill = [1, 0, 0]
120
- assert_equal rgb(1, 0, 0), pa.fill
121
- pa.fill = :red
122
- assert_equal rgb(1, 0, 0), pa.fill
123
- pa.fill = '#f00'
124
- assert_equal rgb(1, 0, 0), pa.fill
125
- pa.fill = '#ff0000'
126
- assert_equal rgb(1, 0, 0), pa.fill
127
+ pa.fill = [1, 0, 0]
128
+ assert_equal color(1, 0, 0), pa.fill
129
+
130
+ pa.push :all do |_|
131
+ assert_equal color(1, 0, 0), pa.fill
132
+ pa.fill = [0, 1, 0]
133
+ assert_equal color(0, 1, 0), pa.fill
134
+ end
135
+ assert_equal color(1, 0, 0), pa.fill
136
+
137
+ pa.push :state do |_|
138
+ assert_equal color(1, 0, 0), pa.fill
139
+ pa.fill = [0, 1, 0]
140
+ assert_equal color(0, 1, 0), pa.fill
141
+ end
142
+ assert_equal color(1, 0, 0), pa.fill
143
+
144
+ pa.push :matrix do |_|
145
+ assert_equal color(1, 0, 0), pa.fill
146
+ pa.fill = [0, 1, 0]
147
+ assert_equal color(0, 1, 0), pa.fill
148
+ end
149
+ assert_equal color(0, 1, 0), pa.fill
150
+
151
+ pa.push fill: [0, 0, 1] do |_|
152
+ assert_equal color(0, 0, 1), pa.fill
153
+ pa.fill = [1, 0, 0]
154
+ assert_equal color(1, 0, 0), pa.fill
155
+ end
156
+ assert_equal color(0, 1, 0), pa.fill
157
+
158
+ pa.push stroke: [0, 0, 1] do |_|
159
+ assert_equal color(0, 1, 0), pa.fill
160
+ pa.fill = [1, 0, 0]
161
+ assert_equal color(1, 0, 0), pa.fill
162
+ end
163
+ assert_equal color(0, 1, 0), pa.fill
164
+ end
165
+
166
+ def test_shader ()
167
+ img = Rays::Image.new(10, 10).paint {
168
+ shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
169
+ fill 1, 0, 0
170
+ rect bounds
171
+ }
172
+ assert_equal [0.0, 0.0, 1.0, 1.0], img[0, 0].to_a
127
173
  end
128
174
 
129
175
  end# TestPainter