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_quat.rb CHANGED
@@ -1,144 +1,144 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class QuatTestCase < MiniTest::Unit::TestCase
9
- def setup
10
- @quat_default = Quat.new()
11
- @quat1 = Quat.new(2.0, 3.0, 4.0, 1.0)
12
- @quat2 = Quat.new(6.0, 7.0, 8.0, 5.0)
13
- end
14
-
15
- def test_initalize
16
- assert_equal(0, @quat_default.x)
17
- assert_equal(0, @quat_default.y)
18
- assert_equal(0, @quat_default.z)
19
- assert_equal(0, @quat_default.w)
20
-
21
- assert_equal(2.0, @quat1.x)
22
- assert_equal(3.0, @quat1.y)
23
- assert_equal(4.0, @quat1.z)
24
- assert_equal(1.0, @quat1.w)
25
-
26
- assert_raises ArgumentError do
27
- invalidResult = Quat.new( "hoge" )
28
- end
29
- end
30
-
31
- def test_from_axis
32
- axis = Vector3.new(1.0, 0.0, 0.0)
33
- rad = 30.0*Math::PI / 180
34
- rot_quat = Quat.from_axis(axis, rad)
35
- assert_equal( Math.cos(rad/2.0), rot_quat.w)
36
- assert_equal( Math.sin(rad/2.0), rot_quat.x)
37
- assert_equal( 0.0, rot_quat.y)
38
- assert_equal( 0.0, rot_quat.z)
39
- end
40
-
41
- def test_from_matrix
42
- axis = Vector3.new(1,2,4).normalize()
43
- angle = 46*Math::PI/180
44
- mat = Matrix.from_axis(axis, angle)
45
- quat_expected = Quat.from_axis(axis, angle)
46
- quat_actual = Quat.from_matrix(mat)
47
- assert_equal(quat_expected, quat_actual)
48
- end
49
-
50
- def test_to_s
51
- assert_equal("Quat[2.0, 3.0, 4.0, 1.0]", @quat1.to_s)
52
- end
53
-
54
- def test_assign_value
55
- assert_equal(2.0, @quat1.x)
56
- assert_equal(3.0, @quat1.y)
57
- assert_equal(4.0, @quat1.z)
58
- assert_equal(1.0, @quat1.w)
59
-
60
- @quat1.x = 2.0
61
- @quat1.y *= 2.0
62
- @quat1.z -= 3.0
63
- @quat1.w /= 2.0
64
-
65
- assert_equal(2.0, @quat1.x)
66
- assert_equal(6.0, @quat1.y)
67
- assert_equal(1.0, @quat1.z)
68
- assert_equal(0.5, @quat1.w)
69
- end
70
-
71
- def test_equals
72
- assert(!(@quat_default == @quat1))
73
- assert(@quat_default != @quat1)
74
-
75
- assert(@quat1 == @quat1)
76
-
77
- quat = Quat.new(2,3,4,1)
78
- assert(@quat1 == quat)
79
-
80
- #invlid value comparison
81
- assert(@quat1 != "string")
82
- assert(@quat1 != -4)
83
- end
84
-
85
- def test_conjugate
86
- quat1_conjugate = @quat1.conjugate()
87
- quat2_conjugate = @quat2.conjugate()
88
-
89
- assert_equal(-2.0, quat1_conjugate.x)
90
- assert_equal(-3.0, quat1_conjugate.y)
91
- assert_equal(-4.0, quat1_conjugate.z)
92
- assert_equal( 1.0, quat1_conjugate.w)
93
- assert_equal(-6.0, quat2_conjugate.x)
94
- assert_equal(-7.0, quat2_conjugate.y)
95
- assert_equal(-8.0, quat2_conjugate.z)
96
- assert_equal( 5.0, quat2_conjugate.w)
97
- end
98
-
99
- def test_add
100
- # implemented, but how to validate?
101
- end
102
-
103
- def test_add_invalid_value
104
- assert_raises ArgumentError do
105
- invalidResult = @quat1 + 5
106
- end
107
- assert_raises ArgumentError do
108
- invalidResult = @quat1 + nil
109
- end
110
- end
111
-
112
- def test_multiply
113
- multiply = @quat1 * @quat2
114
- assert_equal(-60, multiply.w)
115
- assert_equal( 12, multiply.x)
116
- assert_equal( 30, multiply.y)
117
- assert_equal( 24, multiply.z)
118
-
119
- @quat1 *= @quat2
120
- assert_equal(-60, @quat1.w)
121
- assert_equal( 12, @quat1.x)
122
- assert_equal( 30, @quat1.y)
123
- assert_equal( 24, @quat1.z)
124
- end
125
-
126
- def test_multiply_invalid_value
127
- assert_raises ArgumentError do
128
- invalidResult = @quat1 * 3
129
- end
130
- assert_raises ArgumentError do
131
- invalidResult = @quat2 * nil
132
- end
133
- end
134
-
135
- def test_normalize
136
- quat = Quat.new(-1,2,1,1)
137
- quat = quat.normalize()
138
- assert_equal(-1/Math.sqrt(6), quat.x)
139
- assert_equal( 2/Math.sqrt(6), quat.y)
140
- assert_equal( 1/Math.sqrt(6), quat.z)
141
- assert_equal( 1/Math.sqrt(6), quat.w)
142
- end
143
-
144
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class QuatTestCase < MiniTest::Unit::TestCase
9
+ def setup
10
+ @quat_default = Quat.new()
11
+ @quat1 = Quat.new(2.0, 3.0, 4.0, 1.0)
12
+ @quat2 = Quat.new(6.0, 7.0, 8.0, 5.0)
13
+ end
14
+
15
+ def test_initalize
16
+ assert_equal(0, @quat_default.x)
17
+ assert_equal(0, @quat_default.y)
18
+ assert_equal(0, @quat_default.z)
19
+ assert_equal(0, @quat_default.w)
20
+
21
+ assert_equal(2.0, @quat1.x)
22
+ assert_equal(3.0, @quat1.y)
23
+ assert_equal(4.0, @quat1.z)
24
+ assert_equal(1.0, @quat1.w)
25
+
26
+ assert_raises ArgumentError do
27
+ invalidResult = Quat.new( "hoge" )
28
+ end
29
+ end
30
+
31
+ def test_from_axis
32
+ axis = Vector3.new(1.0, 0.0, 0.0)
33
+ rad = 30.0*Math::PI / 180
34
+ rot_quat = Quat.from_axis(axis, rad)
35
+ assert_equal( Math.cos(rad/2.0), rot_quat.w)
36
+ assert_equal( Math.sin(rad/2.0), rot_quat.x)
37
+ assert_equal( 0.0, rot_quat.y)
38
+ assert_equal( 0.0, rot_quat.z)
39
+ end
40
+
41
+ def test_from_matrix
42
+ axis = Vector3.new(1,2,4).normalize()
43
+ angle = 46*Math::PI/180
44
+ mat = Matrix.from_axis(axis, angle)
45
+ quat_expected = Quat.from_axis(axis, angle)
46
+ quat_actual = Quat.from_matrix(mat)
47
+ assert_equal(quat_expected, quat_actual)
48
+ end
49
+
50
+ def test_to_s
51
+ assert_equal("Quat[2.0, 3.0, 4.0, 1.0]", @quat1.to_s)
52
+ end
53
+
54
+ def test_assign_value
55
+ assert_equal(2.0, @quat1.x)
56
+ assert_equal(3.0, @quat1.y)
57
+ assert_equal(4.0, @quat1.z)
58
+ assert_equal(1.0, @quat1.w)
59
+
60
+ @quat1.x = 2.0
61
+ @quat1.y *= 2.0
62
+ @quat1.z -= 3.0
63
+ @quat1.w /= 2.0
64
+
65
+ assert_equal(2.0, @quat1.x)
66
+ assert_equal(6.0, @quat1.y)
67
+ assert_equal(1.0, @quat1.z)
68
+ assert_equal(0.5, @quat1.w)
69
+ end
70
+
71
+ def test_equals
72
+ assert(!(@quat_default == @quat1))
73
+ assert(@quat_default != @quat1)
74
+
75
+ assert(@quat1 == @quat1)
76
+
77
+ quat = Quat.new(2,3,4,1)
78
+ assert(@quat1 == quat)
79
+
80
+ #invlid value comparison
81
+ assert(@quat1 != "string")
82
+ assert(@quat1 != -4)
83
+ end
84
+
85
+ def test_conjugate
86
+ quat1_conjugate = @quat1.conjugate()
87
+ quat2_conjugate = @quat2.conjugate()
88
+
89
+ assert_equal(-2.0, quat1_conjugate.x)
90
+ assert_equal(-3.0, quat1_conjugate.y)
91
+ assert_equal(-4.0, quat1_conjugate.z)
92
+ assert_equal( 1.0, quat1_conjugate.w)
93
+ assert_equal(-6.0, quat2_conjugate.x)
94
+ assert_equal(-7.0, quat2_conjugate.y)
95
+ assert_equal(-8.0, quat2_conjugate.z)
96
+ assert_equal( 5.0, quat2_conjugate.w)
97
+ end
98
+
99
+ def test_add
100
+ # implemented, but how to validate?
101
+ end
102
+
103
+ def test_add_invalid_value
104
+ assert_raises ArgumentError do
105
+ invalidResult = @quat1 + 5
106
+ end
107
+ assert_raises ArgumentError do
108
+ invalidResult = @quat1 + nil
109
+ end
110
+ end
111
+
112
+ def test_multiply
113
+ multiply = @quat1 * @quat2
114
+ assert_equal(-60, multiply.w)
115
+ assert_equal( 12, multiply.x)
116
+ assert_equal( 30, multiply.y)
117
+ assert_equal( 24, multiply.z)
118
+
119
+ @quat1 *= @quat2
120
+ assert_equal(-60, @quat1.w)
121
+ assert_equal( 12, @quat1.x)
122
+ assert_equal( 30, @quat1.y)
123
+ assert_equal( 24, @quat1.z)
124
+ end
125
+
126
+ def test_multiply_invalid_value
127
+ assert_raises ArgumentError do
128
+ invalidResult = @quat1 * 3
129
+ end
130
+ assert_raises ArgumentError do
131
+ invalidResult = @quat2 * nil
132
+ end
133
+ end
134
+
135
+ def test_normalize
136
+ quat = Quat.new(-1,2,1,1)
137
+ quat = quat.normalize()
138
+ assert_equal(-1/Math.sqrt(6), quat.x)
139
+ assert_equal( 2/Math.sqrt(6), quat.y)
140
+ assert_equal( 1/Math.sqrt(6), quat.z)
141
+ assert_equal( 1/Math.sqrt(6), quat.w)
142
+ end
143
+
144
+ end
@@ -1,184 +1,184 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class RectangleTestCase < MiniTest::Unit::TestCase
9
- def setup
10
- @rectangle = Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2))
11
- @rectangle_default = Rectangle.new()
12
- end
13
-
14
- def test_initialize
15
- assert_equal(Vector3.new(1, 2,3), @rectangle.base_point)
16
- assert_equal(Vector3.new(0,-0.5,0), @rectangle.u_vector)
17
- assert_equal(Vector3.new(0, 0,2), @rectangle.v_vector)
18
-
19
- assert_equal(Vector3.new(0,0,0), @rectangle_default.base_point)
20
- assert_equal(Vector3.new(1,0,0), @rectangle_default.u_vector)
21
- assert_equal(Vector3.new(0,1,0), @rectangle_default.v_vector)
22
- end
23
-
24
- def test_equals
25
- assert(@rectangle != nil)
26
- assert(@rectangle != "string")
27
-
28
- shallow_copied = @rectangle
29
- assert(@rectangle.equal?(shallow_copied))
30
- assert(@rectangle == shallow_copied)
31
-
32
- assert_equal(@rectangle, Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2)))
33
- assert(@rectangle == Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2.0)))
34
- assert(@rectangle != Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2.2)))
35
- end
36
-
37
- def test_clone
38
- shallow_copied = @rectangle
39
- shallow_copied.base_point.x = -1
40
- assert(@rectangle == shallow_copied)
41
- assert(@rectangle.equal?(shallow_copied))
42
- assert_equal(-1, shallow_copied.base_point.x)
43
- assert_equal(-1, @rectangle.base_point.x)
44
-
45
- cloned = @rectangle.clone
46
- assert(@rectangle == cloned)
47
- assert(!@rectangle.equal?(cloned))
48
- cloned.base_point.x = -2
49
- cloned.u_vector.x = 4
50
- cloned.v_vector.z = 6
51
- assert_equal(-2, cloned.base_point.x)
52
- assert_equal(4, cloned.u_vector.x)
53
- assert_equal(6, cloned.v_vector.z)
54
-
55
- assert_equal(-1, @rectangle.base_point.x) # original never changed in editing cloned one.
56
- assert_equal(0, @rectangle.u_vector.x)
57
- assert_equal(2, @rectangle.v_vector.z)
58
- end
59
-
60
- def test_to_s
61
- assert_equal("Rectangle[base[1, 2, 3], u[0, -0.5, 0], v[0, 0, 2]", @rectangle.to_s)
62
- end
63
-
64
- def test_box
65
- box1 = @rectangle.box
66
- box2 = @rectangle_default.box
67
- assert_equal(Vector3.new(1, 1.5, 3), box1.min_point)
68
- assert_equal(Vector3.new(1, 2, 5), box1.max_point)
69
- assert_equal(Vector3.new(0, 0, 0), box2.min_point)
70
- assert_equal(Vector3.new(1, 1, 0), box2.max_point)
71
- end
72
-
73
- def test_point
74
- point = @rectangle.point(0.2, 1.0)
75
- assert_equal(Vector3.new(1, 1.9, 5), point)
76
-
77
- point = @rectangle.point(-2.0, 0.5)
78
- assert_equal(Vector3.new(1, 3, 4), point)
79
-
80
- point = @rectangle_default.point(0,0)
81
- assert_equal(Vector3.new(0,0,0), point)
82
-
83
- point = @rectangle_default.point(0.5, 0.5)
84
- assert_equal(@rectangle_default.center_point, point)
85
- end
86
-
87
- def test_edges
88
- edges = @rectangle.edges
89
- assert_equal(4, edges.size)
90
- assert_equal(Vector3.new(1,2, 3), edges[0].start_point)
91
- assert_equal(Vector3.new(1,1.5,3), edges[0].end_point)
92
- assert_equal(Vector3.new(1,1.5,3), edges[1].start_point)
93
- assert_equal(Vector3.new(1,1.5,5), edges[1].end_point)
94
- assert_equal(Vector3.new(1,1.5,5), edges[2].start_point)
95
- assert_equal(Vector3.new(1,2 ,5), edges[2].end_point)
96
- assert_equal(Vector3.new(1,2 ,5), edges[3].start_point)
97
- assert_equal(Vector3.new(1,2 ,3), edges[3].end_point)
98
- end
99
-
100
- def test_vertices
101
- vertices = @rectangle.vertices
102
- assert_equal(4, vertices.size)
103
- assert_equal(Vector3.new(1,2,3), vertices[0])
104
- assert_equal(Vector3.new(1,1.5,3), vertices[1])
105
- assert_equal(Vector3.new(1,1.5,5), vertices[2])
106
- assert_equal(Vector3.new(1,2,5), vertices[3])
107
- end
108
-
109
- def test_normal
110
- assert_equal(Vector3.new(-1,0,0), @rectangle.normal)
111
- assert_equal(Vector3.new(0,0,1), @rectangle_default.normal)
112
- end
113
-
114
- def test_opposite_point
115
- assert_equal(Vector3.new(1,1.5,5), @rectangle.opposite_point)
116
- assert_equal(Vector3.new(1,1,0), @rectangle_default.opposite_point)
117
- end
118
-
119
- def test_center_point
120
- assert_equal(Vector3.new(1,1.75,4), @rectangle.center_point)
121
- assert_equal(Vector3.new(0.5,0.5,0), @rectangle_default.center_point)
122
- end
123
-
124
- def test_area
125
- assert_in_delta( 1.0, @rectangle.area, @rectangle.tolerance)
126
- assert_in_delta( 1.0, @rectangle_default.area, @rectangle_default.tolerance)
127
- end
128
-
129
- def test_uv_param
130
- # inside case
131
- check_point = @rectangle.center_point
132
- u, v = @rectangle.uv_parameter(check_point)
133
- assert_in_delta(0.5, u, @rectangle.tolerance)
134
- assert_in_delta(0.5, v, @rectangle.tolerance)
135
-
136
- # inside case2
137
- check_point = @rectangle.point(0.3,0.6) + @rectangle.normal*1.0
138
- u, v = @rectangle.uv_parameter(check_point)
139
- assert_in_delta(0.3, u, @rectangle.tolerance)
140
- assert_in_delta(0.6, v, @rectangle.tolerance)
141
-
142
- # on edge
143
- u, v = @rectangle.uv_parameter(Vector3.new(2, 1.75, 5))
144
- assert_in_delta(0.5, u, @rectangle.tolerance)
145
- assert_in_delta(1, v, @rectangle.tolerance)
146
-
147
- # on vertex
148
- u, v = @rectangle.uv_parameter(@rectangle.opposite_point)
149
- assert_in_delta(1.0, u, @rectangle.tolerance)
150
- assert_in_delta(1, v, @rectangle.tolerance)
151
-
152
- # outside case1
153
- u, v = @rectangle.uv_parameter(@rectangle.point(2.0, -3.0))
154
- assert_in_delta(2.0, u, @rectangle.tolerance)
155
- assert_in_delta(-3.0, v, @rectangle.tolerance)
156
- end
157
-
158
- def test_distance_to_point
159
- # inside case
160
- distance, point_on_rectangle = @rectangle.distance(Vector3.new(0.5,1.75,4.5))
161
- assert_in_delta( 0.5, distance, @rectangle.tolerance)
162
- assert_equal(Vector3.new(1, 1.75, 4.5), point_on_rectangle)
163
-
164
- # on edge
165
- distance, point_on_rectangle = @rectangle.distance(Vector3.new(2.0,1.5,4.5))
166
- assert_in_delta( 1.0, distance, @rectangle.tolerance)
167
- assert_equal(Vector3.new(1, 1.5, 4.5), point_on_rectangle)
168
-
169
- # on vertex
170
- distance, point_on_rectangle = @rectangle.distance(Vector3.new(-0.5,2,3))
171
- assert_in_delta( 1.5, distance, @rectangle.tolerance)
172
- assert_equal(Vector3.new(1,2,3), point_on_rectangle)
173
-
174
- # outside on edge
175
- distance, point_on_rectangle = @rectangle.distance(Vector3.new(0,1.75,2))
176
- assert_in_delta( Math::sqrt(2), distance, @rectangle.tolerance)
177
- assert_equal(Vector3.new(1,1.75,3), point_on_rectangle)
178
-
179
- # outside on vertex
180
- distance, point_on_rectangle = @rectangle.distance(Vector3.new(0,0,0))
181
- assert_in_delta( Math::sqrt(12.25), distance, @rectangle.tolerance)
182
- assert_equal(Vector3.new(1,1.5,3), point_on_rectangle)
183
- end
184
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class RectangleTestCase < MiniTest::Unit::TestCase
9
+ def setup
10
+ @rectangle = Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2))
11
+ @rectangle_default = Rectangle.new()
12
+ end
13
+
14
+ def test_initialize
15
+ assert_equal(Vector3.new(1, 2,3), @rectangle.base_point)
16
+ assert_equal(Vector3.new(0,-0.5,0), @rectangle.u_vector)
17
+ assert_equal(Vector3.new(0, 0,2), @rectangle.v_vector)
18
+
19
+ assert_equal(Vector3.new(0,0,0), @rectangle_default.base_point)
20
+ assert_equal(Vector3.new(1,0,0), @rectangle_default.u_vector)
21
+ assert_equal(Vector3.new(0,1,0), @rectangle_default.v_vector)
22
+ end
23
+
24
+ def test_equals
25
+ assert(@rectangle != nil)
26
+ assert(@rectangle != "string")
27
+
28
+ shallow_copied = @rectangle
29
+ assert(@rectangle.equal?(shallow_copied))
30
+ assert(@rectangle == shallow_copied)
31
+
32
+ assert_equal(@rectangle, Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2)))
33
+ assert(@rectangle == Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2.0)))
34
+ assert(@rectangle != Rectangle.new( Vector3.new(1,2,3), Vector3.new(0,-0.5,0), Vector3.new(0,0,2.2)))
35
+ end
36
+
37
+ def test_clone
38
+ shallow_copied = @rectangle
39
+ shallow_copied.base_point.x = -1
40
+ assert(@rectangle == shallow_copied)
41
+ assert(@rectangle.equal?(shallow_copied))
42
+ assert_equal(-1, shallow_copied.base_point.x)
43
+ assert_equal(-1, @rectangle.base_point.x)
44
+
45
+ cloned = @rectangle.clone
46
+ assert(@rectangle == cloned)
47
+ assert(!@rectangle.equal?(cloned))
48
+ cloned.base_point.x = -2
49
+ cloned.u_vector.x = 4
50
+ cloned.v_vector.z = 6
51
+ assert_equal(-2, cloned.base_point.x)
52
+ assert_equal(4, cloned.u_vector.x)
53
+ assert_equal(6, cloned.v_vector.z)
54
+
55
+ assert_equal(-1, @rectangle.base_point.x) # original never changed in editing cloned one.
56
+ assert_equal(0, @rectangle.u_vector.x)
57
+ assert_equal(2, @rectangle.v_vector.z)
58
+ end
59
+
60
+ def test_to_s
61
+ assert_equal("Rectangle[base[1, 2, 3], u[0, -0.5, 0], v[0, 0, 2]", @rectangle.to_s)
62
+ end
63
+
64
+ def test_box
65
+ box1 = @rectangle.box
66
+ box2 = @rectangle_default.box
67
+ assert_equal(Vector3.new(1, 1.5, 3), box1.min_point)
68
+ assert_equal(Vector3.new(1, 2, 5), box1.max_point)
69
+ assert_equal(Vector3.new(0, 0, 0), box2.min_point)
70
+ assert_equal(Vector3.new(1, 1, 0), box2.max_point)
71
+ end
72
+
73
+ def test_point
74
+ point = @rectangle.point(0.2, 1.0)
75
+ assert_equal(Vector3.new(1, 1.9, 5), point)
76
+
77
+ point = @rectangle.point(-2.0, 0.5)
78
+ assert_equal(Vector3.new(1, 3, 4), point)
79
+
80
+ point = @rectangle_default.point(0,0)
81
+ assert_equal(Vector3.new(0,0,0), point)
82
+
83
+ point = @rectangle_default.point(0.5, 0.5)
84
+ assert_equal(@rectangle_default.center_point, point)
85
+ end
86
+
87
+ def test_edges
88
+ edges = @rectangle.edges
89
+ assert_equal(4, edges.size)
90
+ assert_equal(Vector3.new(1,2, 3), edges[0].start_point)
91
+ assert_equal(Vector3.new(1,1.5,3), edges[0].end_point)
92
+ assert_equal(Vector3.new(1,1.5,3), edges[1].start_point)
93
+ assert_equal(Vector3.new(1,1.5,5), edges[1].end_point)
94
+ assert_equal(Vector3.new(1,1.5,5), edges[2].start_point)
95
+ assert_equal(Vector3.new(1,2 ,5), edges[2].end_point)
96
+ assert_equal(Vector3.new(1,2 ,5), edges[3].start_point)
97
+ assert_equal(Vector3.new(1,2 ,3), edges[3].end_point)
98
+ end
99
+
100
+ def test_vertices
101
+ vertices = @rectangle.vertices
102
+ assert_equal(4, vertices.size)
103
+ assert_equal(Vector3.new(1,2,3), vertices[0])
104
+ assert_equal(Vector3.new(1,1.5,3), vertices[1])
105
+ assert_equal(Vector3.new(1,1.5,5), vertices[2])
106
+ assert_equal(Vector3.new(1,2,5), vertices[3])
107
+ end
108
+
109
+ def test_normal
110
+ assert_equal(Vector3.new(-1,0,0), @rectangle.normal)
111
+ assert_equal(Vector3.new(0,0,1), @rectangle_default.normal)
112
+ end
113
+
114
+ def test_opposite_point
115
+ assert_equal(Vector3.new(1,1.5,5), @rectangle.opposite_point)
116
+ assert_equal(Vector3.new(1,1,0), @rectangle_default.opposite_point)
117
+ end
118
+
119
+ def test_center_point
120
+ assert_equal(Vector3.new(1,1.75,4), @rectangle.center_point)
121
+ assert_equal(Vector3.new(0.5,0.5,0), @rectangle_default.center_point)
122
+ end
123
+
124
+ def test_area
125
+ assert_in_delta( 1.0, @rectangle.area, @rectangle.tolerance)
126
+ assert_in_delta( 1.0, @rectangle_default.area, @rectangle_default.tolerance)
127
+ end
128
+
129
+ def test_uv_param
130
+ # inside case
131
+ check_point = @rectangle.center_point
132
+ u, v = @rectangle.uv_parameter(check_point)
133
+ assert_in_delta(0.5, u, @rectangle.tolerance)
134
+ assert_in_delta(0.5, v, @rectangle.tolerance)
135
+
136
+ # inside case2
137
+ check_point = @rectangle.point(0.3,0.6) + @rectangle.normal*1.0
138
+ u, v = @rectangle.uv_parameter(check_point)
139
+ assert_in_delta(0.3, u, @rectangle.tolerance)
140
+ assert_in_delta(0.6, v, @rectangle.tolerance)
141
+
142
+ # on edge
143
+ u, v = @rectangle.uv_parameter(Vector3.new(2, 1.75, 5))
144
+ assert_in_delta(0.5, u, @rectangle.tolerance)
145
+ assert_in_delta(1, v, @rectangle.tolerance)
146
+
147
+ # on vertex
148
+ u, v = @rectangle.uv_parameter(@rectangle.opposite_point)
149
+ assert_in_delta(1.0, u, @rectangle.tolerance)
150
+ assert_in_delta(1, v, @rectangle.tolerance)
151
+
152
+ # outside case1
153
+ u, v = @rectangle.uv_parameter(@rectangle.point(2.0, -3.0))
154
+ assert_in_delta(2.0, u, @rectangle.tolerance)
155
+ assert_in_delta(-3.0, v, @rectangle.tolerance)
156
+ end
157
+
158
+ def test_distance_to_point
159
+ # inside case
160
+ distance, point_on_rectangle = @rectangle.distance(Vector3.new(0.5,1.75,4.5))
161
+ assert_in_delta( 0.5, distance, @rectangle.tolerance)
162
+ assert_equal(Vector3.new(1, 1.75, 4.5), point_on_rectangle)
163
+
164
+ # on edge
165
+ distance, point_on_rectangle = @rectangle.distance(Vector3.new(2.0,1.5,4.5))
166
+ assert_in_delta( 1.0, distance, @rectangle.tolerance)
167
+ assert_equal(Vector3.new(1, 1.5, 4.5), point_on_rectangle)
168
+
169
+ # on vertex
170
+ distance, point_on_rectangle = @rectangle.distance(Vector3.new(-0.5,2,3))
171
+ assert_in_delta( 1.5, distance, @rectangle.tolerance)
172
+ assert_equal(Vector3.new(1,2,3), point_on_rectangle)
173
+
174
+ # outside on edge
175
+ distance, point_on_rectangle = @rectangle.distance(Vector3.new(0,1.75,2))
176
+ assert_in_delta( Math::sqrt(2), distance, @rectangle.tolerance)
177
+ assert_equal(Vector3.new(1,1.75,3), point_on_rectangle)
178
+
179
+ # outside on vertex
180
+ distance, point_on_rectangle = @rectangle.distance(Vector3.new(0,0,0))
181
+ assert_in_delta( Math::sqrt(12.25), distance, @rectangle.tolerance)
182
+ assert_equal(Vector3.new(1,1.5,3), point_on_rectangle)
183
+ end
184
+ end