rmath3d_plain 1.0.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,187 @@
1
+ require 'minitest/autorun'
2
+ class TC_RVec2 < Minitest::Test
3
+ def setup
4
+ @tolerance = RMath3D::TOLERANCE
5
+ @zero = RVec2.new( 0, 0 )
6
+ @ax = RVec2.new( 1, 0 )
7
+ @ay = RVec2.new( 0, 1 )
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ def test_initialize
14
+ v0 = RVec2.new
15
+ assert_in_delta( 0, v0.x, @tolerance )
16
+ assert_in_delta( 0, v0.y, @tolerance )
17
+
18
+ v1 = RVec2.new( 1, 2 )
19
+ assert_in_delta( 1, v1.x, @tolerance )
20
+ assert_in_delta( 2, v1.y, @tolerance )
21
+
22
+ v2 = RVec2.new( v1 )
23
+ assert_in_delta( 1, v2.x, @tolerance )
24
+ assert_in_delta( 2, v2.y, @tolerance )
25
+ end
26
+
27
+ def test_to_s
28
+ assert_respond_to( @zero, :to_s )
29
+ end
30
+
31
+ def test_coerce
32
+ assert_respond_to( @zero, :coerce )
33
+ end
34
+
35
+ def test_setElements
36
+ v = RVec2.new
37
+ v.setElements( 1, 2 )
38
+ assert_in_delta( 1, v.x, @tolerance )
39
+ assert_in_delta( 2, v.y, @tolerance )
40
+ end
41
+
42
+ def test_setElement
43
+ v = RVec2.new
44
+
45
+ # x=
46
+ v.x = 1
47
+ assert_in_delta( 1, v.x, @tolerance )
48
+ v[0] = 2
49
+ assert_in_delta( 2, v.x, @tolerance )
50
+
51
+ # y=
52
+ v.y = 1
53
+ assert_in_delta( 1, v.y, @tolerance )
54
+ v[1] = 2
55
+ assert_in_delta( 2, v.y, @tolerance )
56
+ end
57
+
58
+ def test_getElement
59
+ assert_in_delta( 1, @ax[0], @tolerance )
60
+ assert_in_delta( 1, @ay[1], @tolerance )
61
+
62
+ assert_in_delta( 1, @ax.x, @tolerance )
63
+ assert_in_delta( 1, @ay.y, @tolerance )
64
+ end
65
+
66
+ def test_getLength
67
+ len_sq = 1.0*1.0 + 2.0*2.0 # == 5.0
68
+ len = Math.sqrt( len_sq ) # == 2.23606797749979
69
+
70
+ v = RVec2.new( 1, 2 )
71
+ assert_in_delta( len_sq, v.getLengthSq, @tolerance )
72
+ assert_in_delta( len , v.getLength , @tolerance )
73
+ end
74
+
75
+ def test_normalize
76
+ len_sq = 1.0*1.0 + 2.0*2.0 # == 5.0
77
+ len = Math.sqrt( len_sq ) # == 2.23606797749979
78
+ x = 1.0 / len
79
+ y = 2.0 / len
80
+ v = RVec2.new( 1, 2 )
81
+ # getNormalized
82
+ v0 = v.getNormalized
83
+ assert_in_delta( x, v0.x, @tolerance )
84
+ assert_in_delta( y, v0.y, @tolerance )
85
+
86
+ # normalize!
87
+ v.normalize!
88
+ assert_in_delta( x, v.x, @tolerance )
89
+ assert_in_delta( y, v.y, @tolerance )
90
+ end
91
+
92
+ def test_unary_operators
93
+ v = RVec2.new( 1, 2 )
94
+
95
+ # RVec2#+@
96
+ vp = +v
97
+ assert_in_delta( 1, vp.x, @tolerance )
98
+ assert_in_delta( 2, vp.y, @tolerance )
99
+
100
+ # RVec2#-@
101
+ vm = -v
102
+ assert_in_delta( -1, vm.x, @tolerance )
103
+ assert_in_delta( -2, vm.y, @tolerance )
104
+ end
105
+
106
+ def test_plus_operations
107
+ v0 = RVec2.new( 1, 1 )
108
+ v1 = RVec2.new( 2, 2 )
109
+
110
+ # RVec2#+
111
+ vr = v0 + v1
112
+ assert_in_delta( 3, vr.x, @tolerance )
113
+ assert_in_delta( 3, vr.y, @tolerance )
114
+
115
+ # RVec2#add!
116
+ v0.add!( v1 )
117
+ assert_in_delta( 3, v0.x, @tolerance )
118
+ assert_in_delta( 3, v0.y, @tolerance )
119
+
120
+ assert_raises( TypeError ) { v0 + 1.0 }
121
+ assert_raises( TypeError ) { 1.0 + v0 }
122
+ end
123
+
124
+ def test_minus_operations
125
+ v0 = RVec2.new( 1, 1 )
126
+ v1 = RVec2.new( 2, 2 )
127
+
128
+ # RVec2#-
129
+ vr = v0 - v1
130
+ assert_in_delta( -1, vr.x, @tolerance )
131
+ assert_in_delta( -1, vr.y, @tolerance )
132
+
133
+ # RVec2#sub!
134
+ v0.sub!( v1 )
135
+ assert_in_delta( -1, v0.x, @tolerance )
136
+ assert_in_delta( -1, v0.y, @tolerance )
137
+
138
+ assert_raises( TypeError ) { v0 - 1.0 }
139
+ assert_raises( TypeError ) { 1.0 - v0 }
140
+ end
141
+
142
+ def test_mult_operations
143
+ v0 = RVec2.new( 1, 1 )
144
+
145
+ vr = v0 * 2.0
146
+ assert_in_delta( 2.0, vr.x, @tolerance )
147
+ assert_in_delta( 2.0, vr.y, @tolerance )
148
+
149
+ vr = 2.0 * v0
150
+ assert_in_delta( 2.0, vr.x, @tolerance )
151
+ assert_in_delta( 2.0, vr.y, @tolerance )
152
+
153
+ v0.mul!( 2.0 )
154
+ assert_in_delta( 2.0, v0.x, @tolerance )
155
+ assert_in_delta( 2.0, v0.y, @tolerance )
156
+
157
+ assert_raises( TypeError ) { v0 * @zero }
158
+ end
159
+
160
+ def test_equality_operations
161
+ v = RVec2.new
162
+ assert( v == @zero )
163
+ assert( v != @ax )
164
+ end
165
+
166
+ def test_dot
167
+ v0 = RVec2.new( 1, 1 )
168
+ v1 = RVec2.new( 2, 2 )
169
+ assert_in_delta( 4.0, RVec2.dot(v0, v1), @tolerance )
170
+ assert_in_delta( 0.0, RVec2.dot(@ax, @ay), @tolerance )
171
+ end
172
+
173
+ def test_cross
174
+ c = RVec2.cross( @ax, @ay )
175
+ assert_in_delta( c, 1.0, @tolerance )
176
+ end
177
+
178
+ def test_transform
179
+ m = RMtx2.new.rotation( Math::PI/4.0 )
180
+ va = RVec2.new( Math.sqrt(2)/2, Math.sqrt(2)/2 )
181
+
182
+ vr = @ax.transform( m )
183
+ assert_kind_of( RVec2, vr )
184
+ assert_in_delta( va.x, vr.x, @tolerance )
185
+ assert_in_delta( va.y, vr.y, @tolerance )
186
+ end
187
+ end
metadata CHANGED
@@ -1,17 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmath3d_plain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - vaiorabbit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-18 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: |
14
- Provides vector3/4, matrix3x3/4x4 and quaternion in plain Ruby form.
13
+ description: 'Provides vector2/3/4, matrix2x2/3x3/4x4 and quaternion in plain Ruby
14
+ form.
15
+
16
+ '
15
17
  email:
