rmath3d 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,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmath3d
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
13
  description: |
14
- Provides vector3/4, matrix3x3/4x4 and quaternion in C extension library form (and plain Ruby form with the same interface for debugging use).
14
+ Provides vector2/3/4, matrix2x2/3x3/4x4 and quaternion in C extension library form (and plain Ruby form with the same interface for debugging use).
15
15
  Notice: This library provides native extension. You must setup development environment (or DevKit) before installation.
16
16
  email:
17
17
  - vaiorabbit@gmail.com
@@ -25,6 +25,8 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - ext/rmath3d/RMath3D.h
28
+ - ext/rmath3d/RMtx2.c
29
+ - ext/rmath3d/RMtx2.h
28
30
  - ext/rmath3d/RMtx3.c
29
31
  - ext/rmath3d/RMtx3.h
30
32
  - ext/rmath3d/RMtx4.c
@@ -32,6 +34,8 @@ files:
32
34
  - ext/rmath3d/RQuat.c
33
35
  - ext/rmath3d/RQuat.h
34
36
  - ext/rmath3d/RType.h
37
+ - ext/rmath3d/RVec2.c
38
+ - ext/rmath3d/RVec2.h
35
39
  - ext/rmath3d/RVec3.c
36
40
  - ext/rmath3d/RVec3.h
37
41
  - ext/rmath3d/RVec4.c
@@ -43,16 +47,18 @@ files:
43
47
  - sample/opengl2/load_matrix.rb
44
48
  - sample/simple/transform.rb
45
49
  - test/test.rb
50
+ - test/test_RMtx2.rb
46
51
  - test/test_RMtx3.rb
47
52
  - test/test_RMtx4.rb
48
53
  - test/test_RQuat.rb
54
+ - test/test_RVec2.rb
49
55
  - test/test_RVec3.rb
50
56
  - test/test_RVec4.rb
51
57
  homepage: https://github.com/vaiorabbit/rmath3d
52
58
  licenses:
53
- - zlib/libpng
59
+ - Zlib
54
60
  metadata: {}
55
- post_install_message:
61
+ post_install_message:
56
62
  rdoc_options: []
57
63
  require_paths:
58
64
  - lib
@@ -60,16 +66,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
66
  requirements:
61
67
  - - ">="
62
68
  - !ruby/object:Gem::Version
63
- version: '0'
69
+ version: 2.4.0
64
70
  required_rubygems_version: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - ">="
67
73
  - !ruby/object:Gem::Version
68
74
  version: '0'
69
75
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.2.2
72
- signing_key:
76
+ rubygems_version: 3.1.2
77
+ signing_key:
73
78
  specification_version: 4
74
79
  summary: Ruby Math Module for 3D Applications
75
80
  test_files: []