wector 0.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +12 -0
- data/Rakefile +1 -0
- data/lib/wector.rb +67 -0
- data/wector.gemspec +22 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3ad1ed315bccca62b4e2e13998f1b6650e57568a
|
4
|
+
data.tar.gz: 84d317bc05507b498d6600563e3b7b389fb2feac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a869f2c0b7a53e01e15649dd5d8c670f55dcf36cbe0bac907ef8e8ba05f73832dfbb95b51bd31d7e0f6b502281f42b9ad9980b3320acebc2f6d323d96602898f
|
7
|
+
data.tar.gz: 79aa29c909682638bb53c57df5402661c9a006695c23c5e1de0fc246498ae3d1e6b12adeea587194c341dc057f485bbf8133501b561bd9efeb31e4e7c6b5df1f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Stephen Belanger
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Wector
|
2
|
+
|
3
|
+
Wector does what we all wish the built-in Vector class did; it makes vector math easy by allowing any method of the Numeric interface to be used to combine two arrays or an array and a number.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add `wector` to your application's Gemfile and `bundle install` or install it yourself with `gem install wector`.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
vector = Wector.new([1.2, 3.4, 5.6, 7.8])
|
12
|
+
p vector + (vector ** 2)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/wector.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
class Wector < Array
|
2
|
+
def [](*args)
|
3
|
+
args.each do |arg|
|
4
|
+
raise "Non-numeric item" unless arg.is_a?(Integer) or arg.is_a?(Float)
|
5
|
+
unshift arg
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Comparison operators
|
11
|
+
[
|
12
|
+
:*,:+,:/,:-,:**,:%,:^,:==,:===,:<=>,:>,:>=,:<,:<=,:~,:&,:|
|
13
|
+
].map { |v| v.to_s }.each do |attr_name|
|
14
|
+
Wector.class_eval %Q{
|
15
|
+
def #{attr_name}(other)
|
16
|
+
if other.is_a? Array
|
17
|
+
raise "Incorrect Dimensions" unless self.size == other.size
|
18
|
+
other = other.dup
|
19
|
+
self.class.new(map { |i| i #{attr_name} other.shift })
|
20
|
+
elsif other.is_a?(Integer) or other.is_a?(Float)
|
21
|
+
self.class.new(map { |i| i #{attr_name} other })
|
22
|
+
else
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# Comparison methods
|
30
|
+
[
|
31
|
+
:-@, :+@, :modulo, :coerce, :div, :divmod, :eql?, :fdiv, :quo, :remainder,
|
32
|
+
:round
|
33
|
+
].map { |v| v.to_s }.each do |attr_name|
|
34
|
+
Wector.class_eval %Q{
|
35
|
+
def #{attr_name}(other)
|
36
|
+
if other.is_a? Array
|
37
|
+
raise "Incorrect Dimensions" unless self.size == other.size
|
38
|
+
other = other.dup
|
39
|
+
self.class.new(map { |i| i.#{attr_name} other.shift })
|
40
|
+
elsif other.is_a?(Integer) or other.is_a?(Float)
|
41
|
+
self.class.new(map { |i| i.#{attr_name} other })
|
42
|
+
else
|
43
|
+
super
|
44
|
+
end
|
45
|
+
end
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
# Transform methods
|
50
|
+
[
|
51
|
+
:ceil, :abs, :abs2, :magnitude, :arg, :angle, :phase, :conj, :conjugate,
|
52
|
+
:denominator, :floor, :imag, :imaginary, :integer?, :nonzero?, :numerator,
|
53
|
+
:polar, :real, :real?, :rect, :to_c, :to_int, :truncate, :zero?
|
54
|
+
].map { |v| v.to_s }.each do |attr_name|
|
55
|
+
Wector.class_eval %Q{
|
56
|
+
def #{attr_name}
|
57
|
+
self.class.new(map { |i| i.#{attr_name} })
|
58
|
+
end
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
# Add interface to convert arrays to vectors
|
63
|
+
class Array
|
64
|
+
def to_wector
|
65
|
+
Wector.new(self)
|
66
|
+
end
|
67
|
+
end
|
data/wector.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "wector"
|
4
|
+
spec.version = "0.0.2"
|
5
|
+
spec.authors = ["Stephen Belanger"]
|
6
|
+
spec.email = ["admin@stephenbelanger.com"]
|
7
|
+
spec.description = %q{
|
8
|
+
Wector does what we all wish the built-in Vector class did; it makes vector
|
9
|
+
math easy by allowing any method of the Numeric interface to be used to
|
10
|
+
combine two arrays or an array and a number.
|
11
|
+
}
|
12
|
+
spec.summary = %q{Wector makes vector math dead simple}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Belanger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: "\n Wector does what we all wish the built-in Vector class did; it
|
42
|
+
makes vector\n math easy by allowing any method of the Numeric interface to be
|
43
|
+
used to\n combine two arrays or an array and a number.\n "
|
44
|
+
email:
|
45
|
+
- admin@stephenbelanger.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- .gitignore
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/wector.rb
|
56
|
+
- wector.gemspec
|
57
|
+
homepage: ''
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.0
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Wector makes vector math dead simple
|
81
|
+
test_files: []
|