snow-math 0.0.1

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,57 @@
1
+ # This file is part of ruby-snowmath.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ require 'snow-math'
6
+
7
+ module Snow ; end
8
+
9
+ module Snow::Swizzle
10
+
11
+ def method_missing(sym, *args)
12
+ chars = sym.to_s
13
+ if chars =~ self.class.class_variable_get(:@@SWIZZLE_CHARS)
14
+ mapping = self.class.class_variable_get(:@@SWIZZLE_MAPPING)
15
+ arg_indices = chars.each_char.map {
16
+ |char|
17
+ index = mapping[char]
18
+ if index.nil?
19
+ raise ArgumentError, "No index mapping for swizzle character #{char} found"
20
+ end
21
+ index
22
+ }
23
+ swizzle_klass = mapping[chars.length]
24
+
25
+ if swizzle_klass.nil?
26
+ raise ArgumentError, "No swizzle class defined for #{chars.length} components"
27
+ end
28
+
29
+ self.class.class_exec(arg_indices, swizzle_klass) {
30
+ |indices, klass|
31
+ define_method(sym) { klass.new(indices.map { |index| self.fetch(index) }) }
32
+ }
33
+ return self.send(sym)
34
+ end
35
+
36
+ super sym, *args
37
+ end
38
+
39
+ end
40
+
41
+ class Snow::Vec3
42
+ @@SWIZZLE_CHARS = /^[xyz]{3,4}$/
43
+ @@SWIZZLE_MAPPING = { 3 => self, 4 => ::Snow::Vec4, 'x' => 0, 'y' => 1, 'z' => 2 }
44
+ include ::Snow::Swizzle
45
+ end
46
+
47
+ class Snow::Vec4
48
+ @@SWIZZLE_CHARS = /^[xyzw]{3,4}$/
49
+ @@SWIZZLE_MAPPING = { 3 => ::Snow::Vec3, 4 => self, 'x' => 0, 'y' => 1, 'z' => 2, 'w' => 3 }
50
+ include ::Snow::Swizzle
51
+ end
52
+
53
+ class Snow::Quat
54
+ @@SWIZZLE_CHARS = /^[xyzw]{3,4}$/
55
+ @@SWIZZLE_MAPPING = { 3 => ::Snow::Vec3, 4 => self, 'x' => 0, 'y' => 1, 'z' => 2, 'w' => 3 }
56
+ include ::Snow::Swizzle
57
+ end
@@ -0,0 +1,51 @@
1
+ # This file is part of ruby-snowmath.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ require 'snow-math'
6
+
7
+ module Snow ; end
8
+
9
+ module Snow::EnumeratorSupport
10
+ include ::Enumerable
11
+
12
+ def to_a
13
+ (0 ... self.length).each.map { |index| fetch(index) }
14
+ end
15
+
16
+ def each(&block)
17
+ return to_enum(:each) unless block_given?
18
+ (0 ... self.length).each {
19
+ |index|
20
+ yield(fetch(index))
21
+ }
22
+ self
23
+ end
24
+
25
+ def map!(&block)
26
+ return to_enum(:map!) unless block_given?
27
+ (0 ... self.length).each {
28
+ |index|
29
+ store(index, yield(fetch(index)))
30
+ }
31
+ self
32
+ end
33
+
34
+ def map(&block)
35
+ return to_enum(:map) unless block_given?
36
+ self.dup.map!(&block)
37
+ end
38
+
39
+ end
40
+
41
+ if Snow.const_defined?(:Vec3Array)
42
+ class Snow::Vec3Array ; include Snow::EnumeratorSupport ; end
43
+ class Snow::Vec4Array ; include Snow::EnumeratorSupport ; end
44
+ class Snow::QuatArray ; include Snow::EnumeratorSupport ; end
45
+ class Snow::Mat4Array ; include Snow::EnumeratorSupport ; end
46
+ end
47
+
48
+ class Snow::Vec3 ; include Snow::EnumeratorSupport ; end
49
+ class Snow::Vec4 ; include Snow::EnumeratorSupport ; end
50
+ class Snow::Quat ; include Snow::EnumeratorSupport ; end
51
+ class Snow::Mat4 ; include Snow::EnumeratorSupport ; end
File without changes
@@ -0,0 +1,111 @@
1
+ # This file is part of ruby-snowmath.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ require 'snow-math/bindings'
6
+
7
+ module Snow ; end
8
+
9
+ if Snow.const_defined?(:Vec3Array)
10
+ class Snow::Vec3Array
11
+ class << self ; alias_method :[], :new ; end
12
+
13
+ alias_method :[], :fetch
14
+ alias_method :[]=, :store
15
+ end
16
+ end
17
+
18
+ class Snow::Vec3
19
+
20
+ # Shortcut through to new
21
+ class << self ; alias_method :[], :new ; end
22
+
23
+ alias_method :[], :fetch
24
+ alias_method :[]=, :store
25
+
26
+ def x
27
+ self[0]
28
+ end
29
+
30
+ def x=(value)
31
+ self[0] = value
32
+ end
33
+
34
+ def y
35
+ self[1]
36
+ end
37
+
38
+ def y=(value)
39
+ self[1] = value
40
+ end
41
+
42
+ def z
43
+ self[2]
44
+ end
45
+
46
+ def z=(value)
47
+ self[2] = value
48
+ end
49
+
50
+ def dup
51
+ self.class.new(self)
52
+ end
53
+
54
+ def normalize!
55
+ normalize self
56
+ end
57
+
58
+ def inverse!
59
+ inverse self
60
+ end
61
+
62
+ def negate!
63
+ negate self
64
+ end
65
+
66
+ def cross_product!(rhs)
67
+ cross_product rhs, self
68
+ end
69
+
70
+ def multiply_vec3!(rhs)
71
+ multiply_vec3 rhs, self
72
+ end
73
+
74
+ def multiply(rhs, output = nil)
75
+ case rhs
76
+ when Vec3 then multiply_vec3(rhs, output)
77
+ when Numeric then scale(rhs, output)
78
+ else raise TypeError, "Invalid type for RHS"
79
+ end
80
+ end
81
+
82
+ def multiply!(rhs)
83
+ multiply rhs, self
84
+ end
85
+
86
+ def add!(rhs)
87
+ add rhs, self
88
+ end
89
+
90
+ def subtract!(rhs)
91
+ subtract rhs, self
92
+ end
93
+
94
+ def scale!(rhs)
95
+ scale rhs, self
96
+ end
97
+
98
+ def divide!(rhs)
99
+ divide rhs, self
100
+ end
101
+
102
+ alias_method :-, :subtract
103
+ alias_method :+, :add
104
+ alias_method :^, :cross_product
105
+ alias_method :**, :dot_product
106
+ alias_method :*, :multiply
107
+ alias_method :/, :divide
108
+ alias_method :-@, :negate
109
+ alias_method :~, :inverse
110
+
111
+ end
@@ -0,0 +1,113 @@
1
+ # This file is part of ruby-snowmath.
2
+ # Copyright (c) 2013 Noel Raymond Cower. All rights reserved.
3
+ # See COPYING for license details.
4
+
5
+ require 'snow-math/bindings'
6
+
7
+ module Snow ; end
8
+
9
+ if Snow.const_defined?(:Vec4Array)
10
+ class Snow::Vec4Array
11
+ class << self ; alias_method :[], :new ; end
12
+
13
+ alias_method :[], :fetch
14
+ alias_method :[]=, :store
15
+ end
16
+ end
17
+
18
+ class Snow::Vec4
19
+
20
+ class << self ; alias_method :[], :new ; end
21
+
22
+ alias_method :[], :fetch
23
+ alias_method :[]=, :store
24
+
25
+ def x
26
+ self[0]
27
+ end
28
+
29
+ def x=(value)
30
+ self[0] = value
31
+ end
32
+
33
+ def y
34
+ self[1]
35
+ end
36
+
37
+ def y=(value)
38
+ self[1] = value
39
+ end
40
+
41
+ def z
42
+ self[2]
43
+ end
44
+
45
+ def z=(value)
46
+ self[2] = value
47
+ end
48
+
49
+ def w
50
+ self[3]
51
+ end
52
+
53
+ def w=(value)
54
+ self[3] = value
55
+ end
56
+
57
+ def dup
58
+ self.class.new(self)
59
+ end
60
+
61
+ def normalize!
62
+ normalize self
63
+ end
64
+
65
+ def inverse!
66
+ inverse self
67
+ end
68
+
69
+ def negate!
70
+ negate self
71
+ end
72
+
73
+ def multiply_vec4!(rhs)
74
+ multiply_vec4 rhs, self
75
+ end
76
+
77
+ def multiply(rhs, output = nil)
78
+ case rhs
79
+ when Vec4 then multiply_vec4(rhs, output)
80
+ when Numeric then scale(rhs, output)
81
+ else raise TypeError, "Invalid type for RHS"
82
+ end
83
+ end
84
+
85
+ def multiply!(rhs)
86
+ multiply rhs, self
87
+ end
88
+
89
+ def add!(rhs)
90
+ add rhs, self
91
+ end
92
+
93
+ def subtract!(rhs)
94
+ subtract rhs, self
95
+ end
96
+
97
+ def scale!(rhs)
98
+ scale rhs, self
99
+ end
100
+
101
+ def divide!(rhs)
102
+ divide rhs, self
103
+ end
104
+
105
+ alias_method :-, :subtract
106
+ alias_method :+, :add
107
+ alias_method :*, :multiply
108
+ alias_method :/, :divide
109
+ alias_method :**, :dot_product
110
+ alias_method :-@, :negate
111
+ alias_method :~, :inverse
112
+
113
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: snow-math
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Noel Raymond Cower
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Math types built on the SnowPalm math code
14
+ email: ncower@gmail.com
15
+ executables: []
16
+ extensions:
17
+ - ext/extconf.rb
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/snow-math/inspect.rb
21
+ - lib/snow-math/line.rb
22
+ - lib/snow-math/mat3.rb
23
+ - lib/snow-math/mat4.rb
24
+ - lib/snow-math/plane.rb
25
+ - lib/snow-math/ptr.rb
26
+ - lib/snow-math/quat.rb
27
+ - lib/snow-math/swizzle.rb
28
+ - lib/snow-math/to_a.rb
29
+ - lib/snow-math/vec2.rb
30
+ - lib/snow-math/vec3.rb
31
+ - lib/snow-math/vec4.rb
32
+ - lib/snow-math.rb
33
+ - ext/snow-math/mat4.c
34
+ - ext/snow-math/maths.c
35
+ - ext/snow-math/quat.c
36
+ - ext/snow-math/snow-math.c
37
+ - ext/snow-math/vec3.c
38
+ - ext/snow-math/vec4.c
39
+ - ext/snow-math/maths_local.h
40
+ - ext/extconf.rb
41
+ homepage: https://github.com/nilium/ruby-snowmath
42
+ licenses:
43
+ - Simplified BSD
44
+ metadata: {}
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --title
48
+ - snowmath -- 3D Math Types
49
+ - --main
50
+ - README.md
51
+ - --line-numbers
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.3
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Snow Math Types
70
+ test_files: []
71
+ has_rdoc: