mageo 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_polar3d.rb CHANGED
@@ -7,89 +7,87 @@ require "mageo/polar3d.rb"
7
7
  require "mageo/vector3d.rb"
8
8
 
9
9
  class TC_Polar3D < Test::Unit::TestCase
10
- $tolerance = 10**(-10)
10
+ $tolerance = 10**(-10)
11
11
 
12
- include Math
12
+ include Math
13
13
 
14
- def setup
15
- @p3d00 = Polar3D.new( 0.0, 0.00*PI, 0.00*PI)
16
- @p3d01 = Polar3D.new( 2.0, 0.00*PI, 0.25*PI)
17
- @p3d02 = Polar3D.new( 2.0, 0.25*PI, 0.00*PI)
18
- @p3d03 = Polar3D.new( 2.0, 0.25*PI, 0.25*PI)
19
- end
14
+ def setup
15
+ @p3d00 = Polar3D.new( 0.0, 0.00*PI, 0.00*PI)
16
+ @p3d01 = Polar3D.new( 2.0, 0.00*PI, 0.25*PI)
17
+ @p3d02 = Polar3D.new( 2.0, 0.25*PI, 0.00*PI)
18
+ @p3d03 = Polar3D.new( 2.0, 0.25*PI, 0.25*PI)
19
+ end
20
20
 
21
- def test_to_v3d
22
- assert_equal( Vector3D, @p3d00.to_v3d.class )
23
- assert_in_delta( 0.0, @p3d00.to_v3d[0], $tolerance )
24
- assert_in_delta( 0.0, @p3d00.to_v3d[1], $tolerance )
25
- assert_in_delta( 0.0, @p3d00.to_v3d[2], $tolerance )
21
+ def test_to_v3d
22
+ assert_equal( Vector3D, @p3d00.to_v3d.class )
23
+ assert_in_delta( 0.0, @p3d00.to_v3d[0], $tolerance )
24
+ assert_in_delta( 0.0, @p3d00.to_v3d[1], $tolerance )
25
+ assert_in_delta( 0.0, @p3d00.to_v3d[2], $tolerance )
26
26
 
27
- assert_equal( Vector3D, @p3d01.to_v3d.class )
28
- assert_in_delta( 0.0, @p3d01.to_v3d[0], $tolerance )
29
- assert_in_delta( 0.0, @p3d01.to_v3d[1], $tolerance )
30
- assert_in_delta( 2.0, @p3d01.to_v3d[2], $tolerance )
27
+ assert_equal( Vector3D, @p3d01.to_v3d.class )
28
+ assert_in_delta( 0.0, @p3d01.to_v3d[0], $tolerance )
29
+ assert_in_delta( 0.0, @p3d01.to_v3d[1], $tolerance )
30
+ assert_in_delta( 2.0, @p3d01.to_v3d[2], $tolerance )
31
31
 
32
- assert_equal( Vector3D, @p3d02.to_v3d.class )
33
- assert_in_delta( Math::sqrt(2.0), @p3d02.to_v3d[0], $tolerance )
34
- assert_in_delta( 0.0 , @p3d02.to_v3d[1], $tolerance )
35
- assert_in_delta( Math::sqrt(2.0), @p3d02.to_v3d[2], $tolerance )
32
+ assert_equal( Vector3D, @p3d02.to_v3d.class )
33
+ assert_in_delta( Math::sqrt(2.0), @p3d02.to_v3d[0], $tolerance )
34
+ assert_in_delta( 0.0 , @p3d02.to_v3d[1], $tolerance )
35
+ assert_in_delta( Math::sqrt(2.0), @p3d02.to_v3d[2], $tolerance )
36
36
 
