bivector 0.0.2 → 0.0.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.
Files changed (2) hide show
  1. data/lib/bivector.rb +76 -64
  2. metadata +1 -1
data/lib/bivector.rb CHANGED
@@ -1,64 +1,76 @@
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 / norm, y / norm)
51
- end
52
-
53
- def angles_to(another, style = 'rad')
54
- if another.is_a? Bivector
55
- angle = Math.acos(dot_product(another) / ( norm * another.norm))
56
- case style
57
- when 'rad'
58
- return angle
59
- when 'ang'
60
- return angle * 360 / Math::PI
61
- end
62
- end
63
- end
64
- end
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 / norm, y / norm)
51
+ end
52
+
53
+ def angles_to(another, style = 'rad')
54
+ if another.is_a? Bivector
55
+ angle = Math.acos(dot_product(another) / ( norm * another.norm))
56
+ case style
57
+ when 'rad'
58
+ return angle
59
+ when 'ang'
60
+ return angle * 180 / Math::PI
61
+ end
62
+ end
63
+ end
64
+
65
+ def parallels_to?(another)
66
+ if another.is_a? Bivector
67
+ self.zero? || another.zero? || x * another.y - y * another.x == 0
68
+ end
69
+ end
70
+
71
+ def perpendicular_to?(another)
72
+ if another.is_a? Bivector
73
+ self.dot_product(another) == 0
74
+ end
75
+ end
76
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bivector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: