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/test/test_plane.rb CHANGED
@@ -1,200 +1,200 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class PlaneTestCase < MiniTest::Unit::TestCase
9
- def setup
10
- @base_point = Vector3.new(0,0,1)
11
- @normal = Vector3.new(0,0,1)
12
- @plane = Plane.new(@base_point, @normal)
13
- @plane_default = Plane.new()
14
- end
15
-
16
- def test_initialize
17
- assert_equal(@base_point, @plane.base_point)
18
- assert_equal(@normal, @plane.normal)
19
- assert_equal(Vector3.new(0,0,0),@plane_default.base_point)
20
- assert_equal(Vector3.new(0,0,1),@plane_default.normal)
21
- assert_equal(Geom.default_tolerance, @plane_default.tolerance)
22
- end
23
-
24
- def test_to_s
25
- assert_equal("Plane[point[0, 0, 1], normal[0.0, 0.0, 1.0]]", @plane.to_s)
26
- end
27
-
28
- def test_equals
29
- plane = Plane.new()
30
- shallow_copied = plane
31
- assert(plane.equal?(shallow_copied))
32
- assert(plane == shallow_copied)
33
- assert(plane != nil)
34
- assert(plane != "string")
35
-
36
- assert_equal(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)), Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
37
-
38
- assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
39
- assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(4.0,6,8.0)))
40
- assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,3)) != Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
41
- assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) != Plane.new(Vector3.new(2,3,4), Vector3.new(1,2,3)))
42
- end
43
-
44
- def test_clone
45
- plane = Plane.new()
46
- shallow_copied = plane
47
- shallow_copied.base_point.x = -1
48
- assert(plane == shallow_copied)
49
- assert(plane.equal?(shallow_copied))
50
- assert_equal(-1, shallow_copied.base_point.x)
51
-
52
- cloned = plane.clone
53
- assert(plane == cloned)
54
- assert(!plane.equal?(cloned))
55
- cloned.base_point.x = -2
56
- assert_equal(-2, cloned.base_point.x)
57
-
58
- assert_equal(-1, plane.base_point.x) # original never changed in editing cloned one.
59
- end
60
-
61
- def test_distance_to_point
62
- target_point = Vector3.new(1,2,3)
63
- distance, closest_point = @plane.distance(target_point)
64
- assert_in_delta(2, distance, target_point.tolerance)
65
- assert_equal(Vector3.new(1,2,1),closest_point)
66
-
67
- target_point = Vector3.new(1,-4,-5)
68
- distance, closest_point = @plane_default.distance(target_point)
69
- assert_in_delta(5, distance, target_point.tolerance)
70
- assert_equal(Vector3.new(1,-4,0),closest_point)
71
-
72
- target_point = Vector3.new(-2,4.5,1.0)
73
- distance, closest_point = @plane.distance(target_point)
74
- assert_in_delta(0, distance, target_point.tolerance)
75
- assert_equal(Vector3.new(-2,4.5,1.0),closest_point)
76
-
77
- plane2 = Plane.new(Vector3.new( 1.0, 1.0, 1.0), Vector3.new(1.0, 1.0, 0.0))
78
- target_point = Vector3.new( 0.0, 0.0, 0.0 )
79
- distance, closest_point = plane2.distance(target_point)
80
- assert_in_delta( Math::sqrt(2), distance, plane2.tolerance)
81
- assert_equal( Vector3.new( 1,1,0 ), closest_point)
82
- end
83
-
84
- def test_distance_to_line
85
- #intersect case
86
- target_line = Line.new(Vector3.new(1,1,2),Vector3.new(1,1,1))
87
- distance, intersect_point, parameter = @plane.distance(target_line)
88
- assert_in_delta(0, distance, @plane.tolerance)
89
- assert_equal(Vector3.new(0,0,1), intersect_point)
90
- assert_in_delta(-1, parameter, intersect_point.tolerance)
91
-
92
- #intersect case 2
93
- target_line = Line.new(Vector3.new(0,0,0),Vector3.new(2,2,2))
94
- distance, intersect_point, parameter = @plane.distance(target_line)
95
- assert_in_delta(0, distance, @plane.tolerance)
96
- assert_equal(Vector3.new(1,1,1), intersect_point)
97
- assert_in_delta(0.5, parameter, intersect_point.tolerance)
98
-
99
- #parallel case
100
- target_line = Line.new(Vector3.new(1,1,1.5),Vector3.new(1,1,0))
101
- distance, intersect_point, parameter = @plane_default.distance(target_line)
102
- assert_in_delta(1.5, distance, @plane_default.tolerance)
103
- assert_equal(nil, intersect_point)
104
- assert_equal(nil, parameter)
105
-
106
- #contains case
107
- target_line = Line.new(Vector3.new(1,1,1),Vector3.new(1,2.0,0))
108
- distance, intersect_point, parameter = @plane.distance(target_line)
109
- assert_in_delta(0, distance, @plane.tolerance)
110
- assert_equal(nil, intersect_point)
111
- assert_equal(nil, parameter)
112
- end
113
-
114
- def test_distance_to_finite_line
115
- #intersect case
116
- target_finite_line = FiniteLine.new(Vector3.new(0,0,0),Vector3.new(2,2,2))
117
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
118
- assert_in_delta(0, distance, @plane.tolerance)
119
- assert_equal( Vector3.new(1,1,1), point_on_plane)
120
- assert_equal( Vector3.new(1,1,1), point_on_line)
121
- assert_in_delta(0.5, parameter_on_line, @plane.tolerance)
122
-
123
- #intersect case2
124
- target_finite_line = FiniteLine.new(Vector3.new(0,0,0),Vector3.new(1,1,1))
125
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
126
- assert_in_delta(0, distance, @plane.tolerance)
127
- assert_equal( Vector3.new(1,1,1), point_on_plane)
128
- assert_equal( Vector3.new(1,1,1), point_on_line)
129
- assert_in_delta(1, parameter_on_line, @plane.tolerance)
130
-
131
- #not intersect case
132
- target_finite_line = FiniteLine.new(Vector3.new(2,2,2),Vector3.new(4,5,6))
133
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
134
- assert_in_delta(1, distance, @plane.tolerance)
135
- assert_equal( Vector3.new(2,2,1), point_on_plane)
136
- assert_equal( Vector3.new(2,2,2), point_on_line)
137
- assert_in_delta(0, parameter_on_line, @plane.tolerance)
138
-
139
- #not intersect case2
140
- target_finite_line = FiniteLine.new(Vector3.new(3,6,-9),Vector3.new(-2,3,-5))
141
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
142
- assert_in_delta(6, distance, @plane.tolerance)
143
- assert_equal( Vector3.new(-2,3,1), point_on_plane)
144
- assert_equal( Vector3.new(-2,3,-5), point_on_line)
145
- assert_in_delta(1, parameter_on_line, @plane.tolerance)
146
-
147
- #parallel case
148
- target_finite_line = FiniteLine.new(Vector3.new(3,3,3),Vector3.new(1,-4,3))
149
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
150
- assert_in_delta(2, distance, @plane.tolerance)
151
- assert_equal( nil, point_on_plane)
152
- assert_equal( nil, point_on_line)
153
- assert_equal( nil, parameter_on_line)
154
-
155
- #including case
156
- target_finite_line = FiniteLine.new(Vector3.new(3,3,1),Vector3.new(1,-4,1))
157
- distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
158
- assert_in_delta(0, distance, @plane.tolerance)
159
- assert_equal( nil, point_on_plane)
160
- assert_equal( nil, point_on_line)
161
- assert_equal( nil, parameter_on_line)
162
- end
163
-
164
- def test_distance_to_plane
165
- #intersect case
166
- target_plane = Plane.new(Vector3.new(1,1,4), Vector3.new(1,-1,0))
167
- distance, intersect_line = @plane.distance(target_plane)
168
- assert_in_delta(0, distance, @plane.tolerance)
169
- assert(intersect_line.direction.parallel?(Vector3.new(1,1,0)))
170
-
171
- #parallel case
172
- target_plane = Plane.new(Vector3.new(1,1,4), Vector3.new(0,0,-1))
173
- distance, intersect_line = @plane.distance(target_plane)
174
- assert_in_delta(3, distance, @plane.tolerance)
175
- assert_equal(nil, intersect_line)
176
-
177
- #including case
178
- target_plane = Plane.new(Vector3.new(1,1,1), Vector3.new(0,0,3))
179
- distance, intersect_line = @plane.distance(target_plane)
180
- assert_in_delta(0, distance, @plane.tolerance)
181
- assert_equal(nil, intersect_line)
182
- end
183
-
184
- def test_distance_to_invalid_value
185
- assert_raises ArgumentError do
186
- @plane.distance(4)
187
- end
188
- assert_raises ArgumentError do
189
- @plane.distance(nil)
190
- end
191
- end
192
-
193
- def test_project
194
- assert_equal( Vector3.new( 2.0, 4.0, 1.0), @plane.project(Vector3.new(2.0, 4.0, -5.0)))
195
- assert_equal( Vector3.new( 2.0, 4.0, 1.0), @plane.project(Vector3.new(2.0, 4.0, 5.0)))
196
- assert_equal( Vector3.new( 0.0, -4.0, 1.0), @plane.project(Vector3.new(0.0, -4.0, 1.0)))
197
- plane2 = Plane.new( Vector3.new(1,1,1), Vector3.new(1,1,0))
198
- assert_equal( Vector3.new( 1,1,5), plane2.project( Vector3.new( 0,0,5)))
199
- end
200
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class PlaneTestCase < MiniTest::Unit::TestCase
9
+ def setup
10
+ @base_point = Vector3.new(0,0,1)
11
+ @normal = Vector3.new(0,0,1)
12
+ @plane = Plane.new(@base_point, @normal)
13
+ @plane_default = Plane.new()
14
+ end
15
+
16
+ def test_initialize
17
+ assert_equal(@base_point, @plane.base_point)
18
+ assert_equal(@normal, @plane.normal)
19
+ assert_equal(Vector3.new(0,0,0),@plane_default.base_point)
20
+ assert_equal(Vector3.new(0,0,1),@plane_default.normal)
21
+ assert_equal(Geom.default_tolerance, @plane_default.tolerance)
22
+ end
23
+
24
+ def test_to_s
25
+ assert_equal("Plane[point[0, 0, 1], normal[0.0, 0.0, 1.0]]", @plane.to_s)
26
+ end
27
+
28
+ def test_equals
29
+ plane = Plane.new()
30
+ shallow_copied = plane
31
+ assert(plane.equal?(shallow_copied))
32
+ assert(plane == shallow_copied)
33
+ assert(plane != nil)
34
+ assert(plane != "string")
35
+
36
+ assert_equal(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)), Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
37
+
38
+ assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
39
+ assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(4.0,6,8.0)))
40
+ assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,3)) != Plane.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
41
+ assert(Plane.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) != Plane.new(Vector3.new(2,3,4), Vector3.new(1,2,3)))
42
+ end
43
+
44
+ def test_clone
45
+ plane = Plane.new()
46
+ shallow_copied = plane
47
+ shallow_copied.base_point.x = -1
48
+ assert(plane == shallow_copied)
49
+ assert(plane.equal?(shallow_copied))
50
+ assert_equal(-1, shallow_copied.base_point.x)
51
+
52
+ cloned = plane.clone
53
+ assert(plane == cloned)
54
+ assert(!plane.equal?(cloned))
55
+ cloned.base_point.x = -2
56
+ assert_equal(-2, cloned.base_point.x)
57
+
58
+ assert_equal(-1, plane.base_point.x) # original never changed in editing cloned one.
59
+ end
60
+
61
+ def test_distance_to_point
62
+ target_point = Vector3.new(1,2,3)
63
+ distance, closest_point = @plane.distance(target_point)
64
+ assert_in_delta(2, distance, target_point.tolerance)
65
+ assert_equal(Vector3.new(1,2,1),closest_point)
66
+
67
+ target_point = Vector3.new(1,-4,-5)
68
+ distance, closest_point = @plane_default.distance(target_point)
69
+ assert_in_delta(5, distance, target_point.tolerance)
70
+ assert_equal(Vector3.new(1,-4,0),closest_point)
71
+
72
+ target_point = Vector3.new(-2,4.5,1.0)
73
+ distance, closest_point = @plane.distance(target_point)
74
+ assert_in_delta(0, distance, target_point.tolerance)
75
+ assert_equal(Vector3.new(-2,4.5,1.0),closest_point)
76
+
77
+ plane2 = Plane.new(Vector3.new( 1.0, 1.0, 1.0), Vector3.new(1.0, 1.0, 0.0))
78
+ target_point = Vector3.new( 0.0, 0.0, 0.0 )
79
+ distance, closest_point = plane2.distance(target_point)
80
+ assert_in_delta( Math::sqrt(2), distance, plane2.tolerance)
81
+ assert_equal( Vector3.new( 1,1,0 ), closest_point)
82
+ end
83
+
84
+ def test_distance_to_line
85
+ #intersect case
86
+ target_line = Line.new(Vector3.new(1,1,2),Vector3.new(1,1,1))
87
+ distance, intersect_point, parameter = @plane.distance(target_line)
88
+ assert_in_delta(0, distance, @plane.tolerance)
89
+ assert_equal(Vector3.new(0,0,1), intersect_point)
90
+ assert_in_delta(-1, parameter, intersect_point.tolerance)
91
+
92
+ #intersect case 2
93
+ target_line = Line.new(Vector3.new(0,0,0),Vector3.new(2,2,2))
94
+ distance, intersect_point, parameter = @plane.distance(target_line)
95
+ assert_in_delta(0, distance, @plane.tolerance)
96
+ assert_equal(Vector3.new(1,1,1), intersect_point)
97
+ assert_in_delta(0.5, parameter, intersect_point.tolerance)
98
+
99
+ #parallel case
100
+ target_line = Line.new(Vector3.new(1,1,1.5),Vector3.new(1,1,0))
101
+ distance, intersect_point, parameter = @plane_default.distance(target_line)
102
+ assert_in_delta(1.5, distance, @plane_default.tolerance)
103
+ assert_equal(nil, intersect_point)
104
+ assert_equal(nil, parameter)
105
+
106
+ #contains case
107
+ target_line = Line.new(Vector3.new(1,1,1),Vector3.new(1,2.0,0))
108
+ distance, intersect_point, parameter = @plane.distance(target_line)
109
+ assert_in_delta(0, distance, @plane.tolerance)
110
+ assert_equal(nil, intersect_point)
111
+ assert_equal(nil, parameter)
112
+ end
113
+
114
+ def test_distance_to_finite_line
115
+ #intersect case
116
+ target_finite_line = FiniteLine.new(Vector3.new(0,0,0),Vector3.new(2,2,2))
117
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
118
+ assert_in_delta(0, distance, @plane.tolerance)
119
+ assert_equal( Vector3.new(1,1,1), point_on_plane)
120
+ assert_equal( Vector3.new(1,1,1), point_on_line)
121
+ assert_in_delta(0.5, parameter_on_line, @plane.tolerance)
122
+
123
+ #intersect case2
124
+ target_finite_line = FiniteLine.new(Vector3.new(0,0,0),Vector3.new(1,1,1))
125
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
126
+ assert_in_delta(0, distance, @plane.tolerance)
127
+ assert_equal( Vector3.new(1,1,1), point_on_plane)
128
+ assert_equal( Vector3.new(1,1,1), point_on_line)
129
+ assert_in_delta(1, parameter_on_line, @plane.tolerance)
130
+
131
+ #not intersect case
132
+ target_finite_line = FiniteLine.new(Vector3.new(2,2,2),Vector3.new(4,5,6))
133
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
134
+ assert_in_delta(1, distance, @plane.tolerance)
135
+ assert_equal( Vector3.new(2,2,1), point_on_plane)
136
+ assert_equal( Vector3.new(2,2,2), point_on_line)
137
+ assert_in_delta(0, parameter_on_line, @plane.tolerance)
138
+
139
+ #not intersect case2
140
+ target_finite_line = FiniteLine.new(Vector3.new(3,6,-9),Vector3.new(-2,3,-5))
141
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
142
+ assert_in_delta(6, distance, @plane.tolerance)
143
+ assert_equal( Vector3.new(-2,3,1), point_on_plane)
144
+ assert_equal( Vector3.new(-2,3,-5), point_on_line)
145
+ assert_in_delta(1, parameter_on_line, @plane.tolerance)
146
+
147
+ #parallel case
148
+ target_finite_line = FiniteLine.new(Vector3.new(3,3,3),Vector3.new(1,-4,3))
149
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
150
+ assert_in_delta(2, distance, @plane.tolerance)
151
+ assert_equal( nil, point_on_plane)
152
+ assert_equal( nil, point_on_line)
153
+ assert_equal( nil, parameter_on_line)
154
+
155
+ #including case
156
+ target_finite_line = FiniteLine.new(Vector3.new(3,3,1),Vector3.new(1,-4,1))
157
+ distance, point_on_plane, point_on_line, parameter_on_line = @plane.distance(target_finite_line)
158
+ assert_in_delta(0, distance, @plane.tolerance)
159
+ assert_equal( nil, point_on_plane)
160
+ assert_equal( nil, point_on_line)
161
+ assert_equal( nil, parameter_on_line)
162
+ end
163
+
164
+ def test_distance_to_plane
165
+ #intersect case
166
+ target_plane = Plane.new(Vector3.new(1,1,4), Vector3.new(1,-1,0))
167
+ distance, intersect_line = @plane.distance(target_plane)
168
+ assert_in_delta(0, distance, @plane.tolerance)
169
+ assert(intersect_line.direction.parallel?(Vector3.new(1,1,0)))
170
+
171
+ #parallel case
172
+ target_plane = Plane.new(Vector3.new(1,1,4), Vector3.new(0,0,-1))
173
+ distance, intersect_line = @plane.distance(target_plane)
174
+ assert_in_delta(3, distance, @plane.tolerance)
175
+ assert_equal(nil, intersect_line)
176
+
177
+ #including case
178
+ target_plane = Plane.new(Vector3.new(1,1,1), Vector3.new(0,0,3))
179
+ distance, intersect_line = @plane.distance(target_plane)
180
+ assert_in_delta(0, distance, @plane.tolerance)
181
+ assert_equal(nil, intersect_line)
182
+ end
183
+
184
+ def test_distance_to_invalid_value
185
+ assert_raises ArgumentError do
186
+ @plane.distance(4)
187
+ end
188
+ assert_raises ArgumentError do
189
+ @plane.distance(nil)
190
+ end
191
+ end
192
+
193
+ def test_project
194
+ assert_equal( Vector3.new( 2.0, 4.0, 1.0), @plane.project(Vector3.new(2.0, 4.0, -5.0)))
195
+ assert_equal( Vector3.new( 2.0, 4.0, 1.0), @plane.project(Vector3.new(2.0, 4.0, 5.0)))
196
+ assert_equal( Vector3.new( 0.0, -4.0, 1.0), @plane.project(Vector3.new(0.0, -4.0, 1.0)))
197
+ plane2 = Plane.new( Vector3.new(1,1,1), Vector3.new(1,1,0))
198
+ assert_equal( Vector3.new( 1,1,5), plane2.project( Vector3.new( 0,0,5)))
199
+ end
200
+ end
@@ -1,93 +1,93 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class PolylineTestCase < MiniTest::Unit::TestCase
9
- def setup
10
- @vertices = Array.new(6)
11
- @vertices[0] = Vector3.new(1,0,0)
12
- @vertices[1] = Vector3.new(2.0,0,0)
13
- @vertices[2] = Vector3.new(3,1,0)
14
- @vertices[3] = Vector3.new(2,2,1)
15
- @vertices[4] = Vector3.new(1,2,0)
16
- @vertices[5] = Vector3.new(0,1,0)
17
- @polyline_open = Polyline.new(@vertices, true)
18
- @polyline_closed = Polyline.new(@vertices, false)
19
- end
20
-
21
- def test_initialize
22
- idx = 0
23
- @vertices.each do |vertex|
24
- assert_equal(@polyline_open.vertices[idx], vertex)
25
- assert_equal(@polyline_closed.vertices[idx], vertex)
26
- idx += 1
27
- end
28
- assert_equal( true, @polyline_open.is_open )
29
- assert_equal( false, @polyline_closed.is_open )
30
- end
31
-
32
- def test_equals
33
- shallow_copied = @polyline_open
34
- assert(@polyline_open.equal?(shallow_copied))
35
- assert(@polyline_open == shallow_copied)
36
- assert(@polyline_open != nil)
37
- assert(@polyline_open != "string")
38
-
39
- assert(@polyline_open != @polyline_closed)
40
-
41
- polyline_new_open = Polyline.new(@vertices, true)
42
- assert(!@polyline_open.equal?(polyline_new_open))
43
- assert(@polyline_open == polyline_new_open)
44
- assert_equal(@polyline_open, polyline_new_open)
45
-
46
- new_vertices = @vertices.clone
47
- new_vertices.push( Vector3.new(3,4,5))
48
- polyline_new_open = Polyline.new(new_vertices, true)
49
- assert(polyline_new_open != @polyline_open)
50
- assert(@polyline_open != polyline_new_open)
51
- end
52
-
53
- def test_clone
54
- shallow_copied = @polyline_open
55
- vert_cnt = @polyline_open.vertices.size
56
- shallow_copied.vertices[vert_cnt - 1].x = 20
57
- assert(@polyline_open == shallow_copied)
58
- assert(@polyline_open.equal?(shallow_copied))
59
- assert_equal(20, @polyline_open.vertices[vert_cnt - 1].x)
60
- assert_equal(20, shallow_copied.vertices[vert_cnt - 1].x)
61
-
62
- cloned = @polyline_open.clone
63
- assert(@polyline_open == cloned)
64
- assert(!@polyline_open.equal?(cloned))
65
-
66
- cloned.vertices[vert_cnt - 1].x = -20
67
- assert_equal(-20, cloned.vertices[vert_cnt - 1].x)
68
- assert_equal(20, @polyline_open.vertices[vert_cnt - 1].x) # original never changed in editing cloned one.
69
-
70
- cloned.is_open = false
71
- assert_equal(false, cloned.is_open)
72
- assert_equal(true, @polyline_open.is_open)
73
- end
74
-
75
- def test_to_s
76
- assert_equal("Polyline[[1, 0, 0], [2.0, 0, 0], [3, 1, 0], [2, 2, 1], [1, 2, 0], [0, 1, 0]] open",
77
- @polyline_open.to_s);
78
- assert_equal("Polyline[[1, 0, 0], [2.0, 0, 0], [3, 1, 0], [2, 2, 1], [1, 2, 0], [0, 1, 0]] closed",
79
- @polyline_closed.to_s);
80
- end
81
-
82
- def test_box
83
- assert_equal(Vector3.new(0,0,0), @polyline_open.box.min_point)
84
- assert_equal(Vector3.new(3,2,1), @polyline_open.box.max_point)
85
- assert_equal(Vector3.new(0,0,0), @polyline_closed.box.min_point)
86
- assert_equal(Vector3.new(3,2,1), @polyline_closed.box.max_point)
87
- end
88
-
89
- def test_center
90
- assert_equal(Vector3.new(1.5, 1.0, 1.0/6.0), @polyline_open.center)
91
- assert_equal(Vector3.new(1.5, 1.0, 1.0/6.0), @polyline_closed.center)
92
- end
93
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class PolylineTestCase < MiniTest::Unit::TestCase
9
+ def setup
10
+ @vertices = Array.new(6)
11
+ @vertices[0] = Vector3.new(1,0,0)
12
+ @vertices[1] = Vector3.new(2.0,0,0)
13
+ @vertices[2] = Vector3.new(3,1,0)
14
+ @vertices[3] = Vector3.new(2,2,1)
15
+ @vertices[4] = Vector3.new(1,2,0)
16
+ @vertices[5] = Vector3.new(0,1,0)
17
+ @polyline_open = Polyline.new(@vertices, true)
18
+ @polyline_closed = Polyline.new(@vertices, false)
19
+ end
20
+
21
+ def test_initialize
22
+ idx = 0
23
+ @vertices.each do |vertex|
24
+ assert_equal(@polyline_open.vertices[idx], vertex)
25
+ assert_equal(@polyline_closed.vertices[idx], vertex)
26
+ idx += 1
27
+ end
28
+ assert_equal( true, @polyline_open.is_open )
29
+ assert_equal( false, @polyline_closed.is_open )
30
+ end
31
+
32
+ def test_equals
33
+ shallow_copied = @polyline_open
34
+ assert(@polyline_open.equal?(shallow_copied))
35
+ assert(@polyline_open == shallow_copied)
36
+ assert(@polyline_open != nil)
37
+ assert(@polyline_open != "string")
38
+
39
+ assert(@polyline_open != @polyline_closed)
40
+
41
+ polyline_new_open = Polyline.new(@vertices, true)
42
+ assert(!@polyline_open.equal?(polyline_new_open))
43
+ assert(@polyline_open == polyline_new_open)
44
+ assert_equal(@polyline_open, polyline_new_open)
45
+
46
+ new_vertices = @vertices.clone
47
+ new_vertices.push( Vector3.new(3,4,5))
48
+ polyline_new_open = Polyline.new(new_vertices, true)
49
+ assert(polyline_new_open != @polyline_open)
50
+ assert(@polyline_open != polyline_new_open)
51
+ end
52
+
53
+ def test_clone
54
+ shallow_copied = @polyline_open
55
+ vert_cnt = @polyline_open.vertices.size
56
+ shallow_copied.vertices[vert_cnt - 1].x = 20
57
+ assert(@polyline_open == shallow_copied)
58
+ assert(@polyline_open.equal?(shallow_copied))
59
+ assert_equal(20, @polyline_open.vertices[vert_cnt - 1].x)
60
+ assert_equal(20, shallow_copied.vertices[vert_cnt - 1].x)
61
+
62
+ cloned = @polyline_open.clone
63
+ assert(@polyline_open == cloned)
64
+ assert(!@polyline_open.equal?(cloned))
65
+
66
+ cloned.vertices[vert_cnt - 1].x = -20
67
+ assert_equal(-20, cloned.vertices[vert_cnt - 1].x)
68
+ assert_equal(20, @polyline_open.vertices[vert_cnt - 1].x) # original never changed in editing cloned one.
69
+
70
+ cloned.is_open = false
71
+ assert_equal(false, cloned.is_open)
72
+ assert_equal(true, @polyline_open.is_open)
73
+ end
74
+
75
+ def test_to_s
76
+ assert_equal("Polyline[[1, 0, 0], [2.0, 0, 0], [3, 1, 0], [2, 2, 1], [1, 2, 0], [0, 1, 0]] open",
77
+ @polyline_open.to_s);
78
+ assert_equal("Polyline[[1, 0, 0], [2.0, 0, 0], [3, 1, 0], [2, 2, 1], [1, 2, 0], [0, 1, 0]] closed",
79
+ @polyline_closed.to_s);
80
+ end
81
+
82
+ def test_box
83
+ assert_equal(Vector3.new(0,0,0), @polyline_open.box.min_point)
84
+ assert_equal(Vector3.new(3,2,1), @polyline_open.box.max_point)
85
+ assert_equal(Vector3.new(0,0,0), @polyline_closed.box.min_point)
86
+ assert_equal(Vector3.new(3,2,1), @polyline_closed.box.max_point)
87
+ end
88
+
89
+ def test_center
90
+ assert_equal(Vector3.new(1.5, 1.0, 1.0/6.0), @polyline_open.center)
91
+ assert_equal(Vector3.new(1.5, 1.0, 1.0/6.0), @polyline_closed.center)
92
+ end
93
+ end