37
- assert_equal( Vector3D, @p3d03.to_v3d.class )
38
- #√2 * cos(0.25PI)
39
- assert_in_delta( 1.0 , @p3d03.to_v3d[0], $tolerance)
40
- assert_in_delta( 1.0 , @p3d03.to_v3d[1], $tolerance)
41
- assert_in_delta( Math::sqrt(2.0), @p3d03.to_v3d[2], $tolerance )
37
+ assert_equal( Vector3D, @p3d03.to_v3d.class )
38
+ #√2 * cos(0.25PI)
39
+ assert_in_delta( 1.0 , @p3d03.to_v3d[0], $tolerance)
40
+ assert_in_delta( 1.0 , @p3d03.to_v3d[1], $tolerance)
41
+ assert_in_delta( Math::sqrt(2.0), @p3d03.to_v3d[2], $tolerance )
42
42
 
43
- end
43
+ end
44
44
 
45
- def test_minimize_phi!
46
- p2pA = Polar3D.new( 2.0, 0.5*PI, -2.5*PI )
47
- p2pA.minimize_phi!
48
- assert_in_delta( 1.5*PI, p2pA.phi, $tolerance )
45
+ def test_minimize_phi!
46
+ p2pA = Polar3D.new( 2.0, 0.5*PI, -2.5*PI )
47
+ p2pA.minimize_phi!
48
+ assert_in_delta( 1.5*PI, p2pA.phi, $tolerance )
49
49
 
50
- p2pB = Polar3D.new( 2.0, 0.5*PI, -0.5*PI )
51
- p2pB.minimize_phi!
52
- assert_in_delta( 1.5*PI, p2pB.phi, $tolerance )
50
+ p2pB = Polar3D.new( 2.0, 0.5*PI, -0.5*PI )
51
+ p2pB.minimize_phi!
52
+ assert_in_delta( 1.5*PI, p2pB.phi, $tolerance )
53
53
 
54
- p2pC = Polar3D.new( 2.0, 0.5*PI, 1.5*PI )
55
- p2pC.minimize_phi!
56
- assert_in_delta( 1.5*PI, p2pC.phi, $tolerance )
54
+ p2pC = Polar3D.new( 2.0, 0.5*PI, 1.5*PI )
55
+ p2pC.minimize_phi!
56
+ assert_in_delta( 1.5*PI, p2pC.phi, $tolerance )
57
57
 
58
- p2pD = Polar3D.new( 2.0, 0.5*PI, 3.5*PI )
59
- p2pD.minimize_phi!
60
- assert_in_delta( 1.5*PI, p2pD.phi, $tolerance )
58
+ p2pD = Polar3D.new( 2.0, 0.5*PI, 3.5*PI )
59
+ p2pD.minimize_phi!
60
+ assert_in_delta( 1.5*PI, p2pD.phi, $tolerance )
61
61
 
62
- p2pE = Polar3D.new( 2.0, 0.5*PI, 5.5*PI )
63
- p2pE.minimize_phi!
64
- assert_in_delta( 1.5*PI, p2pE.phi, $tolerance )
62
+ p2pE = Polar3D.new( 2.0, 0.5*PI, 5.5*PI )
63
+ p2pE.minimize_phi!
64
+ assert_in_delta( 1.5*PI, p2pE.phi, $tolerance )
65
65
 
66
- p2pF = Polar3D.new( 2.0, 0.5*PI, 4.5*PI )
67
- p2pF.minimize_phi!
68
- assert_in_delta( 0.5*PI, p2pF.phi, $tolerance )
66
+ p2pF = Polar3D.new( 2.0, 0.5*PI, 4.5*PI )
67
+ p2pF.minimize_phi!
68
+ assert_in_delta( 0.5*PI, p2pF.phi, $tolerance )
69
69
 
70
- end
70
+ end
71
71
 
72
- def test_minimize_phi
73
- p2pA = Polar3D.new( 2.0, 0.5*PI, -2.5*PI ).minimize_phi
74
- assert_in_delta( 1.5*PI, p2pA.phi, $tolerance )
72
+ def test_minimize_phi
73
+ p2pA = Polar3D.new( 2.0, 0.5*PI, -2.5*PI ).minimize_phi
74
+ assert_in_delta( 1.5*PI, p2pA.phi, $tolerance )
75
75
 