16
18
  - vaiorabbit@gmail.com
17
19
  executables: []
@@ -26,16 +28,18 @@ files:
26
28
  - sample/opengl2/load_matrix.rb
27
29
  - sample/simple/transform.rb
28
30
  - test/test.rb
31
+ - test/test_RMtx2.rb
29
32
  - test/test_RMtx3.rb
30
33
  - test/test_RMtx4.rb
31
34
  - test/test_RQuat.rb
35
+ - test/test_RVec2.rb
32
36
  - test/test_RVec3.rb
33
37
  - test/test_RVec4.rb
34
38
  homepage: https://github.com/vaiorabbit/rmath3d
35
39
  licenses:
36
- - zlib/libpng
40
+ - Zlib
37
41
  metadata: {}
38
- post_install_message:
42
+ post_install_message:
39
43
  rdoc_options: []
40
44
  require_paths:
41
45
  - lib
@@ -43,16 +47,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
47
  requirements:
44
48
  - - ">="
45
49
  - !ruby/object:Gem::Version
46
- version: '0'
50
+ version: 2.4.0
47
51
  required_rubygems_version: !ruby/object:Gem::Requirement
48
52
  requirements:
49
53
  - - ">="
50
54
  - !ruby/object:Gem::Version
51
55
  version: '0'
52
56
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.2.2
55
- signing_key:
57
+ rubygems_version: 3.1.2
58
+ signing_key:
56
59
  specification_version: 4
57
60
  summary: Ruby Math Module for 3D Applications
58
61
  test_files: []