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/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
|
10
|
-
Rays::Font.new
|
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
|
12
|
+
def image(w = W, h = H, *args)
|
13
13
|
Rays::Image.new w, h, *args
|
14
14
|
end
|
15
15
|
|
16
|
-
def color
|
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
|
21
|
-
Rays::Bounds.new
|
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
|
57
|
-
Rays::Image.new(10, 10).paint
|
55
|
+
def test_paint()
|
56
|
+
def paint(&block)
|
57
|
+
Rays::Image.new(10, 10).paint(&block)
|
58
58
|
end
|
59
|
-
def fill
|
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
|
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
|
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
|
10
|
-
Rays::Matrix.new
|
9
|
+
def matrix(*args)
|
10
|
+
Rays::Matrix.new(*args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def mat_str
|
14
|
-
matrix
|
13
|
+
def mat_str(str)
|
14
|
+
matrix(*str.split(/\s*/).map(&:to_f))
|
15
15
|
end
|
16
16
|
|
17
|
-
def translate
|
18
|
-
Rays::Matrix.translate
|
17
|
+
def translate(*args)
|
18
|
+
Rays::Matrix.translate(*args)
|
19
19
|
end
|
20
20
|
|
21
|
-
def scale
|
22
|
-
Rays::Matrix.scale
|
21
|
+
def scale(*args)
|
22
|
+
Rays::Matrix.scale(*args)
|
23
23
|
end
|
24
24
|
|
25
|
-
def rotate
|
26
|
-
Rays::Matrix.rotate
|
25
|
+
def rotate(*args)
|
26
|
+
Rays::Matrix.rotate(*args)
|
27
27
|
end
|
28
28
|
|
29
|
-
def point
|
30
|
-
Rays::Point.new
|
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
|
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
|
13
|
+
def font(name = nil, size = nil)
|
14
14
|
Rays::Font.new name, size
|
15
15
|
end
|
16
16
|
|
17
|
-
def color
|
18
|
-
Rays::Color.new
|
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
|
data/test/test_painter_shape.rb
CHANGED
@@ -6,19 +6,19 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestPainterShape < 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 image
|
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
|
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
|
data/test/test_point.rb
CHANGED
@@ -6,11 +6,11 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestPoint < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def point
|
10
|
-
Rays::Point.new
|
9
|
+
def point(*args)
|
10
|
+
Rays::Point.new(*args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def test_initialize
|
13
|
+
def test_initialize()
|
14
14
|
assert_equal point(0, 0, 0), point()
|
15
15
|
assert_equal point(1, 1, 0), point(1)
|
16
16
|
assert_equal point(1, 2, 0), point(1, 2)
|
@@ -18,7 +18,7 @@ class TestPoint < Test::Unit::TestCase
|
|
18
18
|
assert_raise(ArgumentError) {point(1, 2, 3, 4)}
|
19
19
|
end
|
20
20
|
|
21
|
-
def test_dup
|
21
|
+
def test_dup()
|
22
22
|
o = point
|
23
23
|
assert_equal point(0, 0, 0), o
|
24
24
|
o.x = 1
|
@@ -30,14 +30,14 @@ class TestPoint < Test::Unit::TestCase
|
|
30
30
|
assert_equal point(1, 0, 0), o
|
31
31
|
end
|
32
32
|
|
33
|
-
def test_get_xyz
|
33
|
+
def test_get_xyz()
|
34
34
|
o = point 1, 2, 3
|
35
35
|
assert_equal 1, o.x
|
36
36
|
assert_equal 2, o.y
|
37
37
|
assert_equal 3, o.z
|
38
38
|
end
|
39
39
|
|
40
|
-
def test_set_xyz
|
40
|
+
def test_set_xyz()
|
41
41
|
o = point
|
42
42
|
o.x = 1
|
43
43
|
assert_equal [1, 0, 0], o.to_a(3)
|
@@ -47,7 +47,7 @@ class TestPoint < Test::Unit::TestCase
|
|
47
47
|
assert_equal [1, 2, 3], o.to_a(3)
|
48
48
|
end
|
49
49
|
|
50
|
-
def test_move_to
|
50
|
+
def test_move_to()
|
51
51
|
o = point 1, 2, 3
|
52
52
|
assert_equal point(4, 2, 3), o.move_to( 4)
|
53
53
|
assert_equal point(4, 5, 3), o.move_to( 4, 5)
|
@@ -67,7 +67,7 @@ class TestPoint < Test::Unit::TestCase
|
|
67
67
|
assert_equal point(4, 5, 6), o1
|
68
68
|
end
|
69
69
|
|
70
|
-
def test_move_by
|
70
|
+
def test_move_by()
|
71
71
|
o = point 1, 2, 3
|
72
72
|
assert_equal point( 5, 2, 3), o.move_by( 4)
|
73
73
|
assert_equal point( 5, 7, 3), o.move_by( 4, 5)
|
@@ -90,13 +90,13 @@ class TestPoint < Test::Unit::TestCase
|
|
90
90
|
assert_equal point(5, 7, 9), o1
|
91
91
|
end
|
92
92
|
|
93
|
-
def test_length
|
93
|
+
def test_length()
|
94
94
|
assert_in_delta 0, point(0).length
|
95
95
|
assert_in_delta 1, point(1, 0, 0).length
|
96
96
|
assert_in_delta Math.sqrt(2), point(1, 1, 0).length
|
97
97
|
end
|
98
98
|
|
99
|
-
def test_normalize
|
99
|
+
def test_normalize()
|
100
100
|
assert_in_delta 1, point( 1, 0, 0) .normalize.length
|
101
101
|
assert_in_delta 1, point( 1, 1, 0) .normalize.length
|
102
102
|
assert_in_delta 1, point( 1, 1, 1) .normalize.length
|
@@ -105,12 +105,12 @@ class TestPoint < Test::Unit::TestCase
|
|
105
105
|
assert_raise(Rucy::NativeError) {point(0).normalize}
|
106
106
|
end
|
107
107
|
|
108
|
-
def test_normal
|
108
|
+
def test_normal()
|
109
109
|
assert_equal point(1, 2, 3).normalize, point(1, 2, 3).normal
|
110
110
|
assert_raise(Rucy::NativeError) {point(0).normal}
|
111
111
|
end
|
112
112
|
|
113
|
-
def test_to_a
|
113
|
+
def test_to_a()
|
114
114
|
o = point 1, 2, 3
|
115
115
|
assert_equal [1, 2], o.to_a
|
116
116
|
assert_equal [1], o.to_a(1)
|
@@ -121,7 +121,7 @@ class TestPoint < Test::Unit::TestCase
|
|
121
121
|
assert_raise(ArgumentError) {o.to_a(4)}
|
122
122
|
end
|
123
123
|
|
124
|
-
def test_index
|
124
|
+
def test_index()
|
125
125
|
o = point 1, 2, 3
|
126
126
|
assert_equal 1, o[0]
|
127
127
|
assert_equal 2, o[1]
|
@@ -130,7 +130,7 @@ class TestPoint < Test::Unit::TestCase
|
|
130
130
|
assert_raise(IndexError) {point[3]}
|
131
131
|
end
|
132
132
|
|
133
|
-
def test_index_assign
|
133
|
+
def test_index_assign()
|
134
134
|
o = point 1, 2, 3
|
135
135
|
o[0] = 4
|
136
136
|
assert_equal [4, 2, 3], o.to_a(3)
|
@@ -142,7 +142,7 @@ class TestPoint < Test::Unit::TestCase
|
|
142
142
|
assert_raise(IndexError) {point[ 3] = 7}
|
143
143
|
end
|
144
144
|
|
145
|
-
def test_compare
|
145
|
+
def test_compare()
|
146
146
|
o = point 1, 2, 3
|
147
147
|
assert o == point(1, 2, 3)
|
148
148
|
assert_not o != point(1, 2, 3)
|
@@ -156,11 +156,11 @@ class TestPoint < Test::Unit::TestCase
|
|
156
156
|
assert o > point(1, 2, 2)
|
157
157
|
end
|
158
158
|
|
159
|
-
def test_negate
|
159
|
+
def test_negate()
|
160
160
|
assert_equal point(-1, 2, -3), -point(1, -2, 3)
|
161
161
|
end
|
162
162
|
|
163
|
-
def test_arithmetic_operations
|
163
|
+
def test_arithmetic_operations()
|
164
164
|
assert_equal point(11, 22, 33), point(10, 20, 30) + point(1, 2, 3)
|
165
165
|
assert_equal point( 9, 18, 27), point(10, 20, 30) - point(1, 2, 3)
|
166
166
|
assert_equal point(10, 40, 90), point(10, 20, 30) * point(1, 2, 3)
|
@@ -175,15 +175,15 @@ class TestPoint < Test::Unit::TestCase
|
|
175
175
|
assert_equal point( 5, 10, 15), point(10, 20, 30) / 2
|
176
176
|
end
|
177
177
|
|
178
|
-
def test_inspect
|
178
|
+
def test_inspect()
|
179
179
|
assert_equal "#<Rays::Point 1.0, 2.0, 3.0>", point(1, 2, 3).inspect
|
180
180
|
end
|
181
181
|
|
182
|
-
def test_dot
|
182
|
+
def test_dot()
|
183
183
|
assert_equal 1*4 + 2*5 + 3*6, Rays::Point::dot(point(1, 2, 3), point(4, 5, 6))
|
184
184
|
end
|
185
185
|
|
186
|
-
def test_cross
|
186
|
+
def test_cross()
|
187
187
|
assert_equal point(0, 0, 1), Rays::Point::cross(point(1, 0, 0), point(0, 1, 0))
|
188
188
|
end
|
189
189
|
|