76
- p2pB = Polar3D.new( 2.0, 0.5*PI, -0.5*PI ).minimize_phi
77
- assert_in_delta( 1.5*PI, p2pB.phi, $tolerance )
76
+ p2pB = Polar3D.new( 2.0, 0.5*PI, -0.5*PI ).minimize_phi
77
+ assert_in_delta( 1.5*PI, p2pB.phi, $tolerance )
78
78
 
79
- p2pC = Polar3D.new( 2.0, 0.5*PI, 1.5*PI ).minimize_phi
80
- assert_in_delta( 1.5*PI, p2pC.phi, $tolerance )
79
+ p2pC = Polar3D.new( 2.0, 0.5*PI, 1.5*PI ).minimize_phi
80
+ assert_in_delta( 1.5*PI, p2pC.phi, $tolerance )
81
81
 
82
- p2pD = Polar3D.new( 2.0, 0.5*PI, 3.5*PI ).minimize_phi
83
- assert_in_delta( 1.5*PI, p2pD.phi, $tolerance )
82
+ p2pD = Polar3D.new( 2.0, 0.5*PI, 3.5*PI ).minimize_phi
83
+ assert_in_delta( 1.5*PI, p2pD.phi, $tolerance )
84
84
 
85
- p2pE = Polar3D.new( 2.0, 0.5*PI, 5.5*PI ).minimize_phi
86
- assert_in_delta( 1.5*PI, p2pE.phi, $tolerance )
87
-
88
- p2pF = Polar3D.new( 2.0, 0.5*PI, 4.5*PI ).minimize_phi
89
- assert_in_delta( 0.5*PI, p2pF.phi, $tolerance )
90
-
91
- end
85
+ p2pE = Polar3D.new( 2.0, 0.5*PI, 5.5*PI ).minimize_phi
86
+ assert_in_delta( 1.5*PI, p2pE.phi, $tolerance )
92
87
 
88
+ p2pF = Polar3D.new( 2.0, 0.5*PI, 4.5*PI ).minimize_phi
89
+ assert_in_delta( 0.5*PI, p2pF.phi, $tolerance )
93
90
 
91
+ end
94
92
  end
95
93
 
@@ -8,7 +8,7 @@ require "mageo/polyhedron.rb"
8
8
  # initialize でインスタンスを生成できないことのみテストする。
9
9
  # その他の機能はサブクラスでテスト。
10
10
  class TC_Polyhedron < Test::Unit::TestCase
11
- def test_initialize
12
- assert_raise( NotImplementedError ) { Polyhedron.new }
13
- end
11
+ def test_initialize
12
+ assert_raise( NotImplementedError ) { Polyhedron.new }
13
+ end
14
14
  end
data/test/test_segment.rb CHANGED
@@ -6,77 +6,76 @@ require "helper"
6
6
  require "mageo/segment.rb"
7
7
 
8
8
  class TC_Segment < Test::Unit::TestCase
