rays 0.1.11 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/test/test_color.rb
CHANGED
@@ -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
|
18
|
-
Rays::Color.
|
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
|
32
|
-
assert_equal color(0, 0, 0, 1),
|
33
|
-
assert_equal color(0, 0, 0, 1),
|
34
|
-
assert_equal color(0, 0, 0, 0),
|
35
|
-
assert_equal color(0, 0, 0, 0),
|
36
|
-
assert_equal color8(0x01, 0x23, 0x45, 0x67),
|
37
|
-
assert_equal color8(0x89, 0xab, 0xcd, 0xef),
|
38
|
-
assert_equal color8(0x0, 0x2, 0x4, 0x6, 15),
|
39
|
-
assert_equal color8(0x9, 0xb, 0xd, 0xf, 15),
|
40
|
-
assert_equal color(0, 0, 0, 1),
|
41
|
-
assert_raise(ArgumentError) {
|
42
|
-
assert_raise(ArgumentError) {
|
43
|
-
assert_raise(ArgumentError) {
|
44
|
-
assert_raise(ArgumentError) {
|
45
|
-
assert_raise(ArgumentError) {
|
46
|
-
assert_raise(ArgumentError) {
|
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
|
data/test/test_font.rb
CHANGED
data/test/test_image.rb
CHANGED
@@ -9,11 +9,11 @@ class TestImage < Test::Unit::TestCase
|
|
9
9
|
W = 10
|
10
10
|
H = 10
|
11
11
|
|
12
|
-
def
|
12
|
+
def image (w = W, h = H, *args)
|
13
13
|
Rays::Image.new w, h, *args
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
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,
|
26
|
-
assert_equal H,
|
25
|
+
assert_equal W, image.width
|
26
|
+
assert_equal H, image.height
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
|
31
|
-
assert_equal
|
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
|
35
|
-
assert_equal W,
|
36
|
-
assert_equal H,
|
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 =
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
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
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
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
|
data/test/test_matrix.rb
ADDED
@@ -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
|
data/test/test_painter.rb
CHANGED
@@ -14,50 +14,114 @@ class TestPainter < Test::Unit::TestCase
|
|
14
14
|
Rays::Font.new name, size
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
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
|
28
|
+
assert_equal color(1, 1, 1, 1), pa.background
|
25
29
|
pa.background = 0
|
26
|
-
assert_equal
|
27
|
-
pa.background
|
28
|
-
assert_equal
|
29
|
-
|
30
|
-
assert_equal
|
31
|
-
|
32
|
-
assert_equal
|
30
|
+
assert_equal color(0, 0, 0, 1), pa.background
|
31
|
+
pa.background 1
|
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
|
42
|
+
assert_equal color(1, 1, 1, 1), pa.fill
|
39
43
|
pa.fill = 0
|
40
|
-
assert_equal
|
41
|
-
pa.fill
|
42
|
-
assert_equal
|
43
|
-
|
44
|
-
assert_equal
|
45
|
-
|
46
|
-
assert_equal
|
44
|
+
assert_equal color(0, 0, 0, 1), pa.fill
|
45
|
+
pa.fill 1
|
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
|
56
|
+
assert_equal color(1, 1, 1, 1), pa.stroke
|
53
57
|
pa.stroke = 0
|
54
|
-
assert_equal
|
55
|
-
pa.stroke
|
56
|
-
assert_equal
|
57
|
-
|
58
|
-
assert_equal
|
59
|
-
|
60
|
-
assert_equal
|
58
|
+
assert_equal color(0, 0, 0, 1), pa.stroke
|
59
|
+
pa.stroke 1
|
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
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_stroke_width_accessor ()
|
68
|
+
pa = painter
|
69
|
+
assert_equal 0, pa.stroke_width
|
70
|
+
pa.stroke_width = 1
|
71
|
+
assert_equal 1, pa.stroke_width
|
72
|
+
pa.stroke_width = 0
|
73
|
+
assert_equal 0, pa.stroke_width
|
74
|
+
pa.stroke_width 2
|
75
|
+
assert_equal 2, pa.stroke_width
|
76
|
+
pa.push stroke_width: 3 do |_|
|
77
|
+
assert_equal 3, pa.stroke_width
|
78
|
+
end
|
79
|
+
assert_equal 2, pa.stroke_width
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_stroke_cap_accessor ()
|
83
|
+
pa = painter
|
84
|
+
assert_equal :butt, pa.stroke_cap
|
85
|
+
pa.stroke_cap = :round
|
86
|
+
assert_equal :round, pa.stroke_cap
|
87
|
+
pa.stroke_cap :square
|
88
|
+
assert_equal :square, pa.stroke_cap
|
89
|
+
pa.push stroke_cap: :butt do |_|
|
90
|
+
assert_equal :butt, pa.stroke_cap
|
91
|
+
end
|
92
|
+
assert_equal :square, pa.stroke_cap
|
93
|
+
assert_raise(ArgumentError) {pa.stroke_cap :foo}
|
94
|
+
assert_raise(ArgumentError) {pa.stroke_cap :BUTT}
|
95
|
+
assert_raise(ArgumentError) {pa.stroke_cap Rays::CAP_BUTT}# ToDo: accept this
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_stroke_join_accessor ()
|
99
|
+
pa = painter
|
100
|
+
assert_equal :miter, pa.stroke_join
|
101
|
+
pa.stroke_join = :round
|
102
|
+
assert_equal :round, pa.stroke_join
|
103
|
+
pa.stroke_join :square
|
104
|
+
assert_equal :square, pa.stroke_join
|
105
|
+
pa.push stroke_join: :miter do |_|
|
106
|
+
assert_equal :miter, pa.stroke_join
|
107
|
+
end
|
108
|
+
assert_equal :square, pa.stroke_join
|
109
|
+
assert_raise(ArgumentError) {pa.stroke_join :foo}
|
110
|
+
assert_raise(ArgumentError) {pa.stroke_join :MITER}
|
111
|
+
assert_raise(ArgumentError) {pa.stroke_join Rays::JOIN_MITER}# ToDo: accept this
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_miter_limit_accessor ()
|
115
|
+
pa = painter
|
116
|
+
assert_equal 2, pa.miter_limit
|
117
|
+
pa.miter_limit = 3
|
118
|
+
assert_equal 3, pa.miter_limit
|
119
|
+
pa.miter_limit 4
|
120
|
+
assert_equal 4, pa.miter_limit
|
121
|
+
pa.push miter_limit: 9 do |_|
|
122
|
+
assert_equal 9, pa.miter_limit
|
123
|
+
end
|
124
|
+
assert_equal 4, pa.miter_limit
|
61
125
|
end
|
62
126
|
|
63
127
|
def test_clip_accessor ()
|
@@ -66,11 +130,11 @@ class TestPainter < Test::Unit::TestCase
|
|
66
130
|
assert_equal [1, 2, 3, 4], pa.clip.to_a
|
67
131
|
pa.clip = [5, 6, 7, 8]
|
68
132
|
assert_equal [5, 6, 7, 8], pa.clip.to_a
|
69
|
-
pa.clip
|
133
|
+
pa.clip 1, 2, 3, 4
|
70
134
|
assert_equal [1, 2, 3, 4], pa.clip.to_a
|
71
|
-
|
135
|
+
pa.push clip: [5, 6, 7, 8] do |_|
|
72
136
|
assert_equal [5, 6, 7, 8], pa.clip.to_a
|
73
|
-
|
137
|
+
end
|
74
138
|
assert_equal [1, 2, 3, 4], pa.clip.to_a
|
75
139
|
end
|
76
140
|
|
@@ -81,11 +145,11 @@ class TestPainter < Test::Unit::TestCase
|
|
81
145
|
assert_equal f10, pa.font
|
82
146
|
pa.font = f20
|
83
147
|
assert_equal f20, pa.font
|
84
|
-
pa.font
|
148
|
+
pa.font f10
|
85
149
|
assert_equal f10, pa.font
|
86
|
-
|
150
|
+
pa.push font: f20 do |_|
|
87
151
|
assert_equal f20, pa.font
|
88
|
-
|
152
|
+
end
|
89
153
|
assert_equal f10, pa.font
|
90
154
|
end
|
91
155
|
|
@@ -100,30 +164,72 @@ class TestPainter < Test::Unit::TestCase
|
|
100
164
|
assert_equal 20, pa.font.size
|
101
165
|
end
|
102
166
|
|
103
|
-
def
|
167
|
+
def test_color_by_name ()
|
104
168
|
pa = painter
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
assert_equal
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
assert_equal
|
169
|
+
pa.fill = :rgb001
|
170
|
+
assert_equal color(0, 0, 1), pa.fill
|
171
|
+
pa.fill = [1, 0, 0]
|
172
|
+
assert_equal color(1, 0, 0), pa.fill
|
173
|
+
pa.fill 0, 1, 0
|
174
|
+
assert_equal color(0, 1, 0), pa.fill
|
175
|
+
pa.fill = '#f00'
|
176
|
+
assert_equal color(1, 0, 0), pa.fill
|
177
|
+
pa.fill '#0f0'
|
178
|
+
assert_equal color(0, 1, 0), pa.fill
|
179
|
+
pa.fill = '#ff0000'
|
180
|
+
assert_equal color(1, 0, 0), pa.fill
|
181
|
+
pa.fill '#00ff00'
|
182
|
+
assert_equal color(0, 1, 0), pa.fill
|
115
183
|
end
|
116
184
|
|
117
|
-
def
|
185
|
+
def test_push ()
|
118
186
|
pa = painter
|
119
|
-
pa.fill =
|
120
|
-
assert_equal
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
187
|
+
pa.fill = [1, 0, 0]
|
188
|
+
assert_equal color(1, 0, 0), pa.fill
|
189
|
+
|
190
|
+
pa.push :all do |_|
|
191
|
+
assert_equal color(1, 0, 0), pa.fill
|
192
|
+
pa.fill = [0, 1, 0]
|
193
|
+
assert_equal color(0, 1, 0), pa.fill
|
194
|
+
end
|
195
|
+
assert_equal color(1, 0, 0), pa.fill
|
196
|
+
|
197
|
+
pa.push :state do |_|
|
198
|
+
assert_equal color(1, 0, 0), pa.fill
|
199
|
+
pa.fill = [0, 1, 0]
|
200
|
+
assert_equal color(0, 1, 0), pa.fill
|
201
|
+
end
|
202
|
+
assert_equal color(1, 0, 0), pa.fill
|
203
|
+
|
204
|
+
pa.push :matrix do |_|
|
205
|
+
assert_equal color(1, 0, 0), pa.fill
|
206
|
+
pa.fill = [0, 1, 0]
|
207
|
+
assert_equal color(0, 1, 0), pa.fill
|
208
|
+
end
|
209
|
+
assert_equal color(0, 1, 0), pa.fill
|
210
|
+
|
211
|
+
pa.push fill: [0, 0, 1] do |_|
|
212
|
+
assert_equal color(0, 0, 1), pa.fill
|
213
|
+
pa.fill = [1, 0, 0]
|
214
|
+
assert_equal color(1, 0, 0), pa.fill
|
215
|
+
end
|
216
|
+
assert_equal color(0, 1, 0), pa.fill
|
217
|
+
|
218
|
+
pa.push stroke: [0, 0, 1] do |_|
|
219
|
+
assert_equal color(0, 1, 0), pa.fill
|
220
|
+
pa.fill = [1, 0, 0]
|
221
|
+
assert_equal color(1, 0, 0), pa.fill
|
222
|
+
end
|
223
|
+
assert_equal color(0, 1, 0), pa.fill
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_shader ()
|
227
|
+
img = Rays::Image.new(10, 10).paint {
|
228
|
+
shader "void main() {gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);}"
|
229
|
+
fill 1, 0, 0
|
230
|
+
rect bounds
|
231
|
+
}
|
232
|
+
assert_equal [0.0, 0.0, 1.0, 1.0], img[0, 0].to_a
|
127
233
|
end
|
128
234
|
|
129
235
|
end# TestPainter
|