gmath3D 0.2.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb CHANGED
@@ -1,15 +1,15 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- begin
5
- Bundler.setup(:default, :development)
6
- rescue Bundler::BundlerError => e
7
- $stderr.puts e.message
8
- $stderr.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
10
- end
11
- require 'minitest/unit'
12
-
13
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
-
15
- require 'gmath3D'
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'minitest/unit'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ require 'gmath3D'
data/test/test_box.rb CHANGED
@@ -1,167 +1,172 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class BoxTestCase < MiniTest::Unit::TestCase
9
- def setup
10
- @box_default = Box.new()
11
- @box = Box.new(Vector3.new(-3,2,5), Vector3.new(2,-2.5, 0))
12
- end
13
-
14
- def test_to_s
15
- assert_equal( "Box[min[-3, -2.5, 0], max[2, 2, 5]]", @box.to_s)
16
- end
17
-
18
- def test_initalize
19
- assert_equal(0, @box_default.min_point.x)
20
- assert_equal(0, @box_default.min_point.y)
21
- assert_equal(0, @box_default.min_point.z)
22
- assert_equal(1, @box_default.max_point.x)
23
- assert_equal(1, @box_default.max_point.y)
24
- assert_equal(1, @box_default.max_point.z)
25
-
26
- assert_equal(-3.0, @box.min_point.x)
27
- assert_equal(-2.5, @box.min_point.y)
28
- assert_equal(0.0 , @box.min_point.z)
29
- assert_equal(2.0 , @box.max_point.x)
30
- assert_equal(2.0 , @box.max_point.y)
31
- assert_equal(5.0 , @box.max_point.z)
32
-
33
- assert_equal(Geom.default_tolerance, @box_default.tolerance)
34
-
35
- assert_raises ArgumentError do
36
- invalidResult = Box.new(nil)
37
- end
38
- assert_raises ArgumentError do
39
- invalidResult = Box.new(Vector3.new(), 4.0)
40
- end
41
- end
42
-
43
- def test_from_points
44
- points = Array.new(6)
45
- points[0] = Vector3.new( 3, 0, 1)
46
- points[1] = Vector3.new( 2,-2, 10)
47
- points[2] = Vector3.new(-6, 2, -4)
48
- points[3] = Vector3.new( 3, 5, -1)
49
- points[4] = Vector3.new(-2, 2, 2)
50
- points[5] = Vector3.new(11, 1, 0)
51
- box = Box.from_points(points)
52
- assert_equal(Vector3.new(-6, -2, -4), box.min_point)
53
- assert_equal(Vector3.new(11, 5, 10), box.max_point)
54
-
55
- points = Array.new(2)
56
- points[0] = Vector3.new( -3, -2, -1)
57
- points[1] = Vector3.new( -4, -8, -10)
58
- box = Box.from_points(points)
59
- assert_equal(Vector3.new(-4, -8, -10), box.min_point)
60
- assert_equal(Vector3.new(-3, -2, -1), box.max_point)
61
-
62
- points = Array.new(0)
63
- box = Box.from_points(points)
64
- assert_equal(nil, box)
65
- end
66
-
67
- def test_equal
68
- shallow_copied = @box
69
- assert( shallow_copied == @box )
70
- assert( shallow_copied.equal?( @box ) )
71
-
72
- deep_copied = Box.new(Vector3.new(-3,2,5), Vector3.new(2,-2.5, 0))
73
- assert( deep_copied == @box )
74
- assert( !deep_copied.equal?( @box ) )
75
-
76
- assert( @box != 5 )
77
- end
78
-
79
- def test_add
80
- added_box = @box_default + Vector3.new(-2, 0.5, 3)
81
- assert_equal(Vector3.new(-2,0,0), added_box.min_point)
82
- assert_equal(Vector3.new(1,1,3) , added_box.max_point)
83
-
84
- added_box = @box_default + Box.new( Vector3.new(-2,0.5, 3), Vector3.new(4, 0, 2.0))
85
- assert_equal(Vector3.new(-2,0,0), added_box.min_point)
86
- assert_equal(Vector3.new(4,1,3) , added_box.max_point)
87
-
88
- point_ary = [Vector3.new(1,4,9), Vector3.new(4,-2,4), Vector3.new(2,-5,0)]
89
- added_box = @box + point_ary
90
- assert_equal(Vector3.new(-3,-5, 0), added_box.min_point)
91
- assert_equal(Vector3.new( 4, 4, 9), added_box.max_point)
92
-
93
- assert_raises ArgumentError do
94
- invalidResult = @box + 4
95
- end
96
- end
97
-
98
- def test_center
99
- assert_equal( Vector3.new(0.5, 0.5, 0.5), @box_default.center)
100
- assert_equal( Vector3.new(-0.5,-0.25,2.5), @box.center)
101
- end
102
-
103
- def test_length
104
- width, height, depth = @box_default.length
105
- assert_in_delta( 1, width , @box_default.tolerance)
106
- assert_in_delta( 1, height, @box_default.tolerance)
107
- assert_in_delta( 1, depth , @box_default.tolerance)
108
-
109
- width, height, depth = @box.length
110
- assert_in_delta( 5.0, width , @box.tolerance)
111
- assert_in_delta( 4.5, height, @box.tolerance)
112
- assert_in_delta( 5.0, depth , @box.tolerance)
113
- end
114
-
115
- def test_volume
116
- assert_in_delta( 1.0, @box_default.volume, @box_default.tolerance )
117
- assert_in_delta( 112.5, @box.volume, @box.tolerance )
118
- end
119
-
120
- def test_vertices
121
- verts = @box_default.vertices
122
- assert(verts.include?(Vector3.new(0,0,0)))
123
- assert(verts.include?(Vector3.new(1,0,0)))
124
- assert(verts.include?(Vector3.new(1,1,0)))
125
- assert(verts.include?(Vector3.new(0,1,0)))
126
- assert(verts.include?(Vector3.new(0,0,1)))
127
- assert(verts.include?(Vector3.new(1,0,1)))
128
- assert(verts.include?(Vector3.new(1,1,1)))
129
- assert(verts.include?(Vector3.new(0,1,1)))
130
-
131
- verts = @box.vertices #.new(-3,2,5), Vector3.new(2,-2.5, 0))
132
- assert(verts.include?(Vector3.new(-3, -2.5, 0)))
133
- assert(verts.include?(Vector3.new( 2, -2.5, 0)))
134
- assert(verts.include?(Vector3.new( 2, 2.0, 0)))
135
- assert(verts.include?(Vector3.new(-3, 2.0, 0)))
136
- assert(verts.include?(Vector3.new(-3, -2.5, 5)))
137
- assert(verts.include?(Vector3.new( 2, -2.5, 5)))
138
- assert(verts.include?(Vector3.new( 2, 2.0, 5)))
139
- assert(verts.include?(Vector3.new(-3, 2.0, 5)))
140
- end
141
-
142
- def test_translate
143
- trans = Vector3.new(1,2.5,-0.5)
144
- translated = @box_default.translate(trans)
145
- assert_equal(Box.new(Vector3.new(1,2.5,-0.5), Vector3.new(2,3.5,0.5)), translated)
146
-
147
- # this procedure is not destructive
148
- assert_equal(Box.new(Vector3.new(0,0,0), Vector3.new(1,1,1)), @box_default)
149
- end
150
-
151
- def test_rotate
152
- angle_90 = 90.0*Math::PI/180.0
153
- angle_45 = 45.0*Math::PI/180.0
154
- rotation1 = Quat.from_axis(Vector3.new(0,0,1), angle_90)
155
- rotation2 = Quat.from_axis(Vector3.new(0,0,1), angle_45)
156
- # rotation3 = Quat.from_axis(Vector3.new(1,1,1).normalize, angle_90)
157
- rotated1 = @box_default.rotate(rotation1)
158
- rotated2 = @box_default.rotate(rotation2)
159
- assert_equal(Box.new(Vector3.new(0,-1,0), Vector3.new(1,0,1)), rotated1)
160
- assert_equal(Box.new(
161
- Vector3.new(0, -(Math.sqrt(2.0)/2) ,0),
162
- Vector3.new(Math.sqrt(2.0), (Math.sqrt(2.0)/2) ,1)), rotated2)
163
-
164
- # this procedure is not destructive
165
- assert_equal(Box.new(Vector3.new(0,0,0), Vector3.new(1,1,1)), @box_default)
166
- end
167
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class BoxTestCase < MiniTest::Unit::TestCase
9
+ def setup
10
+ @box_default = Box.new()
11
+ @box = Box.new(Vector3.new(-3,2,5), Vector3.new(2,-2.5, 0))
12
+ end
13
+
14
+ def test_to_s
15
+ assert_equal( "Box[min[-3, -2.5, 0], max[2, 2, 5]]", @box.to_s)
16
+ end
17
+
18
+ def test_initalize
19
+ assert_equal(0, @box_default.min_point.x)
20
+ assert_equal(0, @box_default.min_point.y)
21
+ assert_equal(0, @box_default.min_point.z)
22
+ assert_equal(1, @box_default.max_point.x)
23
+ assert_equal(1, @box_default.max_point.y)
24
+ assert_equal(1, @box_default.max_point.z)
25
+
26
+ assert_equal(-3.0, @box.min_point.x)
27
+ assert_equal(-2.5, @box.min_point.y)
28
+ assert_equal(0.0 , @box.min_point.z)
29
+ assert_equal(2.0 , @box.max_point.x)
30
+ assert_equal(2.0 , @box.max_point.y)
31
+ assert_equal(5.0 , @box.max_point.z)
32
+
33
+ assert_equal(Geom.default_tolerance, @box_default.tolerance)
34
+
35
+ assert_raises ArgumentError do
36
+ invalidResult = Box.new(nil)
37
+ end
38
+ assert_raises ArgumentError do
39
+ invalidResult = Box.new(Vector3.new(), 4.0)
40
+ end
41
+ end
42
+
43
+ def test_from_points
44
+ points = Array.new(6)
45
+ points[0] = Vector3.new( 3, 0, 1)
46
+ points[1] = Vector3.new( 2,-2, 10)
47
+ points[2] = Vector3.new(-6, 2, -4)
48
+ points[3] = Vector3.new( 3, 5, -1)
49
+ points[4] = Vector3.new(-2, 2, 2)
50
+ points[5] = Vector3.new(11, 1, 0)
51
+ box = Box.from_points(points)
52
+ assert_equal(Vector3.new(-6, -2, -4), box.min_point)
53
+ assert_equal(Vector3.new(11, 5, 10), box.max_point)
54
+
55
+ points = Array.new(2)
56
+ points[0] = Vector3.new( -3, -2, -1)
57
+ points[1] = Vector3.new( -4, -8, -10)
58
+ box = Box.from_points(points)
59
+ assert_equal(Vector3.new(-4, -8, -10), box.min_point)
60
+ assert_equal(Vector3.new(-3, -2, -1), box.max_point)
61
+
62
+ points = Array.new(0)
63
+ box = Box.from_points(points)
64
+ assert_equal(nil, box)
65
+ end
66
+
67
+ def test_equal
68
+ shallow_copied = @box
69
+ assert( shallow_copied == @box )
70
+ assert( shallow_copied.equal?( @box ) )
71
+
72
+ deep_copied = Box.new(Vector3.new(-3,2,5), Vector3.new(2,-2.5, 0))
73
+ assert( deep_copied == @box )
74
+ assert( !deep_copied.equal?( @box ) )
75
+
76
+ assert( @box != 5 )
77
+ end
78
+
79
+ def test_add
80
+ added_box = @box_default + Vector3.new(-2, 0.5, 3)
81
+ assert_equal(Vector3.new(-2,0,0), added_box.min_point)
82
+ assert_equal(Vector3.new(1,1,3) , added_box.max_point)
83
+
84
+ added_box = @box_default + Box.new( Vector3.new(-2,0.5, 3), Vector3.new(4, 0, 2.0))
85
+ assert_equal(Vector3.new(-2,0,0), added_box.min_point)
86
+ assert_equal(Vector3.new(4,1,3) , added_box.max_point)
87
+
88
+ point_ary = [Vector3.new(1,4,9), Vector3.new(4,-2,4), Vector3.new(2,-5,0)]
89
+ added_box = @box + point_ary
90
+ assert_equal(Vector3.new(-3,-5, 0), added_box.min_point)
91
+ assert_equal(Vector3.new( 4, 4, 9), added_box.max_point)
92
+
93
+ assert_raises ArgumentError do
94
+ invalidResult = @box + 4
95
+ end
96
+ end
97
+
98
+ def test_center
99
+ assert_equal( Vector3.new(0.5, 0.5, 0.5), @box_default.center)
100
+ assert_equal( Vector3.new(-0.5,-0.25,2.5), @box.center)
101
+ end
102
+
103
+ def test_length
104
+ width, height, depth = @box_default.length
105
+ assert_in_delta( 1, width , @box_default.tolerance)
106
+ assert_in_delta( 1, height, @box_default.tolerance)
107
+ assert_in_delta( 1, depth , @box_default.tolerance)
108
+
109
+ width, height, depth = @box.length
110
+ assert_in_delta( 5.0, width , @box.tolerance)
111
+ assert_in_delta( 4.5, height, @box.tolerance)
112
+ assert_in_delta( 5.0, depth , @box.tolerance)
113
+ end
114
+
115
+ def test_volume
116
+ assert_in_delta( 1.0, @box_default.volume, @box_default.tolerance )
117
+ assert_in_delta( 112.5, @box.volume, @box.tolerance )
118
+ end
119
+
120
+ def test_vertices
121
+ verts = @box_default.vertices
122
+ assert(verts.include?(Vector3.new(0,0,0)))
123
+ assert(verts.include?(Vector3.new(1,0,0)))
124
+ assert(verts.include?(Vector3.new(1,1,0)))
125
+ assert(verts.include?(Vector3.new(0,1,0)))
126
+ assert(verts.include?(Vector3.new(0,0,1)))
127
+ assert(verts.include?(Vector3.new(1,0,1)))
128
+ assert(verts.include?(Vector3.new(1,1,1)))
129
+ assert(verts.include?(Vector3.new(0,1,1)))
130
+
131
+ verts = @box.vertices #.new(-3,2,5), Vector3.new(2,-2.5, 0))
132
+ assert(verts.include?(Vector3.new(-3, -2.5, 0)))
133
+ assert(verts.include?(Vector3.new( 2, -2.5, 0)))
134
+ assert(verts.include?(Vector3.new( 2, 2.0, 0)))
135
+ assert(verts.include?(Vector3.new(-3, 2.0, 0)))
136
+ assert(verts.include?(Vector3.new(-3, -2.5, 5)))
137
+ assert(verts.include?(Vector3.new( 2, -2.5, 5)))
138
+ assert(verts.include?(Vector3.new( 2, 2.0, 5)))
139
+ assert(verts.include?(Vector3.new(-3, 2.0, 5)))
140
+ end
141
+
142
+ def test_translate
143
+ trans = Vector3.new(1,2.5,-0.5)
144
+ translated = @box_default.translate(trans)
145
+ assert_equal(Box.new(Vector3.new(1,2.5,-0.5), Vector3.new(2,3.5,0.5)), translated)
146
+
147
+ # this procedure is not destructive
148
+ assert_equal(Box.new(Vector3.new(0,0,0), Vector3.new(1,1,1)), @box_default)
149
+ end
150
+
151
+ def test_rotate
152
+ angle_90 = 90.0*Math::PI/180.0
153
+ angle_45 = 45.0*Math::PI/180.0
154
+ rotation1 = Quat.from_axis(Vector3.new(0,0,1), angle_90)
155
+ rotation2 = Quat.from_axis(Vector3.new(0,0,1), angle_45)
156
+ rotated1 = @box_default.rotate(rotation1)
157
+ rotated2 = @box_default.rotate(rotation2)
158
+
159
+ assert_equal(Box.new(Vector3.new(-1,0,0), Vector3.new(0,1,1)), rotated1)
160
+ assert_equal(Box.new(
161
+ Vector3.new(-(Math.sqrt(2.0)/2) ,0, 0),
162
+ Vector3.new((Math.sqrt(2.0)/2) ,Math.sqrt(2.0),1)) , rotated2)
163
+
164
+ box2 = Box.new(Vector3.new(-1,-1,0),Vector3.new(1,1,3))
165
+ rotation1 = Quat.from_axis(Vector3.new(1,0,0), angle_90)
166
+ box2_rotated = box2.rotate(rotation1)
167
+ assert_equal(Box.new(Vector3.new(-1,-3,-1), Vector3.new(1,0,1)), box2_rotated)
168
+
169
+ # this procedure is not destructive
170
+ assert_equal(Box.new(Vector3.new(0,0,0), Vector3.new(1,1,1)), @box_default)
171
+ end
172
+ end
data/test/test_ellipse.rb CHANGED
@@ -1,55 +1,55 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- require 'helper'
3
-
4
- include GMath3D
5
-
6
- MiniTest::Unit.autorun
7
-
8
- class EllipseTestCase < MiniTest::Unit::TestCase
9
- def test_initialize
10
- end
11
-
12
- def test_to_s
13
- end
14
-
15
- def test_equals
16
- =begin
17
- line = FiniteLine.new()
18
- shallow_copied = line
19
- assert(line == shallow_copied)
20
- assert(line.equal?(shallow_copied))
21
- assert(line != nil)
22
- assert(line != "string")
23
-
24
- assert_equal(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)),
25
- FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
26
-
27
- assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
28
- assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,3)) != FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
29
- assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) != FiniteLine.new(Vector3.new(2,3,4), Vector3.new(1,2,3)))
30
- line = FiniteLine.new(Vector3.new(1,0,2), Vector3.new(1,-3.5,2))
31
- assert_equal("FiniteLine[from[1, 0, 2], to[1, -3.5, 2]]", line.to_s)
32
- =end
33
- end
34
-
35
- def test_clone
36
- =begin
37
- line = FiniteLine.new()
38
- shallow_copied = line
39
- shallow_copied.start_point.x = -1
40
- assert(line == shallow_copied)
41
- assert(line.equal?(shallow_copied))
42
- assert_equal(-1, shallow_copied.start_point.x)
43
-
44
- cloned = line.clone
45
- assert(line == cloned)
46
- assert(!line.equal?(cloned))
47
- cloned.start_point.x = -2
48
- assert_equal(-2, cloned.start_point.x)
49
-
50
- assert_equal(-1, line.start_point.x) # original never changed in editing cloned one.
51
- =end
52
- end
53
-
54
-
55
- end
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'helper'
3
+
4
+ include GMath3D
5
+
6
+ MiniTest::Unit.autorun
7
+
8
+ class EllipseTestCase < MiniTest::Unit::TestCase
9
+ def test_initialize
10
+ end
11
+
12
+ def test_to_s
13
+ end
14
+
15
+ def test_equals
16
+ =begin
17
+ line = FiniteLine.new()
18
+ shallow_copied = line
19
+ assert(line == shallow_copied)
20
+ assert(line.equal?(shallow_copied))
21
+ assert(line != nil)
22
+ assert(line != "string")
23
+
24
+ assert_equal(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)),
25
+ FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
26
+
27
+ assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) == FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
28
+ assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,3)) != FiniteLine.new(Vector3.new(1.0,2.0,3.0), Vector3.new(2.0,3.0,4.0)))
29
+ assert(FiniteLine.new(Vector3.new(1,2,3), Vector3.new(2,3,4)) != FiniteLine.new(Vector3.new(2,3,4), Vector3.new(1,2,3)))
30
+ line = FiniteLine.new(Vector3.new(1,0,2), Vector3.new(1,-3.5,2))
31
+ assert_equal("FiniteLine[from[1, 0, 2], to[1, -3.5, 2]]", line.to_s)
32
+ =end
33
+ end
34
+
35
+ def test_clone
36
+ =begin
37
+ line = FiniteLine.new()
38
+ shallow_copied = line
39
+ shallow_copied.start_point.x = -1
40
+ assert(line == shallow_copied)
41
+ assert(line.equal?(shallow_copied))
42
+ assert_equal(-1, shallow_copied.start_point.x)
43
+
44
+ cloned = line.clone
45
+ assert(line == cloned)
46
+ assert(!line.equal?(cloned))
47
+ cloned.start_point.x = -2
48
+ assert_equal(-2, cloned.start_point.x)
49
+
50
+ assert_equal(-1, line.start_point.x) # original never changed in editing cloned one.
51
+ =end
52
+ end
53
+
54
+
55
+ end