9
- $tolerance = 1.0 * 10.0 ** (-10)
10
-
11
- VEC_00 = Vector3D[1.0, 2.0, 3.0]
12
- VEC_01 = Vector3D[4.0, 6.0, 8.0]
13
-
14
- VEC_10 = Vector3D[0.0, 0.0, 1.0]
15
- VEC_11 = Vector3D[0.0, 0.0, 3.0]
16
-
17
- VEC_20 = Vector3D[1.0, 1.0, 1.0]
18
- VEC_21 = Vector3D[0.0, 0.0, 0.0]
19
- def setup
20
- @s00 = Segment.new(VEC_00, VEC_01)
21
- @s01 = Segment.new(VEC_10, VEC_11)
22
- @s02 = Segment.new(VEC_20, VEC_21)
23
- end
24
-
25
- def test_initialize
26
- vec00 = [1.0, 2.0, 3.0]
27
- vec01 = [4.0, 6.0, 8.0]
28
- assert_raise(Segment::InitializeError){
29
- Segment.new(vec00, vec01)
30
- }
31
- assert_raise(Segment::InitializeError){
32
- Segment.new(VEC_00, VEC_00)
33
- }
34
- end
35
-
36
- def test_endpoints
37
- assert_equal(VEC_00, @s00.endpoints[0])
38
- assert_equal(VEC_01, @s00.endpoints[1])
39
- end
40
-
41
- def test_include?
42
- assert_raise(Segment::TypeError){
43
- @s02.include?([0.0, 0.0, 0.0], $tolerance)
44
- }
45
-
46
- #直線上
47
- assert_equal(false, @s02.include?(Vector3D[-1.0,-1.0,-1.0], $tolerance))
48
- assert_equal(true , @s02.include?(Vector3D[ 0.0, 0.0, 0.0], $tolerance))
49
- assert_equal(true , @s02.include?(Vector3D[ 0.3, 0.3, 0.3], $tolerance))
50
- assert_equal(true , @s02.include?(Vector3D[ 1.0, 1.0, 1.0], $tolerance))
51
- assert_equal(false, @s02.include?(Vector3D[ 2.0, 2.0, 2.0], $tolerance))
52
-
53
- #横に出てる
54
- assert_equal(false, @s02.include?(Vector3D[0.1, 0.1, 0.2], $tolerance))
55
- assert_equal(true , @s02.include?(Vector3D[0.1, 0.1, 0.2], 1.0))
56
- end
57
-
58
- def test_to_v3d
59
- assert_equal(Vector3D[ 3.0, 4.0, 5.0], @s00.to_v3d)
60
- assert_equal(Vector3D[ 0.0, 0.0, 2.0], @s01.to_v3d)
61
- assert_equal(Vector3D[-1.0,-1.0,-1.0], @s02.to_v3d)
62
- end
63
-
64
- def test_eql?
65
- assert_raise(Segment::TypeError){ @s00.eql?([[0,0,0],[1,1,1]])}
66
-
67
- assert_equal(true , @s00.eql?(Segment.new(VEC_01, VEC_00)))
68
- assert_equal(false, @s00.eql?(@s01))
69
- end
70
-
71
- def test_equal2
72
- assert_raise(Segment::TypeError){ @s00.eql?([[0,0,0],[1,1,1]])}
73
-
74
- assert_equal(true , @s00 == Segment.new(VEC_00, VEC_01))
75
- assert_equal(false, @s00 == Segment.new(VEC_01, VEC_00))
76
- assert_equal(false, @s00 == @s01)
77
- end
78
-
79
- #undef test_include?
80
-
9
+ $tolerance = 1.0 * 10.0 ** (-10)
10
+
11
+ VEC_00 = Vector3D[1.0, 2.0, 3.0]
12
+ VEC_01 = Vector3D[4.0, 6.0, 8.0]
13
+
14
+ VEC_10 = Vector3D[0.0, 0.0, 1.0]
15
+ VEC_11 = Vector3D[0.0, 0.0, 3.0]
16
+
17
+ VEC_20 = Vector3D[1.0, 1.0, 1.0]
18
+ VEC_21 = Vector3D[0.0, 0.0, 0.0]
19
+ def setup
20
+ @s00 = Segment.new(VEC_00, VEC_01)
21
+ @s01 = Segment.new(VEC_10, VEC_11)
22
+ @s02 = Segment.new(VEC_20, VEC_21)
23
+ end
24
+
25
+ def test_initialize
26
+ vec00 = [1.0, 2.0, 3.0]
27
+ vec01 = [4.0, 6.0, 8.0]
28
+ assert_raise(Segment::InitializeError){
29
+ Segment.new(vec00, vec01)
30
+ }
31
+ assert_raise(Segment::InitializeError){
32
+ Segment.new(VEC_00, VEC_00)
33
+ }
34
+ end
35
+
36
+ def test_endpoints
37
+ assert_equal(VEC_00, @s00.endpoints[0])
38
+ assert_equal(VEC_01, @s00.endpoints[1])
39
+ end
40
+
41
+ def test_include?
42
+ assert_raise(Segment::TypeError){
43
+ @s02.include?([0.0, 0.0, 0.0], $tolerance)
44
+ }
45
+
46
+ #直線上
47
+ assert_equal(false, @s02.include?(Vector3D[-1.0,-1.0,-1.0], $tolerance))
48
+ assert_equal(true , @s02.include?(Vector3D[ 0.0, 0.0, 0.0], $tolerance))
49
+ assert_equal(true , @s02.include?(Vector3D[ 0.3, 0.3, 0.3], $tolerance))
50
+ assert_equal(true , @s02.include?(Vector3D[ 1.0, 1.0, 1.0], $tolerance))
51
+ assert_equal(false, @s02.include?(Vector3D[ 2.0, 2.0, 2.0], $tolerance))
52
+
53
+ #横に出てる
54
+ assert_equal(false, @s02.include?(Vector3D[0.1, 0.1, 0.2], $tolerance))
55
+ assert_equal(true , @s02.include?(Vector3D[0.1, 0.1, 0.2], 1.0))
56
+ end
57
+
58
+ def test_to_v3d
59
+ assert_equal(Vector3D[ 3.0, 4.0, 5.0], @s00.to_v3d)
60
+ assert_equal(Vector3D[ 0.0, 0.0, 2.0], @s01.to_v3d)
61
+ assert_equal(Vector3D[-1.0,-1.0,-1.0], @s02.to_v3d)
62
+ end
63
+
64
+ def test_eql?
65
+ assert_raise(Segment::TypeError){ @s00.eql?([[0,0,0],[1,1,1]])}
66
+
67
+ assert_equal(true , @s00.eql?(Segment.new(VEC_01, VEC_00)))
68
+ assert_equal(false, @s00.eql?(@s01))
69
+ end
70
+
71
+ def test_equal2
72
+ assert_raise(Segment::TypeError){ @s00.eql?([[0,0,0],[1,1,1]])}
73
+
74
+ assert_equal(true , @s00 == Segment.new(VEC_00, VEC_01))
75
+ assert_equal(false, @s00 == Segment.new(VEC_01, VEC_00))
76
+ assert_equal(false, @s00 == @s01)
77
+ end
78
+
79
+ #undef test_include?
81
80
  end
