bivector 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.
Files changed (2) hide show
  1. data/lib/bivector.rb +52 -0
  2. metadata +45 -0
data/lib/bivector.rb ADDED
@@ -0,0 +1,52 @@
1
+ class Bivector
2
+ attr_accessor :x, :y
3
+
4
+ def initialize(xCoordinate, yCoordinate)
5
+ @x, @y = xCoordinate, yCoordinate
6
+ end
7
+
8
+ def +(another)
9
+ if another.is_a? Bivector
10
+ Bivector.new(x + another.x, y + another.y)
11
+ end
12
+ end
13
+
14
+ def -(another)
15
+ if another.is_a? Bivector
16
+ Bivector.new(x - another.x, y - another.y)
17
+ end
18
+ end
19
+
20
+ def *(aNumber)
21
+ end
22
+
23
+ def norm
24
+ (x**2 + y**2)**0.5
25
+ end
26
+ alias :length :norm
27
+
28
+ def zero?
29
+ return (x == 0 && y ==0) ? true : false
30
+ end
31
+ alias :zero_vector? :zero?
32
+ alias :null_vector? :zero?
33
+
34
+ def dot_product(another)
35
+ if another.is_a? Bivector
36
+ x * another.x + y * another.y
37
+ end
38
+ end
39
+ alias :inner_product :dot_product
40
+
41
+ def cross_product(another)
42
+ if another.is_a? Bivector
43
+ Bivector.new()
44
+ end
45
+ end
46
+ alias :outer_product :cross_product
47
+
48
+ def unit_vector
49
+ return nil if self.zero?
50
+ Bivector.new(x / self.norm, y / self.norm)
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bivector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hegwin Wang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A 2D Vector
15
+ email: zwt315@163.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/bivector.rb
21
+ homepage: https://github.com/hegwin/bivector
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.24
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: A 2D Vector class
45
+ test_files: []