eymiha_math3 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ require 'test/unit'
2
+
3
+ require 'point3c'
4
+
5
+ class TC_Point3c < Test::Unit::TestCase
6
+
7
+ understands ThreeDimensions
8
+
9
+ def test_initialize_and_equality
10
+ p3c = Point3c.new
11
+ assert((p3c.c_radius == 0)&&(p3c.theta == 0)&&(p3c.z == 0))
12
+ p3c = Point3c.new 1,2,3
13
+ assert((p3c.c_radius == 1)&&(p3c.theta == 2)&&(p3c.z == 3))
14
+ p3a = Point3c.new 1,2,3
15
+ assert(p3c == p3a)
16
+ assert(p3c =~ p3a)
17
+ assert(p3c.approximately_equals?((point3c 1.005, 1.991, 3),0.01))
18
+ p3a = Point3c.new 3,2,1
19
+ assert(p3c != p3a)
20
+ end
21
+
22
+ def test_Object_point3c
23
+ p3c = point3c
24
+ assert(p3c == origin)
25
+ p3c = point3c 1,2,3
26
+ assert((p3c.c_radius == 1)&&(p3c.theta == 2)&&(p3c.z == 3))
27
+ p3a = Point3c.new 1,2,3
28
+ assert((p3a.c_radius == 1)&&(p3a.theta == 2)&&(p3a.z == 3))
29
+ assert(p3c == p3a)
30
+ end
31
+
32
+ def test_accessors
33
+ p3c = point3c
34
+ assert(p3c.point3c_like?)
35
+ assert((p3c.c_radius == 0)&&(p3c.theta == 0)&&(p3c.z == 0))
36
+ p3c.c_radius = 1
37
+ p3c.theta = 2
38
+ p3c.z = 3
39
+ assert((p3c.c_radius == 1)&&(p3c.theta == 2)&&(p3c.z == 3))
40
+ p3c.c_radius, p3c.theta, p3c.z = 2, 4, 6
41
+ assert((p3c.c_radius == 2)&&(p3c.theta == 4)&&(p3c.z == 6))
42
+ end
43
+
44
+ def test_origin
45
+ p3c = point3c 0, 0, 0
46
+ assert(p3c == origin)
47
+ assert(origin == p3c)
48
+ p3c = point3c 0, 1, 0
49
+ assert(p3c == origin)
50
+ assert(origin == p3c)
51
+ end
52
+
53
+ def test_set
54
+ p3c = point3c
55
+ p3c.set 1, 2, 3
56
+ assert((p3c.c_radius == 1)&&(p3c.theta == 2)&&(p3c.z == 3))
57
+ p3a = point3c p3c
58
+ assert((p3a.c_radius == 1)&&(p3a.theta == 2)&&(p3a.z == 3))
59
+ p3b = point3c
60
+ assert_raise(TypeError) { p3b.set "bad" }
61
+ assert_raise(TypeError) { point3c "bad" }
62
+ end
63
+
64
+ def test_copy
65
+ p3c = point3c 1, 2, 3
66
+ p3a = p3c.point3c
67
+ assert(p3c == p3a)
68
+ end
69
+
70
+ def test_cartesian_and_spherical
71
+ p3c = point3c 1, 2, 3
72
+ assert(p3c.x =~ -0.416146836547142)
73
+ assert(p3c.y =~ 0.909297426825682)
74
+ assert(p3c.s_radius =~ 3.16227766016838)
75
+ assert(p3c.phi =~ 0.321750554396642)
76
+ end
77
+
78
+ def test_point3
79
+ p3c = point3c 1, 2, 3
80
+ p3 = p3c.point3
81
+ assert(p3.x =~ -0.416146836547142)
82
+ assert(p3.y =~ 0.909297426825682)
83
+ assert(p3.z =~ 3)
84
+ p3a = p3.point3c
85
+ assert(p3c =~ p3a)
86
+ end
87
+
88
+ def test_point3s
89
+ p3c = point3c 1, 2, 3
90
+ p3s = p3c.point3s
91
+ assert(p3s.s_radius =~ 3.16227766016838)
92
+ assert(p3s.theta =~ p3c.theta)
93
+ assert(p3s.phi =~ 0.321750554396642)
94
+ p3a = p3s.point3c
95
+ assert(p3c =~ p3a)
96
+ end
97
+
98
+ end
@@ -0,0 +1,101 @@
1
+ require 'test/unit'
2
+
3
+ require 'point3s'
4
+
5
+ class TC_Point3s < Test::Unit::TestCase
6
+
7
+ understands ThreeDimensions
8
+
9
+ def test_initialize_and_equality
10
+ p3s = Point3s.new
11
+ assert((p3s.s_radius == 0)&&(p3s.theta == 0)&&(p3s.phi == 0))
12
+ p3s = Point3s.new 1,2,3
13
+ assert((p3s.s_radius == 1)&&(p3s.theta == 2)&&(p3s.phi == 3))
14
+ p3a = Point3s.new 1,2,3
15
+ assert(p3s == p3a)
16
+ assert(p3s =~ p3a)
17
+ assert(p3s.approximately_equals?((point3s 1.005, 1.991, 3),0.01))
18
+ p3a = Point3s.new 3,2,1
19
+ assert(p3s != p3a)
20
+ end
21
+
22
+ def test_Object_point3s
23
+ p3s = point3s
24
+ assert(p3s == origin)
25
+ p3s = point3s 1,2,3
26
+ assert((p3s.s_radius == 1)&&(p3s.theta == 2)&&(p3s.phi == 3))
27
+ p3a = Point3s.new 1,2,3
28
+ assert((p3a.s_radius == 1)&&(p3a.theta == 2)&&(p3a.phi == 3))
29
+ assert(p3s == p3a)
30
+ end
31
+
32
+ def test_accessors
33
+ p3s = point3s
34
+ assert(p3s.point3s_like?)
35
+ assert((p3s.s_radius == 0)&&(p3s.theta == 0)&&(p3s.phi == 0))
36
+ p3s.s_radius = 1
37
+ p3s.theta = 2
38
+ p3s.phi = 3
39
+ assert((p3s.s_radius == 1)&&(p3s.theta == 2)&&(p3s.phi == 3))
40
+ p3s.s_radius, p3s.theta, p3s.phi = 2, 4, 6
41
+ assert((p3s.s_radius == 2)&&(p3s.theta == 4)&&(p3s.phi == pi))
42
+ p3s.s_radius, p3s.theta, p3s.phi = -2, -4, -6
43
+ assert((p3s.s_radius == -2)&&(p3s.theta =~ 2.28318530717959)&&
44
+ (p3s.phi == 0))
45
+ end
46
+
47
+ def test_origin
48
+ p3s = point3s 0, 0, 0
49
+ assert(p3s == origin)
50
+ assert(origin == p3s)
51
+ p3s = point3s 0, 1, 2
52
+ assert(p3s == origin)
53
+ assert(origin == p3s)
54
+ end
55
+
56
+ def test_set
57
+ p3s = point3s
58
+ p3s.set 1, 2, 3
59
+ assert((p3s.s_radius == 1)&&(p3s.theta == 2)&&(p3s.phi == 3))
60
+ p3a = point3s p3s
61
+ assert((p3a.s_radius == 1)&&(p3a.theta == 2)&&(p3a.phi == 3))
62
+ p3b = point3s
63
+ assert_raise(TypeError) { p3b.set "bad" }
64
+ assert_raise(TypeError) { point3s "bad" }
65
+ end
66
+
67
+ def test_copy
68
+ p3s = point3s 1, 2, 3
69
+ p3a = p3s.point3s
70
+ assert(p3s == p3a)
71
+ end
72
+
73
+ def test_cartesian_and_cylindrical
74
+ p3s = point3s 1, 2, 3
75
+ assert(p3s.x =~ -0.058726644927621)
76
+ assert(p3s.y =~ 0.128320060202457)
77
+ assert(p3s.z =~ -0.989992496600445)
78
+ assert(p3s.c_radius =~ 0.141120008059867)
79
+ end
80
+
81
+ def test_point3
82
+ p3s = point3s 1, 2, 3
83
+ p3 = p3s.point3
84
+ assert(p3.x =~ -0.058726644927621)
85
+ assert(p3.y =~ 0.128320060202457)
86
+ assert(p3.z =~ -0.989992496600445)
87
+ p3a = p3.point3s
88
+ assert(p3s =~ p3a)
89
+ end
90
+
91
+ def test_point3c
92
+ p3s = point3s 1, 2, 3
93
+ p3c = p3s.point3c
94
+ assert(p3c.c_radius =~ 0.141120008059867)
95
+ assert(p3c.theta =~ p3s.theta)
96
+ assert(p3c.z =~ -0.989992496600445)
97
+ p3a = p3c.point3s
98
+ assert(p3s =~ p3a)
99
+ end
100
+
101
+ end
@@ -0,0 +1,148 @@
1
+ require 'test/unit'
2
+
3
+ require 'quaternion'
4
+
5
+ class TC_Quaternion < Test::Unit::TestCase
6
+
7
+ understands ThreeDimensions
8
+
9
+ def test_initialize_and_equality
10
+ q = Quaternion.new
11
+ assert((q.axis == origin)&&(q.real == 0))
12
+ qa = Quaternion.new(origin,0)
13
+ assert(q == qa)
14
+ p3 = point3 1,2,3
15
+ qb = Quaternion.new p3,4
16
+ assert(qb.axis == p3)
17
+ assert(qb.real == 4)
18
+ assert(q != qb)
19
+ qc = quaternion p3,4
20
+ assert(qc.axis == p3)
21
+ assert(qc.real == 4)
22
+ assert(q != qb)
23
+ assert(qb == qc)
24
+ end
25
+
26
+ def test_accessors
27
+ p3 = point3 1,2,3
28
+ q = quaternion p3,4
29
+ q.axis.scale! 2
30
+ q.real -= 3
31
+ assert(q.axis == point3(2,4,6))
32
+ assert(q.real == 1)
33
+ qb = quaternion q
34
+ assert(q == qb)
35
+ end
36
+
37
+ def test_axis_angle
38
+ p3 = point3 1,2,3
39
+ q = Quaternion.from_axis_angle(p3,pi/8)
40
+ assert(q.axis.x =~ 0.195090322016128)
41
+ assert(q.axis.y =~ 0.390180644032256)
42
+ assert(q.axis.z =~ 0.585270966048385)
43
+ assert(q.real =~ 0.98078528040323)
44
+ qb = q.to_axis_angle
45
+ assert(qb.axis =~ p3)
46
+ assert(qb.real =~ pi/8)
47
+ end
48
+
49
+ def test_add
50
+ p3a,ra = point3(1,2,3),4
51
+ p3b,rb = point3(4,-6,0),-3
52
+ qa = quaternion p3a,ra
53
+ qb = quaternion p3b,rb
54
+ p3c,rc = p3a+p3b,ra+rb
55
+ qc = qa+qb
56
+ assert(qc.axis =~ p3c)
57
+ assert(qc.real =~ rc)
58
+ qa.add! qb
59
+ assert(qa =~ qc)
60
+ end
61
+
62
+ def test_subtract
63
+ p3a,ra = point3(1,2,3),4
64
+ p3b,rb = point3(4,-6,0),-3
65
+ qa = quaternion p3a,ra
66
+ qb = quaternion p3b,rb
67
+ p3c,rc = p3a-p3b,ra-rb
68
+ qc = qa-qb
69
+ assert(qc.axis =~ p3c)
70
+ assert(qc.real =~ rc)
71
+ qa.subtract! qb
72
+ assert(qa =~ qc)
73
+ end
74
+
75
+ def test_multiply
76
+ p3a,ra = point3(1,2,3),4
77
+ p3b,rb = point3(4,-6,0),-3
78
+ qa = quaternion p3a,ra
79
+ qb = quaternion p3b,rb
80
+ p3c,rc = point3(-1,30,-23),-4
81
+ qc = qa*qb
82
+ assert(qc.axis =~ p3c)
83
+ assert(qc.real =~ rc)
84
+ qa.multiply! qb
85
+ assert(qa =~ qc)
86
+ end
87
+
88
+ def test_scale
89
+ p3a,ra = point3(1,2,3),4
90
+ qa = quaternion p3a,ra
91
+ p3c,rc = p3a.scale(5.5),ra*5.5
92
+ qc = qa.scale(5.5)
93
+ assert(qc.axis =~ p3c)
94
+ assert(qc.real =~ rc)
95
+ qa.scale! 5.5
96
+ assert(qa =~ qc)
97
+ end
98
+
99
+ def test_conjugate
100
+ p3a,ra = point3(1,2,3),4
101
+ qa = quaternion p3a,ra
102
+ p3c,rc = point3(-1,-2,-3),ra
103
+ qc = qa.conjugate
104
+ assert(qc.axis =~ p3c)
105
+ assert(qc.real =~ rc)
106
+ qa.conjugate!
107
+ assert(qa =~ qc)
108
+ end
109
+
110
+ def test_norm
111
+ p3a,ra = point3(1,2,3),4
112
+ qa = quaternion p3a,ra
113
+ assert(qa.norm =~ 19.7416573867739)
114
+ end
115
+
116
+ def test_abs
117
+ p3a,ra = point3(1,2,3),4
118
+ qa = quaternion p3a,ra
119
+ assert(qa.abs =~ 4.44315849219606)
120
+ end
121
+
122
+ def test_inverse
123
+ p3a,ra = point3(1,2,3),4
124
+ qa = quaternion p3a,ra
125
+ q = qa.inverse
126
+ assert(q.axis.x =~ (-0.0506543083191159))
127
+ assert(q.axis.y =~ (-0.101308616638232))
128
+ assert(q.axis.z =~ (-0.151962924957348))
129
+ assert(q.real =~ 0.202617233276464)
130
+ qa.inverse!
131
+ assert(q =~ qa)
132
+ end
133
+
134
+ def test_divide
135
+ p3a,ra = point3(1,2,3),4
136
+ qa = quaternion p3a,ra
137
+ p3b,rb = point3(10,0,-10),0
138
+ qb = quaternion p3b,rb
139
+ qc = qa.divide qb
140
+ assert(qc.axis.x =~ 2.41421356237309)
141
+ assert(qc.axis.y =~ (-2.82842712474619))
142
+ assert(qc.axis.z =~ 0.414213562373095)
143
+ assert(qc.real =~ -1.41421356237309)
144
+ qa.divide! qb
145
+ assert(qa =~ qc)
146
+ end
147
+
148
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: eymiha_math3
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-05-22 00:00:00 -04:00
8
+ summary: Emiyha - basic 3D math extensions
9
+ require_paths:
10
+ - lib
11
+ email: dave@eymiha.com
12
+ homepage: http://www.eymiha.com
13
+ rubyforge_project: cori
14
+ description:
15
+ autorequire: eymiha_math3
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Dave Anderson
31
+ files:
32
+ - gem_package.rb
33
+ - rakefile.rb
34
+ - lib/envelope3.rb
35
+ - lib/eymiha_math3.rb
36
+ - lib/point3.rb
37
+ - lib/point3c.rb
38
+ - lib/point3s.rb
39
+ - lib/quaternion.rb
40
+ - test/tc_envelope3.rb
41
+ - test/tc_point3.rb
42
+ - test/tc_point3c.rb
43
+ - test/tc_point3s.rb
44
+ - test/tc_quaternion.rb
45
+ test_files: []
46
+
47
+ rdoc_options:
48
+ - --all
49
+ extra_rdoc_files: []
50
+
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ requirements: []
56
+
57
+ dependencies:
58
+ - !ruby/object:Gem::Dependency
59
+ name: eymiha
60
+ version_requirement:
61
+ version_requirements: !ruby/object:Gem::Version::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.1.0
66
+ version:
67
+ - !ruby/object:Gem::Dependency
68
+ name: eymiha_math
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Version::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 0.1.0
75
+ version: