geo3d 0.0.7 → 0.0.8

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -3
  3. data/lib/geo3d/version.rb +1 -1
  4. data/lib/vector.rb +21 -6
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96291332d1c108ec9adeee6a9ce2deb8244dac5e
4
- data.tar.gz: 95de37c194cda4d9462e9cd13accad6e4da44acf
3
+ metadata.gz: 870525f0b9b488f8fe0bd03f72e679d173b40222
4
+ data.tar.gz: c9803964afa4f1cf843b9a4472b2a16aa749abf5
5
5
  SHA512:
6
- metadata.gz: f7fa1397c73eb27f538fac995e5c5ce422059342968c51cf12ddc3653994fe0615ba893fc50fdb51a3ba76ca26815c2de1a1c2e40ccda50efb24fcecfa916062
7
- data.tar.gz: 0670ed712274a93812c7d304c194342edb08560ae6152afb0842fc3b617239576268e0329b92ddb3594a267bd5279c3acd6ad7fb4d6f3474a2e655db5887a71c
6
+ metadata.gz: b377f16be7634b34158dbf5b21d0960c3025a4188c1ffb1e90b905f0621063d94a0d3f5f2185e5db3dc019984065dc06f4eb05a7bc2358dad37e1fb3bf257143
7
+ data.tar.gz: 11fbe068470ca6034a2174344f5f6a33cbae544821ae5eb7136a91e3d02688ded7e672fedab991ff734d398f4f71c0dcb5be727be082b72cd6baba752af43ba4
data/README.md CHANGED
@@ -18,12 +18,12 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
  ```
21
- a = Geo3d::Vector.new 1, 0, 0
22
- b = Geo3d::Vector.new 0, 1, 0
21
+ a = Geo3d::Vector.point 1, 0, 0
22
+ b = Geo3d::Vector.point 0, 1, 0
23
23
  sum = a + b # add them together
24
24
  sum *= 2 #double the vector
25
25
 
26
- m = Geo3d::Matrix.translation 0, 5, 0 #create a translation matrix that transforms a points 5 units on the y-axis
26
+ m = Geo3d::Matrix.translation 0, 5, 0, #create a translation matrix that transforms a points 5 units on the y-axis
27
27
  sum = m * sum #apply the transform to our vector
28
28
  ```
29
29
 
@@ -32,6 +32,15 @@ sum = m * sum #apply the transform to our vector
32
32
 
33
33
  Describes a three dimensional point or direction. A vector has the following read/write attributes: x, y, z, w
34
34
 
35
+ Constructors
36
+ ```
37
+ a = Geo3d::Vector.new #all attributes are initialized to zero
38
+ b = Geo3d::Vector.new x,y,z,w #initialize all attributes directly
39
+ c = Geo3d::Vector.new x,y,z #initialize x,y, and z directly and default w to zero
40
+ d = Geo3d::Vector.point x,y,z #initialize x,y, and z directly and default w to one
41
+ e = Geo3d::Vector.direction x,y,z #initialize x,y, and z directly and default w to zero
42
+ ```
43
+
35
44
  Vectors are overloaded with all of the basic math operations.
36
45
 
37
46
  Addition
data/lib/geo3d/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Geo3d
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/vector.rb CHANGED
@@ -17,6 +17,14 @@ module Geo3d
17
17
  @w = args[3].to_f if args.size > 3
18
18
  end
19
19
 
20
+ def self.point *args
21
+ self.new(*args).one_w
22
+ end
23
+
24
+ def self.direction *args
25
+ self.new(*args).zero_w
26
+ end
27
+
20
28
  def zero_w
21
29
  self.class.new x, y, z, 0
22
30
  end
@@ -25,6 +33,10 @@ module Geo3d
25
33
  self.class.new x, y, z, 1
26
34
  end
27
35
 
36
+ def xyz
37
+ self.class.new x, y, z
38
+ end
39
+
28
40
  def to_s
29
41
  to_a.compact.join ' '
30
42
  end
@@ -42,19 +54,19 @@ module Geo3d
42
54
  end
43
55
 
44
56
  def + vec
45
- self.class.new x + vec.x, y + vec.y, z + vec.z, w + vec.w
57
+ self.class.new x + vec.x, y + vec.y, z + vec.z, w
46
58
  end
47
59
 
48
60
  def - vec
49
- self.class.new x - vec.x, y - vec.y, z - vec.z, w - vec.w
61
+ self.class.new x - vec.x, y - vec.y, z - vec.z, w
50
62
  end
51
63
 
52
64
  def * scalar
53
- self.class.new x * scalar, y * scalar, z * scalar, w * scalar
65
+ self.class.new x * scalar, y * scalar, z * scalar, w
54
66
  end
55
67
 
56
68
  def / scalar
57
- self.class.new x / scalar, y / scalar, z / scalar, w / scalar
69
+ self.class.new x / scalar, y / scalar, z / scalar, w
58
70
  end
59
71
 
60
72
  def == vec
@@ -98,7 +110,10 @@ module Geo3d
98
110
  end
99
111
 
100
112
  def lerp vec, s
101
- self + ( vec - self )*s;
113
+ l = self + (vec - self)*s
114
+ l.w = w + (vec.w - w)*s
115
+ l
102
116
  end
103
117
  end
104
- end
118
+ end
119
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo3d
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misha Conway