snow-math 1.2.4 → 1.3.0pre0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,13 @@ require 'snow-math/bindings'
7
7
  module Snow ; end
8
8
 
9
9
  if Snow.const_defined?(:Vec3Array)
10
+ #
11
+ # A contiguous array of Vec3s. Allocated as a single block of memory so that
12
+ # it can easily be passed back to C libraries (like OpenGL) and to aid with
13
+ # cache locality.
14
+ #
15
+ # Useful for storing vertex data such as positions, normals, and so on.
16
+ #
10
17
  class Snow::Vec3Array
11
18
  class << self ; alias_method :[], :new ; end
12
19
 
@@ -15,6 +22,9 @@ if Snow.const_defined?(:Vec3Array)
15
22
  end
16
23
  end
17
24
 
25
+ #
26
+ # A 3-component vector class.
27
+ #
18
28
  class Snow::Vec3
19
29
 
20
30
  # Shortcut through to new
@@ -22,55 +32,92 @@ class Snow::Vec3
22
32
 
23
33
  alias_method :[], :fetch
24
34
  alias_method :[]=, :store
35
+ alias_method :dup, :copy
36
+ alias_method :clone, :copy
25
37
 
38
+
39
+ # Returns the X component of the vector.
40
+ #
41
+ # call-seq: x -> float
26
42
  def x
27
43
  self[0]
28
44
  end
29
45
 
46
+ # Sets the X component of the vector.
47
+ #
48
+ # call-seq: x = value -> value
30
49
  def x=(value)
31
50
  self[0] = value
32
51
  end
33
52
 
53
+ # Returns the Y component of the vector.
54
+ #
55
+ # call-seq: y -> float
34
56
  def y
35
57
  self[1]
36
58
  end
37
59
 
60
+ # Sets the Y component of the vector.
61
+ #
62
+ # call-seq: y = value -> value
38
63
  def y=(value)
39
64
  self[1] = value
40
65
  end
41
66
 
67
+ # Returns the Z component of the vector.
68
+ #
69
+ # call-seq: z -> float
42
70
  def z
43
71
  self[2]
44
72
  end
45
73
 
74
+ # Sets the Z component of the vector.
75
+ #
76
+ # call-seq: z = value -> value
46
77
  def z=(value)
47
78
  self[2] = value
48
79
  end
49
80
 
50
- def dup
51
- self.class.new(self)
52
- end
53
-
81
+ # Calls #normalize(self)
82
+ #
83
+ # call-seq: normalize! -> self
54
84
  def normalize!
55
85
  normalize self
56
86
  end
57
87
 
88
+ # Calls #inverse(self)
89
+ #
90
+ # call-seq: inverse! -> self
58
91
  def inverse!
59
92
  inverse self
60
93
  end
61
94
 
95
+ # Calls #negate(self)
96
+ #
97
+ # call-seq: negate! -> self
62
98
  def negate!
63
99
  negate self
64
100
  end
65
101
 
102
+ # Calls #cross_product(rhs, self)
103
+ #
104
+ # call-seq: cross_product!(rhs) -> self
66
105
  def cross_product!(rhs)
67
106
  cross_product rhs, self
68
107
  end
69
108
 
109
+ # Calls #multiply_vec3(rhs, self)
110
+ #
111
+ # call-seq: multiply_vec3!(rhs) -> self
70
112
  def multiply_vec3!(rhs)
71
113
  multiply_vec3 rhs, self
72
114
  end
73
115
 
116
+ # Calls #multiply_vec3 and #scale, respectively.
117
+ #
118
+ # call-seq:
119
+ # multiply(vec3, output) -> output or new vec3
120
+ # multiply(scalar, output) -> output or new vec3
74
121
  def multiply(rhs, output = nil)
75
122
  case rhs
76
123
  when ::Snow::Vec3 then multiply_vec3(rhs, output)
@@ -79,26 +126,42 @@ class Snow::Vec3
79
126
  end
80
127
  end
81
128
 
129
+ # Calls #multiply(rhs, self)
130
+ #
131
+ # call-seq: multiply!(rhs) -> self
82
132
  def multiply!(rhs)
83
133
  multiply rhs, self
84
134
  end
85
135
 
136
+ # Calls #add(rhs, self)
137
+ #
138
+ # call-seq: add!(rhs) -> self
86
139
  def add!(rhs)
87
140
  add rhs, self
88
141
  end
89
142
 
