gmath3D 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/Gemfile +5 -11
- data/LICENSE.txt +20 -20
- data/README.rdoc +19 -19
- data/Rakefile +45 -45
- data/VERSION +1 -1
- data/gmath3D.gemspec +79 -80
- data/lib/box.rb +145 -145
- data/lib/ellipse.rb +11 -11
- data/lib/ext.rb +82 -82
- data/lib/finite_line.rb +244 -244
- data/lib/geom.rb +20 -20
- data/lib/gmath3D.rb +22 -22
- data/lib/line.rb +122 -122
- data/lib/plane.rb +131 -131
- data/lib/polyline.rb +73 -73
- data/lib/quat.rb +170 -170
- data/lib/rectangle.rb +155 -155
- data/lib/tri_mesh.rb +258 -258
- data/lib/triangle.rb +281 -281
- data/lib/util.rb +36 -23
- data/lib/vector3.rb +227 -227
- data/test/helper.rb +15 -15
- data/test/test_box.rb +167 -167
- data/test/test_ellipse.rb +55 -55
- data/test/test_finite_line.rb +306 -306
- data/test/test_geom.rb +17 -17
- data/test/test_line.rb +146 -146
- data/test/test_matrix_util.rb +84 -84
- data/test/test_plane.rb +200 -200
- data/test/test_polyline.rb +93 -93
- data/test/test_quat.rb +144 -144
- data/test/test_rectangle.rb +184 -184
- data/test/test_tri_mesh.rb +186 -186
- data/test/test_triangle.rb +318 -318
- data/test/test_util.rb +88 -57
- data/test/test_vector3.rb +439 -439
- metadata +8 -11
- data/Gemfile.lock +0 -16
data/test/test_util.rb
CHANGED
@@ -1,57 +1,88 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
include GMath3D
|
5
|
-
|
6
|
-
MiniTest::Unit.autorun
|
7
|
-
|
8
|
-
class UtilTestCase < MiniTest::Unit::TestCase
|
9
|
-
def test_check_arg_type
|
10
|
-
integerInstance = 1
|
11
|
-
floatInstance = 3.1415
|
12
|
-
stringInstance = 'string'
|
13
|
-
|
14
|
-
# no exception raise
|
15
|
-
Util3D.check_arg_type(Integer, integerInstance)
|
16
|
-
Util3D.check_arg_type(Float, floatInstance)
|
17
|
-
Util3D.check_arg_type(String, stringInstance)
|
18
|
-
|
19
|
-
# exception raise
|
20
|
-
assert_raises ArgumentError do
|
21
|
-
Util3D.check_arg_type(Integer, floatInstance)
|
22
|
-
end
|
23
|
-
assert_raises ArgumentError do
|
24
|
-
Util3D.check_arg_type(Integer, stringInstance)
|
25
|
-
end
|
26
|
-
assert_raises ArgumentError do
|
27
|
-
Util3D.check_arg_type(Float, integerInstance)
|
28
|
-
end
|
29
|
-
assert_raises ArgumentError do
|
30
|
-
Util3D.check_arg_type(Float, stringInstance)
|
31
|
-
end
|
32
|
-
assert_raises ArgumentError do
|
33
|
-
Util3D.check_arg_type(String, integerInstance)
|
34
|
-
end
|
35
|
-
assert_raises ArgumentError do
|
36
|
-
Util3D.check_arg_type(String, floatInstance)
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
require 'helper'
|
3
|
+
|
4
|
+
include GMath3D
|
5
|
+
|
6
|
+
MiniTest::Unit.autorun
|
7
|
+
|
8
|
+
class UtilTestCase < MiniTest::Unit::TestCase
|
9
|
+
def test_check_arg_type
|
10
|
+
integerInstance = 1
|
11
|
+
floatInstance = 3.1415
|
12
|
+
stringInstance = 'string'
|
13
|
+
|
14
|
+
# no exception raise
|
15
|
+
Util3D.check_arg_type(Integer, integerInstance)
|
16
|
+
Util3D.check_arg_type(Float, floatInstance)
|
17
|
+
Util3D.check_arg_type(String, stringInstance)
|
18
|
+
|
19
|
+
# exception raise
|
20
|
+
assert_raises ArgumentError do
|
21
|
+
Util3D.check_arg_type(Integer, floatInstance)
|
22
|
+
end
|
23
|
+
assert_raises ArgumentError do
|
24
|
+
Util3D.check_arg_type(Integer, stringInstance)
|
25
|
+
end
|
26
|
+
assert_raises ArgumentError do
|
27
|
+
Util3D.check_arg_type(Float, integerInstance)
|
28
|
+
end
|
29
|
+
assert_raises ArgumentError do
|
30
|
+
Util3D.check_arg_type(Float, stringInstance)
|
31
|
+
end
|
32
|
+
assert_raises ArgumentError do
|
33
|
+
Util3D.check_arg_type(String, integerInstance)
|
34
|
+
end
|
35
|
+
assert_raises ArgumentError do
|
36
|
+
Util3D.check_arg_type(String, floatInstance)
|
37
|
+
end
|
38
|
+
|
39
|
+
# not raise exception
|
40
|
+
arg = {:geom => Vector3.new(), :color => [1,0,0,1]}
|
41
|
+
Util3D.check_key_arg(arg, :geom)
|
42
|
+
assert_raises ArgumentError do
|
43
|
+
Util3D.check_key_arg(arg, :dummy)
|
44
|
+
end
|
45
|
+
|
46
|
+
# test nullable
|
47
|
+
Util3D.check_arg_type(String, nil, true)
|
48
|
+
assert_raises ArgumentError do
|
49
|
+
Util3D.check_arg_type(String, nil, false)
|
50
|
+
end
|
51
|
+
assert_raises ArgumentError do
|
52
|
+
Util3D.check_arg_type(String, nil)
|
53
|
+
end
|
54
|
+
assert_raises ArgumentError do
|
55
|
+
Util3D.check_arg_type(String, ["hoge", nil], false, true)
|
56
|
+
end
|
57
|
+
|
58
|
+
#test array check
|
59
|
+
Util3D.check_arg_type(String, "hoge")
|
60
|
+
Util3D.check_arg_type(String, "hoge", false, true)
|
61
|
+
Util3D.check_arg_type(String, ["hoge", "piyo"], false, true)
|
62
|
+
Util3D.check_arg_type(String, ["hoge", nil], true, true)
|
63
|
+
assert_raises ArgumentError do
|
64
|
+
Util3D.check_arg_type(String, ["hoge", "piyo"], false, false)
|
65
|
+
end
|
66
|
+
assert_raises ArgumentError do
|
67
|
+
Util3D.check_arg_type(String, ["hoge", "piyo"], false)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_array_methods
|
72
|
+
point_ary = Array.new([Vector3.new(2,4,3),Vector3.new(-2,2.5,8),Vector3.new(9,0,-3)])
|
73
|
+
assert_equal( Vector3.new(9, 6.5, 8), point_ary.sum)
|
74
|
+
assert_equal( Vector3.new(3, 6.5/3, 8/3.0), point_ary.avg)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_matrix_equation_solving
|
78
|
+
mat = Matrix[[1,2,3],[4,5,6],[7,8,-9]]
|
79
|
+
vec = Matrix.column_vector([26,62,8])
|
80
|
+
inv_mat = mat.inverse
|
81
|
+
ans = inv_mat*vec
|
82
|
+
assert_equal(3, ans.row_size)
|
83
|
+
assert_equal(1, ans.column_size)
|
84
|
+
assert_equal(3, ans[0,0])
|
85
|
+
assert_equal(4, ans[1,0])
|
86
|
+
assert_equal(5, ans[2,0])
|
87
|
+
end
|
88
|
+
end
|