rays 0.1.19 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/rays/color_space.cpp +2 -2
- data/.doc/ext/rays/defs.cpp +11 -10
- data/.doc/ext/rays/point.cpp +0 -8
- data/VERSION +1 -1
- data/ext/rays/color_space.cpp +2 -2
- data/ext/rays/defs.cpp +11 -10
- data/ext/rays/point.cpp +0 -9
- data/lib/rays/autoinit.rb +1 -1
- data/lib/rays/bitmap.rb +3 -3
- data/lib/rays/bounds.rb +22 -22
- data/lib/rays/camera.rb +1 -1
- data/lib/rays/color.rb +13 -13
- data/lib/rays/color_space.rb +4 -4
- data/lib/rays/font.rb +2 -2
- data/lib/rays/image.rb +3 -3
- data/lib/rays/matrix.rb +3 -3
- data/lib/rays/module.rb +5 -5
- data/lib/rays/painter.rb +17 -17
- data/lib/rays/point.rb +11 -11
- data/lib/rays/polygon.rb +10 -10
- data/lib/rays/polygon_line.rb +4 -4
- data/lib/rays/polyline.rb +4 -4
- data/lib/rays/shader.rb +3 -3
- data/rays.gemspec +3 -3
- data/src/painter.cpp +11 -23
- data/test/helper.rb +2 -2
- data/test/test_bitmap.rb +7 -7
- data/test/test_bounds.rb +26 -26
- data/test/test_color.rb +19 -19
- data/test/test_color_space.rb +10 -10
- data/test/test_font.rb +6 -6
- data/test/test_image.rb +14 -14
- data/test/test_matrix.rb +20 -20
- data/test/test_painter.rb +18 -18
- data/test/test_painter_shape.rb +10 -10
- data/test/test_point.rb +20 -20
- data/test/test_polygon.rb +30 -30
- data/test/test_polygon_line.rb +13 -13
- data/test/test_polyline.rb +38 -38
- data/test/test_rays.rb +1 -1
- data/test/test_shader.rb +7 -7
- metadata +20 -20
data/lib/rays/polygon.rb
CHANGED
@@ -12,43 +12,43 @@ module Rays
|
|
12
12
|
|
13
13
|
include Enumerable
|
14
14
|
|
15
|
-
def initialize
|
15
|
+
def initialize(*args, loop: true)
|
16
16
|
setup args, loop
|
17
17
|
end
|
18
18
|
|
19
|
-
def transform
|
19
|
+
def transform(matrix = nil, &block)
|
20
20
|
lines = to_a
|
21
21
|
lines = lines.map {|line| line.transform matrix} if matrix
|
22
22
|
lines = block.call lines if block
|
23
|
-
self.class.new
|
23
|
+
self.class.new(*lines)
|
24
24
|
end
|
25
25
|
|
26
|
-
def intersects
|
26
|
+
def intersects(obj)
|
27
27
|
!(self & obj).empty?
|
28
28
|
end
|
29
29
|
|
30
|
-
def self.line
|
31
|
-
new
|
30
|
+
def self.line(*args, loop: false)
|
31
|
+
new(*args, loop: loop)
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.rect
|
34
|
+
def self.rect(
|
35
35
|
*args, round: nil, lt: nil, rt: nil, lb: nil, rb: nil, nsegment: nil)
|
36
36
|
|
37
37
|
create_rect args, round, lt, rt, lb, rb, nsegment
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.ellipse
|
40
|
+
def self.ellipse(
|
41
41
|
*args, center: nil, radius: nil, hole: nil, from: nil, to: nil,
|
42
42
|
nsegment: nil)
|
43
43
|
|
44
44
|
create_ellipse args, center, radius, hole, from, to, nsegment
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.curve
|
47
|
+
def self.curve(*args, loop: false)
|
48
48
|
create_curve args, loop
|
49
49
|
end
|
50
50
|
|
51
|
-
def self.bezier
|
51
|
+
def self.bezier(*args, loop: false)
|
52
52
|
create_bezier args, loop
|
53
53
|
end
|
54
54
|
|
data/lib/rays/polygon_line.rb
CHANGED
@@ -12,18 +12,18 @@ module Rays
|
|
12
12
|
|
13
13
|
class Line < Polyline
|
14
14
|
|
15
|
-
def initialize
|
15
|
+
def initialize(*points, loop: true, hole: false)
|
16
16
|
setup points, loop, hole
|
17
17
|
end
|
18
18
|
|
19
|
-
def transform
|
19
|
+
def transform(matrix = nil, loop: loop?, hole: hole?, &block)
|
20
20
|
points = to_a
|
21
21
|
points = points.map {|point| matrix * point} if matrix
|
22
22
|
points = block.call points if block
|
23
|
-
self.class.new
|
23
|
+
self.class.new(*points, loop: loop, hole: hole)
|
24
24
|
end
|
25
25
|
|
26
|
-
def inspect
|
26
|
+
def inspect()
|
27
27
|
"#<Rays::Polygon::Line #{to_a.join ', '}, loop: #{loop?}, hole: #{hole?}>"
|
28
28
|
end
|
29
29
|
|
data/lib/rays/polyline.rb
CHANGED
@@ -11,18 +11,18 @@ module Rays
|
|
11
11
|
|
12
12
|
include Enumerable
|
13
13
|
|
14
|
-
def initialize
|
14
|
+
def initialize(*points, loop: false)
|
15
15
|
setup points, loop
|
16
16
|
end
|
17
17
|
|
18
|
-
def transform
|
18
|
+
def transform(matrix = nil, loop: loop?, &block)
|
19
19
|
points = to_a
|
20
20
|
points = points.map {|point| matrix * point} if matrix
|
21
21
|
points = block.call points if block
|
22
|
-
self.class.new
|
22
|
+
self.class.new(*points, loop: loop)
|
23
23
|
end
|
24
24
|
|
25
|
-
def inspect
|
25
|
+
def inspect()
|
26
26
|
"#<Rays::Polyline #{to_a.join ', '}, loop: #{loop?}>"
|
27
27
|
end
|
28
28
|
|
data/lib/rays/shader.rb
CHANGED
@@ -10,16 +10,16 @@ module Rays
|
|
10
10
|
|
11
11
|
class Shader
|
12
12
|
|
13
|
-
def initialize
|
13
|
+
def initialize(source = nil, **uniforms, &block)
|
14
14
|
if source
|
15
15
|
setup source
|
16
|
-
uniform
|
16
|
+
uniform(**uniforms) unless uniforms.empty?
|
17
17
|
end
|
18
18
|
|
19
19
|
Xot::BlockUtil.instance_eval_or_block_call self, &block if block
|
20
20
|
end
|
21
21
|
|
22
|
-
def uniform
|
22
|
+
def uniform(name = nil, *args, **uniforms)
|
23
23
|
set_uniform name, *args if name
|
24
24
|
uniforms.each do |key, value|
|
25
25
|
set_uniform key, value
|
data/rays.gemspec
CHANGED
@@ -26,10 +26,10 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.homepage = "https://github.com/xord/rays"
|
27
27
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
|
-
s.required_ruby_version = '
|
29
|
+
s.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'xot', '~> 0.1.
|
32
|
-
s.add_runtime_dependency 'rucy', '~> 0.1.
|
31
|
+
s.add_runtime_dependency 'xot', '~> 0.1.23'
|
32
|
+
s.add_runtime_dependency 'rucy', '~> 0.1.23'
|
33
33
|
|
34
34
|
s.files = `git ls-files`.split $/
|
35
35
|
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename f}
|
data/src/painter.cpp
CHANGED
@@ -129,7 +129,7 @@ namespace Rays
|
|
129
129
|
GLint scissor_box[4];
|
130
130
|
|
131
131
|
GLboolean blend;
|
132
|
-
GLint
|
132
|
+
GLint blend_src_rgb, blend_src_alpha, blend_dst_rgb, blend_dst_alpha;
|
133
133
|
|
134
134
|
GLint framebuffer_binding;
|
135
135
|
|
@@ -143,8 +143,10 @@ namespace Rays
|
|
143
143
|
glGetIntegerv(GL_SCISSOR_BOX, scissor_box);
|
144
144
|
|
145
145
|
glGetBooleanv(GL_BLEND, &blend);
|
146
|
-
glGetIntegerv(
|
147
|
-
glGetIntegerv(
|
146
|
+
glGetIntegerv(GL_BLEND_SRC_RGB, &blend_src_rgb);
|
147
|
+
glGetIntegerv(GL_BLEND_SRC_ALPHA, &blend_src_alpha);
|
148
|
+
glGetIntegerv(GL_BLEND_DST_RGB, &blend_dst_rgb);
|
149
|
+
glGetIntegerv(GL_BLEND_DST_ALPHA, &blend_dst_alpha);
|
148
150
|
|
149
151
|
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &framebuffer_binding);
|
150
152
|
}
|
@@ -160,7 +162,8 @@ namespace Rays
|
|
160
162
|
glScissor(scissor_box[0], scissor_box[1], scissor_box[2], scissor_box[3]);
|
161
163
|
|
162
164
|
enable(GL_BLEND, blend);
|
163
|
-
|
165
|
+
glBlendFuncSeparate(
|
166
|
+
blend_src_rgb, blend_dst_rgb, blend_src_alpha, blend_dst_alpha);
|
164
167
|
|
165
168
|
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_binding);
|
166
169
|
}
|
@@ -230,7 +233,7 @@ namespace Rays
|
|
230
233
|
}
|
231
234
|
|
232
235
|
static const Shader&
|
233
|
-
|
236
|
+
get_default_shader_for_texture ()
|
234
237
|
{
|
235
238
|
static const Shader SHADER(
|
236
239
|
"varying vec4 " VARYING_TEXCOORD ";"
|
@@ -244,21 +247,6 @@ namespace Rays
|
|
244
247
|
return SHADER;
|
245
248
|
}
|
246
249
|
|
247
|
-
static const Shader&
|
248
|
-
get_default_shader_for_alpha_texture ()
|
249
|
-
{
|
250
|
-
static const Shader SHADER(
|
251
|
-
"varying vec4 " VARYING_TEXCOORD ";"
|
252
|
-
"varying vec4 " VARYING_COLOR ";"
|
253
|
-
"vec4 sampleTexture(vec2);"
|
254
|
-
"void main ()"
|
255
|
-
"{"
|
256
|
-
" vec4 color = sampleTexture(" VARYING_TEXCOORD ".xy);"
|
257
|
-
" gl_FragColor = vec4(v_Color.rgb, color.a);"
|
258
|
-
"}");
|
259
|
-
return SHADER;
|
260
|
-
}
|
261
|
-
|
262
250
|
|
263
251
|
struct Painter::Data
|
264
252
|
{
|
@@ -943,7 +931,7 @@ namespace Rays
|
|
943
931
|
TextureInfo texinfo(texture, src_x, src_y, src_x + src_w, src_y + src_h);
|
944
932
|
|
945
933
|
if (!shader)
|
946
|
-
shader = &
|
934
|
+
shader = &get_default_shader_for_texture();
|
947
935
|
|
948
936
|
draw_polygon(
|
949
937
|
painter, MODES, 0, 0, false, nostroke, points, 4, NULL, 0, texcoords,
|
@@ -1100,7 +1088,7 @@ namespace Rays
|
|
1100
1088
|
{
|
1101
1089
|
int bmp_w = std::max(texture.width(), tex_w);
|
1102
1090
|
int bmp_h = std::max(texture.height(), tex_h);
|
1103
|
-
self->text_image = Image(Bitmap(bmp_w, bmp_h
|
1091
|
+
self->text_image = Image(Bitmap(bmp_w, bmp_h), density);
|
1104
1092
|
}
|
1105
1093
|
|
1106
1094
|
if (!self->text_image)
|
@@ -1120,7 +1108,7 @@ namespace Rays
|
|
1120
1108
|
painter, self->text_image,
|
1121
1109
|
0, 0, str_w, str_h,
|
1122
1110
|
x, y, str_w, str_h,
|
1123
|
-
true, &
|
1111
|
+
true, &get_default_shader_for_texture());
|
1124
1112
|
|
1125
1113
|
debug_draw_text(painter, font, x, y, str_w / density, str_h / density);
|
1126
1114
|
}
|
data/test/helper.rb
CHANGED
data/test/test_bitmap.rb
CHANGED
@@ -9,20 +9,20 @@ class TestBitmap < Test::Unit::TestCase
|
|
9
9
|
W = 32
|
10
10
|
H = 16
|
11
11
|
|
12
|
-
def bitmap
|
12
|
+
def bitmap(w = W, h = H)
|
13
13
|
Rays::Bitmap.new w, h
|
14
14
|
end
|
15
15
|
|
16
|
-
def color
|
17
|
-
Rays::Color.new
|
16
|
+
def color(*args)
|
17
|
+
Rays::Color.new(*args)
|
18
18
|
end
|
19
19
|
|
20
|
-
def test_initialize
|
20
|
+
def test_initialize()
|
21
21
|
assert_equal W, bitmap.width
|
22
22
|
assert_equal H, bitmap.height
|
23
23
|
end
|
24
24
|
|
25
|
-
def test_dup
|
25
|
+
def test_dup()
|
26
26
|
o = bitmap
|
27
27
|
assert_equal color(0, 0, 0, 0), o[0, 0]
|
28
28
|
o[0, 0] = color(1, 0, 0, 0)
|
@@ -34,14 +34,14 @@ class TestBitmap < Test::Unit::TestCase
|
|
34
34
|
assert_equal color(1, 0, 0, 0), o[0, 0]
|
35
35
|
end
|
36
36
|
|
37
|
-
def test_at
|
37
|
+
def test_at()
|
38
38
|
o = bitmap
|
39
39
|
assert_equal color(0, 0, 0, 0), o[0, 0]
|
40
40
|
o[0, 0] = 1
|
41
41
|
assert_equal color(1, 1, 1, 1), o[0, 0]
|
42
42
|
end
|
43
43
|
|
44
|
-
def test_to_a
|
44
|
+
def test_to_a()
|
45
45
|
colors = %w[#f00 #0f0 #00f #ff0].map {|s| color s}
|
46
46
|
bmp = bitmap 2, 2
|
47
47
|
bmp[0, 0], bmp[1, 0], bmp[0, 1], bmp[1, 1] = colors
|
data/test/test_bounds.rb
CHANGED
@@ -6,15 +6,15 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestBounds < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def bounds
|
10
|
-
Rays::Bounds.new
|
9
|
+
def bounds(*args)
|
10
|
+
Rays::Bounds.new(*args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def point
|
14
|
-
Rays::Point.new
|
13
|
+
def point(*args)
|
14
|
+
Rays::Point.new(*args)
|
15
15
|
end
|
16
16
|
|
17
|
-
def test_initialize
|
17
|
+
def test_initialize()
|
18
18
|
assert_equal bounds(0, 0, 0, 0, 0, 0), bounds()
|
19
19
|
assert_equal bounds(0, 0, 0, 1, 1, 0), bounds(1)
|
20
20
|
assert_equal bounds(0, 0, 0, 1, 2, 0), bounds(1, 2)
|
@@ -25,7 +25,7 @@ class TestBounds < Test::Unit::TestCase
|
|
25
25
|
assert_raise(ArgumentError) {bounds(1, 2, 3, 4, 5, 6, 7)}
|
26
26
|
end
|
27
27
|
|
28
|
-
def test_dup
|
28
|
+
def test_dup()
|
29
29
|
o = bounds
|
30
30
|
assert_equal bounds(0, 0, 0, 0, 0, 0), o
|
31
31
|
o.x = 1
|
@@ -37,17 +37,17 @@ class TestBounds < Test::Unit::TestCase
|
|
37
37
|
assert_equal bounds(1, 0, 0, 0, 0, 0), o
|
38
38
|
end
|
39
39
|
|
40
|
-
def test_intersect?
|
40
|
+
def test_intersect?()
|
41
41
|
assert bounds(10, 20, 30, 100, 100, 100).intersect?(bounds 50, 60, 70, 100, 100, 100)
|
42
42
|
assert_not bounds(10, 20, 30, 10, 10, 10).intersect?(bounds 50, 60, 70, 100, 100, 100)
|
43
43
|
end
|
44
44
|
|
45
|
-
def test_include?
|
45
|
+
def test_include?()
|
46
46
|
assert bounds(10, 20, 30, 100, 100, 100).include?(point 50, 60)
|
47
47
|
assert_not bounds(10, 20, 30, 10, 10, 10).include?(point 50, 60)
|
48
48
|
end
|
49
49
|
|
50
|
-
def test_valid?
|
50
|
+
def test_valid?()
|
51
51
|
assert bounds(0, 0, 0, 0, 0, 0).valid?
|
52
52
|
assert bounds(0, 0, 0, 1, 0, 0).valid?
|
53
53
|
assert bounds(0, 0, 0, 0, 1, 0).valid?
|
@@ -57,7 +57,7 @@ class TestBounds < Test::Unit::TestCase
|
|
57
57
|
assert_not bounds(0, 0, 0, 0, 0, -1).valid?
|
58
58
|
end
|
59
59
|
|
60
|
-
def test_get_xyzwhd
|
60
|
+
def test_get_xyzwhd()
|
61
61
|
o = bounds 1, 2, 3, 4, 5, 6
|
62
62
|
assert_equal 1, o.x
|
63
63
|
assert_equal 2, o.y
|
@@ -70,7 +70,7 @@ class TestBounds < Test::Unit::TestCase
|
|
70
70
|
assert_equal 6, o.depth
|
71
71
|
end
|
72
72
|
|
73
|
-
def test_set_xyzwhd
|
73
|
+
def test_set_xyzwhd()
|
74
74
|
o = bounds
|
75
75
|
o.x = 1
|
76
76
|
assert_equal [1, 0, 0, 0, 0, 0], o.to_a(3)
|
@@ -92,7 +92,7 @@ class TestBounds < Test::Unit::TestCase
|
|
92
92
|
assert_equal [1, 2, 3, 7, 8, 9], o.to_a(3)
|
93
93
|
end
|
94
94
|
|
95
|
-
def test_get_ltbrbf
|
95
|
+
def test_get_ltbrbf()
|
96
96
|
o = bounds 1, 2, 3, 4, 5, 6
|
97
97
|
assert_equal 1, o.left
|
98
98
|
assert_equal 2, o.top
|
@@ -106,7 +106,7 @@ class TestBounds < Test::Unit::TestCase
|
|
106
106
|
assert_equal [4, 6], o.rb.to_a
|
107
107
|
end
|
108
108
|
|
109
|
-
def test_set_ltbrbf
|
109
|
+
def test_set_ltbrbf()
|
110
110
|
assert_equal [1, 0, 0, -1, 0, 0], bounds.tap {|o| o.left = 1}.to_a(3)
|
111
111
|
assert_equal [0, 2, 0, 0, -2, 0], bounds.tap {|o| o.top = 2}.to_a(3)
|
112
112
|
assert_equal [0, 0, 3, 0, 0, -3], bounds.tap {|o| o.back = 3}.to_a(3)
|
@@ -132,7 +132,7 @@ class TestBounds < Test::Unit::TestCase
|
|
132
132
|
assert_equal [10, 20, 0, 40, 50, 0], bounds(10, 20, 30, 40).tap {|o| o.rb += 10}.to_a(3)
|
133
133
|
end
|
134
134
|
|
135
|
-
def test_position
|
135
|
+
def test_position()
|
136
136
|
o = bounds 1, 2, 3, 4, 5, 6
|
137
137
|
assert_equal [ 1, 2, 3], o.position.to_a(3)
|
138
138
|
o.position = point 7, 8, 9
|
@@ -142,14 +142,14 @@ class TestBounds < Test::Unit::TestCase
|
|
142
142
|
assert_equal [10, 11, 12], o.pos.to_a(3)
|
143
143
|
end
|
144
144
|
|
145
|
-
def test_size
|
145
|
+
def test_size()
|
146
146
|
o = bounds 1, 2, 3, 4, 5, 6
|
147
147
|
assert_equal point(4, 5, 6), o.size
|
148
148
|
o.size = point 7, 8, 9
|
149
149
|
assert_equal point(7, 8, 9), o.size
|
150
150
|
end
|
151
151
|
|
152
|
-
def test_move_to
|
152
|
+
def test_move_to()
|
153
153
|
o = bounds 1, 2, 3, 4, 5, 6
|
154
154
|
assert_equal bounds(7, 2, 3, 4, 5, 6), o.move_to( 7)
|
155
155
|
assert_equal bounds(7, 8, 3, 4, 5, 6), o.move_to( 7, 8)
|
@@ -169,7 +169,7 @@ class TestBounds < Test::Unit::TestCase
|
|
169
169
|
assert_equal bounds( 7, 8, 9, 4, 5, 6), o1
|
170
170
|
end
|
171
171
|
|
172
|
-
def test_move_by
|
172
|
+
def test_move_by()
|
173
173
|
o = bounds 1, 2, 3, 4, 5, 6
|
174
174
|
assert_equal bounds( 8, 2, 3, 4, 5, 6), o.move_by( 7)
|
175
175
|
assert_equal bounds( 8, 10, 3, 4, 5, 6), o.move_by( 7, 8)
|
@@ -192,7 +192,7 @@ class TestBounds < Test::Unit::TestCase
|
|
192
192
|
assert_equal bounds( 8, 10, 12, 4, 5, 6), o1
|
193
193
|
end
|
194
194
|
|
195
|
-
def test_resize_to
|
195
|
+
def test_resize_to()
|
196
196
|
o = bounds 1, 2, 3, 4, 5, 6
|
197
197
|
assert_equal bounds(1, 2, 3, 7, 5, 6), o.resize_to( 7)
|
198
198
|
assert_equal bounds(1, 2, 3, 7, 8, 6), o.resize_to( 7, 8)
|
@@ -212,7 +212,7 @@ class TestBounds < Test::Unit::TestCase
|
|
212
212
|
assert_equal bounds(1, 2, 3, 7, 8, 9), o1
|
213
213
|
end
|
214
214
|
|
215
|
-
def test_resize_by
|
215
|
+
def test_resize_by()
|
216
216
|
o = bounds 1, 2, 3, 4, 5, 6
|
217
217
|
assert_equal bounds(1, 2, 3, 11, 5, 6), o.resize_by( 7)
|
218
218
|
assert_equal bounds(1, 2, 3, 11, 13, 6), o.resize_by( 7, 8)
|
@@ -235,7 +235,7 @@ class TestBounds < Test::Unit::TestCase
|
|
235
235
|
assert_equal bounds(1, 2, 3, 11, 13, 15), o1
|
236
236
|
end
|
237
237
|
|
238
|
-
def test_inset_by
|
238
|
+
def test_inset_by()
|
239
239
|
o = bounds 1, 2, 3, 20, 30, 40
|
240
240
|
assert_equal bounds(8, 2, 3, 6, 30, 40), o.inset_by( 7)
|
241
241
|
assert_equal bounds(8, 10, 3, 6, 14, 40), o.inset_by( 7, 8)
|
@@ -255,7 +255,7 @@ class TestBounds < Test::Unit::TestCase
|
|
255
255
|
assert_equal bounds( 8, 10, 12, 6, 14, 22), o1
|
256
256
|
end
|
257
257
|
|
258
|
-
def test_to_a
|
258
|
+
def test_to_a()
|
259
259
|
o = bounds 1, 2, 3, 4, 5, 6
|
260
260
|
assert_equal [1, 2, 4, 5], o.to_a
|
261
261
|
assert_equal [1, 4], o.to_a(1)
|
@@ -266,7 +266,7 @@ class TestBounds < Test::Unit::TestCase
|
|
266
266
|
assert_raise(ArgumentError) {o.to_a(4)}
|
267
267
|
end
|
268
268
|
|
269
|
-
def test_index
|
269
|
+
def test_index()
|
270
270
|
o = bounds 1, 2, 3, 4, 5, 6
|
271
271
|
assert_equal point(1, 2, 3), o[0]
|
272
272
|
assert_equal point(4, 5, 6), o[1]
|
@@ -274,7 +274,7 @@ class TestBounds < Test::Unit::TestCase
|
|
274
274
|
assert_raise(IndexError) {o[2]}
|
275
275
|
end
|
276
276
|
|
277
|
-
def test_index_assign
|
277
|
+
def test_index_assign()
|
278
278
|
o = bounds 1, 2, 3, 4, 5, 6
|
279
279
|
o[0] = point 7, 8, 9
|
280
280
|
assert_equal bounds(7, 8, 9, 4, 5, 6), o
|
@@ -284,7 +284,7 @@ class TestBounds < Test::Unit::TestCase
|
|
284
284
|
assert_raise(IndexError) {o[2]}
|
285
285
|
end
|
286
286
|
|
287
|
-
def test_compare
|
287
|
+
def test_compare()
|
288
288
|
o = bounds 1, 2, 3, 4, 5, 6
|
289
289
|
assert o == bounds(1, 2, 3, 4, 5, 6)
|
290
290
|
assert_not o != bounds(1, 2, 3, 4, 5, 6)
|
@@ -304,7 +304,7 @@ class TestBounds < Test::Unit::TestCase
|
|
304
304
|
assert o > bounds(1, 2, 3, 4, 5, 5)
|
305
305
|
end
|
306
306
|
|
307
|
-
def test_operators
|
307
|
+
def test_operators()
|
308
308
|
assert_equal bounds(50, 60, 70, 60, 60, 60), bounds(10, 20, 30, 100, 100, 100) & bounds(50, 60, 70, 100, 100, 100)
|
309
309
|
assert_equal bounds(10, 20, 30, 140, 140, 140), bounds(10, 20, 30, 100, 100, 100) | bounds(50, 60, 70, 100, 100, 100)
|
310
310
|
assert_equal bounds(10, 20, 30, 20, 20, 20), bounds(20, 30, 40, 10, 10, 10) | point(10, 20, 30)
|
@@ -313,7 +313,7 @@ class TestBounds < Test::Unit::TestCase
|
|
313
313
|
assert_equal point(0), (bounds(10, 20, 30, 10, 10, 10) & bounds(50, 60, 70, 10, 10, 10)).size
|
314
314
|
end
|
315
315
|
|
316
|
-
def test_invalid
|
316
|
+
def test_invalid()
|
317
317
|
o = Rays::Bounds.invalid
|
318
318
|
assert_not o.valid?
|
319
319
|
|
data/test/test_color.rb
CHANGED
@@ -6,19 +6,19 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestColor < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def color
|
10
|
-
Rays::Color.new
|
9
|
+
def color(*args)
|
10
|
+
Rays::Color.new(*args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def color8
|
14
|
-
color
|
13
|
+
def color8(r, g, b, a = 255, div = 255)
|
14
|
+
color(*[r, g, b, a].map {|n| n / div.to_f})
|
15
15
|
end
|
16
16
|
|
17
|
-
def hsv
|
18
|
-
Rays::Color.hsv
|
17
|
+
def hsv(*args)
|
18
|
+
Rays::Color.hsv(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
def test_initialize
|
21
|
+
def test_initialize()
|
22
22
|
assert_equal color(0, 0, 0, 1), color()
|
23
23
|
assert_equal color(1, 1, 1, 1), color(1)
|
24
24
|
assert_equal color(1, 1, 1, 2), color(1, 2)
|
@@ -28,7 +28,7 @@ class TestColor < Test::Unit::TestCase
|
|
28
28
|
assert_raise(ArgumentError) {color(1, 2, 3, 4, 5)}
|
29
29
|
end
|
30
30
|
|
31
|
-
def test_initialize_with_string
|
31
|
+
def test_initialize_with_string()
|
32
32
|
assert_equal color(0, 0, 0, 1), color('#000')
|
33
33
|
assert_equal color(0, 0, 0, 1), color('#000000')
|
34
34
|
assert_equal color(0, 0, 0, 0), color('#0000')
|
@@ -46,7 +46,7 @@ class TestColor < Test::Unit::TestCase
|
|
46
46
|
assert_raise(ArgumentError) {color '#0000000'}
|
47
47
|
end
|
48
48
|
|
49
|
-
def test_dup
|
49
|
+
def test_dup()
|
50
50
|
o = color
|
51
51
|
assert_equal color(0, 0, 0), o
|
52
52
|
o.red = 1
|
@@ -58,7 +58,7 @@ class TestColor < Test::Unit::TestCase
|
|
58
58
|
assert_equal color(1, 0, 0), o
|
59
59
|
end
|
60
60
|
|
61
|
-
def test_get_rgb
|
61
|
+
def test_get_rgb()
|
62
62
|
o = color 1, 2, 3, 4
|
63
63
|
assert_equal 1, o.red
|
64
64
|
assert_equal 2, o.green
|
@@ -66,7 +66,7 @@ class TestColor < Test::Unit::TestCase
|
|
66
66
|
assert_equal 4, o.alpha
|
67
67
|
end
|
68
68
|
|
69
|
-
def test_set_rgb
|
69
|
+
def test_set_rgb()
|
70
70
|
o = color
|
71
71
|
assert_equal [0, 0, 0, 1], o.to_a
|
72
72
|
o.red = 1
|
@@ -79,12 +79,12 @@ class TestColor < Test::Unit::TestCase
|
|
79
79
|
assert_equal [1, 2, 3, 4], o.to_a
|
80
80
|
end
|
81
81
|
|
82
|
-
def test_to_a
|
82
|
+
def test_to_a()
|
83
83
|
o = color 1, 2, 3, 4
|
84
84
|
assert_equal [1, 2, 3, 4], o.to_a
|
85
85
|
end
|
86
86
|
|
87
|
-
def test_index
|
87
|
+
def test_index()
|
88
88
|
o = color 1, 2, 3, 4
|
89
89
|
assert_equal 1, o[0]
|
90
90
|
assert_equal 2, o[1]
|
@@ -94,7 +94,7 @@ class TestColor < Test::Unit::TestCase
|
|
94
94
|
assert_raise(IndexError) {color[4]}
|
95
95
|
end
|
96
96
|
|
97
|
-
def test_index_assign
|
97
|
+
def test_index_assign()
|
98
98
|
o = color 1, 2, 3, 4
|
99
99
|
o[0] = 4
|
100
100
|
assert_equal [4, 2, 3, 4], o.to_a
|
@@ -108,7 +108,7 @@ class TestColor < Test::Unit::TestCase
|
|
108
108
|
assert_raise(IndexError) {color[ 4] = 8}
|
109
109
|
end
|
110
110
|
|
111
|
-
def test_compare
|
111
|
+
def test_compare()
|
112
112
|
o = color 1, 2, 3, 4
|
113
113
|
assert o == color(1, 2, 3, 4)
|
114
114
|
assert_not o != color(1, 2, 3, 4)
|
@@ -124,7 +124,7 @@ class TestColor < Test::Unit::TestCase
|
|
124
124
|
assert o > color(1, 2, 3, 3)
|
125
125
|
end
|
126
126
|
|
127
|
-
def test_hsv_hue
|
127
|
+
def test_hsv_hue()
|
128
128
|
assert_equal color(0.5, 0, 1), hsv(-0.25, 1, 1)
|
129
129
|
assert_equal color(1, 0, 0), hsv( 0, 1, 1)
|
130
130
|
assert_equal color(0.5, 1, 0), hsv( 0.25, 1, 1)
|
@@ -134,19 +134,19 @@ class TestColor < Test::Unit::TestCase
|
|
134
134
|
assert_equal color(0.5, 1, 0), hsv( 1.25, 1, 1)
|
135
135
|
end
|
136
136
|
|
137
|
-
def test_hsv_saturation
|
137
|
+
def test_hsv_saturation()
|
138
138
|
assert_equal color(1, 1, 1), hsv(1, 0, 1)
|
139
139
|
assert_equal color(1, 0.5, 0.5), hsv(1, 0.5, 1)
|
140
140
|
assert_equal color(1, 0, 0), hsv(1, 1, 1)
|
141
141
|
end
|
142
142
|
|
143
|
-
def test_hsv_value
|
143
|
+
def test_hsv_value()
|
144
144
|
assert_equal color(0, 0, 0), hsv(1, 1, 0)
|
145
145
|
assert_equal color(0.5, 0, 0), hsv(1, 1, 0.5)
|
146
146
|
assert_equal color(1, 0, 0), hsv(1, 1, 1)
|
147
147
|
end
|
148
148
|
|
149
|
-
def test_hsv_alpha
|
149
|
+
def test_hsv_alpha()
|
150
150
|
assert_equal color(1, 0, 0, 0), hsv(1, 1, 1, 0)
|
151
151
|
assert_equal color(1, 0, 0, 0.5), hsv(1, 1, 1, 0.5)
|
152
152
|
assert_equal color(1, 0, 0, 1), hsv(1, 1, 1, 1)
|
data/test/test_color_space.rb
CHANGED
@@ -6,8 +6,8 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestColorSpace < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def cs
|
10
|
-
Rays::ColorSpace.new
|
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?}
|