82
81
 
data/test/test_sphere.rb CHANGED
@@ -7,14 +7,13 @@ require "mageo/sphere.rb"
7
7
  require "mageo/vector3d.rb"
8
8
 
9
9
  class TC_Sphere < Test::Unit::TestCase
10
- def setup
11
- @s00 = Sphere.new([0.0, 1.0, 2.0], 3.0)
12
- end
13
-
14
- def test_initialize
15
- assert_equal(Vector3D[0.0, 1.0, 2.0], @s00.position)
16
- assert_equal(3.0, @s00.radius)
17
- end
10
+ def setup
11
+ @s00 = Sphere.new([0.0, 1.0, 2.0], 3.0)
12
+ end
18
13
 
14
+ def test_initialize
15
+ assert_equal(Vector3D[0.0, 1.0, 2.0], @s00.position)
16
+ assert_equal(3.0, @s00.radius)
17
+ end
19
18
  end
20
19
 
@@ -8,125 +8,123 @@ require "array_include_eql.rb"
8
8
  require "mageo/tetrahedron.rb"
9
9
 
10
10
  class Tetrahedron
11
- public :center
11
+ public :center
12
12
  end
13
13
 
14
14
  class TC_Tetrahedron < Test::Unit::TestCase
15
- $tolerance = 10**(-10)
16
-
17
- V_00 = Vector3D[ 0.0, 0.0, 0.0]
18
- V_01 = Vector3D[10.0, 0.0, 0.0]
19
- V_02 = Vector3D[ 0.0,10.0, 0.0]
20
- V_03 = Vector3D[ 0.0, 0.0,10.0]
21
-
22
- V_10 = Vector3D[10.0,20.0,30.0]
23
- V_11 = Vector3D[ 0.0,20.0,30.0]
24
- V_12 = Vector3D[10.0, 0.0,30.0]
25
- V_13 = Vector3D[10.0,20.0, 0.0]
26
-
27
- def setup
28
- @t00 = Tetrahedron.new( [ V_00, V_01, V_02, V_03 ])
29
- @t01 = Tetrahedron.new( [ V_10, V_11, V_12, V_13 ])
30
- end
31
-
32
- def test_initialize
33
- assert_raise( ArgumentError ){ Tetrahedron.new }
34
- assert_raise( ArgumentError ){ Tetrahedron.new() }
35
- assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( nil ) }
36
- assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [] ) }
37
- assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [ 0, 1, 2, 3 ] ) }
38
- assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [ [], [], [], [] ] ) }
39
- assert_raise( Tetrahedron::InitializeError ){
40
- Tetrahedron.new( [ V_00, V_01, V_02, [ 0.0, 0.0 ] ])
41
- }
42
- assert_raise( Tetrahedron::InitializeError ){
43
- Tetrahedron.new( [ V_00, V_01, V_02, [ 0.0, 0.0, 1.0, 0.0 ] ])
44
- }
45
-
46
- # 5点ある
47
- assert_raise( Tetrahedron::InitializeError ){
48
- Tetrahedron.new( [ V_00, V_01, V_02, V_03, [ 1.0, 1.0, 1.0] ])
49
- }
50
-
51
- # 体積が 0.0 になるのはエラー
52
- assert_raise( Tetrahedron::InitializeError ){
53
- Tetrahedron.new( [ V_00, V_01, V_02, [ 2.0, 2.0, 0.0] ])
54
- }
55
-
56
- # Vector3DInternal なら 例外
57
- assert_raise( Tetrahedron::InitializeError ){
58
- Tetrahedron.new(
59
- [ Vector3DInternal[ 0.0, 0.0, 0.0],
60
- Vector3DInternal[ 1.0, 0.0, 0.0],
61
- Vector3DInternal[ 0.0, 1.0, 0.0],
62
- Vector3DInternal[ 0.0, 0.0, 1.0]
63
- ]
64
- )
65
- }
66
-
67
- # Vector3D なら OK
68
- assert_nothing_raised{
69
- Tetrahedron.new( [ V_00, V_01, V_02, V_03 ])
70
- }
71
- end
72
-
73
- def test_inside?
74
- assert_equal( true , @t00.inside?( [ 1.0, 1.0, 1.0] ) )
75
- assert_equal( false, @t00.inside?( [ 5.0, 5.0, 5.0] ) )
76
- assert_equal( false, @t00.inside?( [-5.0,-5.0,-5.0] ) )
77
- assert_equal( false, @t00.inside?( [ 0.0, 0.0, 0.0] ) ) #頂点上
78
-
79
- assert_raise(Polyhedron::TypeError){@t00.inside?(Vector3DInternal[1.0, 1.0, 1.0])}
80
- assert_raise(Tetrahedron::TypeError){@t00.inside?(Vector3DInternal[1.0, 1.0, 1.0])}
81
- #pp Polyhedron::TypeError.ancestors
82
- #pp Tetrahedron::TypeError.ancestors
83
- end
84
-
85
- def test_include?
86
- assert_equal( true , @t00.include?([ 1.0, 1.0, 1.0], $tolerance))
87
- assert_equal( false, @t00.include?([ 5.0, 5.0, 5.0], $tolerance))
88
- assert_equal( false, @t00.include?([-5.0,-5.0,-5.0], $tolerance))
89
- assert_equal( true , @t00.include?([ 0.0, 0.0, 0.0], $tolerance)) #頂点上
90
-
91
- assert_equal( false, @t01.include?(Vector3D[ 3.0, 6.0, 30.0], $tolerance))
92
-
93
- assert_raise(Polyhedron::TypeError){@t00.include?(Vector3DInternal[1.0, 1.0, 1.0], $tolerance)}
94
- end
95
-
96
- def test_volume
97
- assert_in_delta( 1000.0/6.0 , @t00.volume, $tolerance )
98
- end
99
-
100
- def test_center
101
- assert_in_delta( 10.0/4.0, @t00.center[0], $tolerance)
102
- assert_in_delta( 10.0/4.0, @t00.center[1], $tolerance)
103
- assert_in_delta( 10.0/4.0, @t00.center[2], $tolerance)
104
- end
105
-
106
- def test_vertices
107
- assert_equal( [ V_00, V_01, V_02, V_03 ], @t00.vertices)
108
- end
109
-
110
- def test_triangles
111
- t = @t00.triangles
112
- assert_equal(4, t.size)
113
- assert_equal(Triangle.new([V_00, V_01, V_02]) ,t[0])
114
- assert_equal(Triangle.new([V_01, V_02, V_03]) ,t[1])
115
- assert_equal(Triangle.new([V_02, V_03, V_00]) ,t[2])
116
- assert_equal(Triangle.new([V_03, V_00, V_01]) ,t[3])
117
- end
118
-
119
- def test_edges
120
- t = @t00.edges
121
- assert_equal(6, t.size)
122
- assert_equal(true, (t.include_eql?(Segment.new(V_00, V_01))))
123
- assert_equal(true, (t.include_eql?(Segment.new(V_00, V_02))))
124
- assert_equal(true, (t.include_eql?(Segment.new(V_00, V_03))))
125
- assert_equal(true, (t.include_eql?(Segment.new(V_01, V_02))))
126
- assert_equal(true, (t.include_eql?(Segment.new(V_01, V_03))))
127
- assert_equal(true, (t.include_eql?(Segment.new(V_02, V_03))))
128
- end
129
-
130
-
15
+ $tolerance = 10**(-10)
16
+
17
+ V_00 = Vector3D[ 0.0, 0.0, 0.0]
18
+ V_01 = Vector3D[10.0, 0.0, 0.0]
19
+ V_02 = Vector3D[ 0.0,10.0, 0.0]
20
+ V_03 = Vector3D[ 0.0, 0.0,10.0]
21
+
22
+ V_10 = Vector3D[10.0,20.0,30.0]
23
+ V_11 = Vector3D[ 0.0,20.0,30.0]
24
+ V_12 = Vector3D[10.0, 0.0,30.0]
25
+ V_13 = Vector3D[10.0,20.0, 0.0]
26
+
27
+ def setup
28
+ @t00 = Tetrahedron.new( [ V_00, V_01, V_02, V_03 ])
29
+ @t01 = Tetrahedron.new( [ V_10, V_11, V_12, V_13 ])
30
+ end
31
+
32
+ def test_initialize
33
+ assert_raise( ArgumentError ){ Tetrahedron.new }
34
+ assert_raise( ArgumentError ){ Tetrahedron.new() }
35
+ assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( nil ) }
36
+ assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [] ) }
37
+ assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [ 0, 1, 2, 3 ] ) }
38
+ assert_raise( Tetrahedron::InitializeError ){ Tetrahedron.new( [ [], [], [], [] ] ) }
39
+ assert_raise( Tetrahedron::InitializeError ){
40
+ Tetrahedron.new( [ V_00, V_01, V_02, [ 0.0, 0.0 ] ])
41
+ }
42
+ assert_raise( Tetrahedron::InitializeError ){
43
+ Tetrahedron.new( [ V_00, V_01, V_02, [ 0.0, 0.0, 1.0, 0.0 ] ])
44
+ }
45
+
46
+ # 5点ある
47
+ assert_raise( Tetrahedron::InitializeError ){
48
+ Tetrahedron.new( [ V_00, V_01, V_02, V_03, [ 1.0, 1.0, 1.0] ])
49
+ }
50
+
51
+ # 体積が 0.0 になるのはエラー
52
+ assert_raise( Tetrahedron::InitializeError ){
53
+ Tetrahedron.new( [ V_00, V_01, V_02, [ 2.0, 2.0, 0.0] ])
54
+ }
55
+
56
+ # Vector3DInternal なら 例外
57
+ assert_raise( Tetrahedron::InitializeError ){
58
+ Tetrahedron.new(
59
+ [ Vector3DInternal[ 0.0, 0.0, 0.0],
60
+ Vector3DInternal[ 1.0, 0.0, 0.0],
61
+ Vector3DInternal[ 0.0, 1.0, 0.0],
62
+ Vector3DInternal[ 0.0, 0.0, 1.0]
63
+ ]
64
+ )
65
+ }
66
+
67
+ # Vector3D なら OK
68
+ assert_nothing_raised{
69
+ Tetrahedron.new( [ V_00, V_01, V_02, V_03 ])
70
+ }
71
+ end
72
+
73
+ def test_inside?
74
+ assert_equal( true , @t00.inside?( [ 1.0, 1.0, 1.0] ) )
75
+ assert_equal( false, @t00.inside?( [ 5.0, 5.0, 5.0] ) )
76
+ assert_equal( false, @t00.inside?( [-5.0,-5.0,-5.0] ) )
77
+ assert_equal( false, @t00.inside?( [ 0.0, 0.0, 0.0] ) ) #頂点上
78
+
79
+ assert_raise(Polyhedron::TypeError){@t00.inside?(Vector3DInternal[1.0, 1.0, 1.0])}
80
+ assert_raise(Tetrahedron::TypeError){@t00.inside?(Vector3DInternal[1.0, 1.0, 1.0])}
81
+ #pp Polyhedron::TypeError.ancestors
82
+ #pp Tetrahedron::TypeError.ancestors
83
+ end
84
+
85
+ def test_include?
86
+ assert_equal( true , @t00.include?([ 1.0, 1.0, 1.0], $tolerance))
87
+ assert_equal( false, @t00.include?([ 5.0, 5.0, 5.0], $tolerance))
88
+ assert_equal( false, @t00.include?([-5.0,-5.0,-5.0], $tolerance))
89
+ assert_equal( true , @t00.include?([ 0.0, 0.0, 0.0], $tolerance)) #頂点上
90
+
91
+ assert_equal( false, @t01.include?(Vector3D[ 3.0, 6.0, 30.0], $tolerance))
92
+
93
+ assert_raise(Polyhedron::TypeError){@t00.include?(Vector3DInternal[1.0, 1.0, 1.0], $tolerance)}
94
+ end
95
+
96
+ def test_volume
97
+ assert_in_delta( 1000.0/6.0 , @t00.volume, $tolerance )
98
+ end
99
+
100
+ def test_center
101
+ assert_in_delta( 10.0/4.0, @t00.center[0], $tolerance)
102
+ assert_in_delta( 10.0/4.0, @t00.center[1], $tolerance)
103
+ assert_in_delta( 10.0/4.0, @t00.center[2], $tolerance)
104
+ end
105
+
106
+ def test_vertices
107
+ assert_equal( [ V_00, V_01, V_02, V_03 ], @t00.vertices)
108
+ end
109
+
110
+ def test_triangles
111
+ t = @t00.triangles
112
+ assert_equal(4, t.size)
113
+ assert_equal(Triangle.new([V_00, V_01, V_02]) ,t[0])
114
+ assert_equal(Triangle.new([V_01, V_02, V_03]) ,t[1])
115
+ assert_equal(Triangle.new([V_02, V_03, V_00]) ,t[2])
116
+ assert_equal(Triangle.new([V_03, V_00, V_01]) ,t[3])
117
+ end
118
+
119
+ def test_edges
120
+ t = @t00.edges
121
+ assert_equal(6, t.size)
122
+ assert_equal(true, (t.include_eql?(Segment.new(V_00, V_01))))
123
+ assert_equal(true, (t.include_eql?(Segment.new(V_00, V_02))))
124
+ assert_equal(true, (t.include_eql?(Segment.new(V_00, V_03))))
125
+ assert_equal(true, (t.include_eql?(Segment.new(V_01, V_02))))
126
+ assert_equal(true, (t.include_eql?(Segment.new(V_01, V_03))))
127
+ assert_equal(true, (t.include_eql?(Segment.new(V_02, V_03))))
128
+ end
131
129
  end
132
130