143
+ # Calls #subtract(rhs, self)
144
+ #
145
+ # call-seq: subtract!(rhs) -> self
90
146
  def subtract!(rhs)
91
147
  subtract rhs, self
92
148
  end
93
149
 
150
+ # Calls #scale(rhs, self)
151
+ #
152
+ # call-seq: scale!(rhs) -> self
94
153
  def scale!(rhs)
95
154
  scale rhs, self
96
155
  end
97
156
 
157
+ # Calls #divide(rhs, self)
158
+ #
159
+ # call-seq: divide!(rhs) -> self
98
160
  def divide!(rhs)
99
161
  divide rhs, self
100
162
  end
101
163
 
164
+
102
165
  alias_method :-, :subtract
103
166
  alias_method :+, :add
104
167
  alias_method :^, :cross_product
@@ -7,6 +7,13 @@ require 'snow-math/bindings'
7
7
  module Snow ; end
8
8
 
9
9
  if Snow.const_defined?(:Vec4Array)
10
+ #
11
+ # A contiguous array of Vec4s. Allocated as a single block of memory so that
12
+ # it can easily be passed back to C libraries (like OpenGL) and to aid with
13
+ # cache locality.
14
+ #
15
+ # Useful also to represent color buffers, vertices, and other miscellanea.
16
+ #
10
17
  class Snow::Vec4Array
11
18
  class << self ; alias_method :[], :new ; end
12
19
 
@@ -15,65 +22,108 @@ if Snow.const_defined?(:Vec4Array)
15
22
  end
16
23
  end
17
24
 
25
+ #
26
+ # A 4-component vector class.
27
+ #
18
28
  class Snow::Vec4
19
29
 
20
30
  class << self ; alias_method :[], :new ; end
21
31
 
22
32
  alias_method :[], :fetch
23
33
  alias_method :[]=, :store
34
+ alias_method :dup, :copy
35
+ alias_method :clone, :copy
24
36
 
37
+
38
+ # Returns the X component of the vector.
39
+ #
40
+ # call-seq: x -> float
25
41
  def x
26
42
  self[0]
27
43
  end
28
44
 
45
+ # Sets the X component of the vector.
46
+ #
47
+ # call-seq: x = value -> value
29
48
  def x=(value)
30
49
  self[0] = value
31
50
  end
32
51
 
52
+ # Returns the Y component of the vector.
53
+ #
54
+ # call-seq: y -> float
33
55
  def y
34
56
  self[1]
35
57
  end
36
58
 
59
+ # Sets the Y component of the vector.
60
+ #
61
+ # call-seq: y = value -> value
37
62
  def y=(value)
38
63
  self[1] = value
39
64
  end
40
65
 
66
+ # Returns the Z component of the vector.
67
+ #
68
+ # call-seq: z -> float
41
69
  def z
42
70
  self[2]
43
71
  end
44
72
 
73
+ # Sets the Z component of the vector.
74
+ #
75
+ # call-seq: z = value -> value
45
76
  def z=(value)
46
77
  self[2] = value
47
78
  end
48
79
 
80
+ # Returns the W component of the vector.
81
+ #
82
+ # call-seq: w -> float
49
83
  def w
50
84
  self[3]
51
85
  end
52
86
 
87
+ # Sets the W component of the vector.
88
+ #
89
+ # call-seq: w = value -> value
53
90
  def w=(value)
54
91
  self[3] = value
55
92
  end
56
93
 
57
- def dup
58
- self.class.new(self)
59
- end
60
-
94
+ # Calls #normalize(self)
95
+ #
96
+ # call-seq: normalize! -> self
61
97
  def normalize!
62
98
  normalize self
63
99
  end
64
100
 
101
+ # Calls #inverse(self)
102
+ #
103
+ # call-seq: inverse! -> self
65
104
  def inverse!
66
105
  inverse self
67
106
  end
68
107
 
108
+ # Calls #negate(self)
109
+ #
110
+ # call-seq: negate! -> self
69
111
  def negate!
70
112
  negate self
71
113
  end
72
114
 
115
+ # Calls #multiply_vec4(rhs, self)
116
+ #
117
+ # call-seq: multiply_vec4!(rhs) -> self
73
118
  def multiply_vec4!(rhs)
74
119
  multiply_vec4 rhs, self
75
120
  end
76
121
 
122
+ # Calls #multiply_vec4 and #scale, respectively.
123
+ #
124
+ # call-seq:
125
+ # multiply(vec4, output = nil) -> output or new vec4
126
+ # multiply(scalar, output = nil) -> output or new vec4
77
127
  def multiply(rhs, output = nil)
78
128
  case rhs
79
129
  when ::Snow::Vec4 then multiply_vec4(rhs, output)
@@ -82,26 +132,42 @@ class Snow::Vec4
82
132
  end
83
133
  end
84
134
 
135
+ # Calls #multiply(rhs, self)
136
+ #
137
+ # call-seq: multiply!(rhs) -> self
85
138
  def multiply!(rhs)
86
139
  multiply rhs, self
87
140
  end
88
141
 
142
+ # Calls #add(rhs, self)
143
+ #
144
+ # call-seq: add!(rhs) -> self
89
145
  def add!(rhs)
90
146
  add rhs, self
91
147
  end
92
148
 
149
+ # Calls #subtract(rhs, self)
150
+ #
151
+ # call-seq: subtract!(rhs) -> self
93
152
  def subtract!(rhs)
94
153
  subtract rhs, self
95
154
  end
96
155
 
156
+ # Calls #scale(rhs, self)
157
+ #
158
+ # call-seq: scale!(rhs) -> self
97
159
  def scale!(rhs)
98
160
  scale rhs, self
99
161
  end
100
162
 
163
+ # Calls #divide(rhs, self)
164
+ #
165
+ # call-seq: divide!(rhs) -> self
101
166
  def divide!(rhs)
102
167
  divide rhs, self
103
168
  end
104
169
 
170
+
105
171
  alias_method :-, :subtract
106
172
  alias_method :+, :add
107
173
  alias_method :*, :multiply
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snow-math
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0pre0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noel Raymond Cower
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-07 00:00:00.000000000 Z
11
+ date: 2013-07-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Math types built on the SnowPalm math code
14
14
  email: ncower@gmail.com
@@ -16,11 +16,12 @@ executables: []
16
16
  extensions:
17
17
  - ext/extconf.rb
18
18
  extra_rdoc_files:
19
+ - ext/snow-math/snow-math.c
19
20
  - README.md
20
21
  - COPYING
21
22
  files:
22
- - lib/snow-math/array_cache.rb
23
23
  - lib/snow-math/inspect.rb
24
+ - lib/snow-math/marshal.rb
24
25
  - lib/snow-math/mat3.rb
25
26
  - lib/snow-math/mat4.rb
26
27
  - lib/snow-math/ptr.rb
@@ -51,6 +52,7 @@ rdoc_options:
51
52
  - snowmath -- 3D Math Types
52
53
  - --main
53
54
  - README.md
55
+ - --markup=markdown
54
56
  - --line-numbers
55
57
  require_paths:
56
58
  - lib
@@ -61,9 +63,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
63
  version: 2.0.0
62
64
  required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  requirements:
64
- - - '>='
66
+ - - '>'
65
67
  - !ruby/object:Gem::Version
66
- version: '0'
68
+ version: 1.3.1
67
69
  requirements: []
68
70
  rubyforge_project:
69
71
  rubygems_version: 2.0.3
@@ -1,42 +0,0 @@
1
- require 'snow-math/bindings'
2
-
3
- module Snow
4
-
5
- [:Vec3Array, :Vec4Array, :QuatArray, :Mat4Array].each {
6
- |klass_sym|
7
- if const_defined?(klass_sym)
8
- const_get(klass_sym).class_exec {
9
- alias_method :__fetch__, :fetch
10
- alias_method :__resize__!, :resize!
11
- alias_method :__array_cache_initialize__, :initialize
12
-
13
- def initialize(*args)
14
- @__cache__ = []
15
- __array_cache_initialize__(*args)
16
- end
17
-
18
- def fetch(index)
19
- @__cache__[index] || (@__cache__[index] = __fetch__(index))
20
- end
21
-
22
- alias_method :[], :fetch
23
-
24
- def resize!(new_length)
25
- @__cache__ = []
26
- __resize__!(new_length)
27
- end
28
-
29
- def resize(new_length)
30
- arr = self.class.new(new_length)
31
- self_length = self.length
32
- (0 ... (self_length < new_length ? self_length : new_length)).each {
33
- |index|
34
- arr.store(index, self.fetch(index))
35
- }
36
- return arr
37
- end
38
- }
39
- end
40
- }
41
-
42
- end