vector2d 2.0.0 → 2.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.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +11 -1
- data/README.md +14 -10
- data/lib/vector2d/properties.rb +6 -6
- data/lib/vector2d/transformations.rb +16 -0
- data/lib/vector2d/version.rb +1 -1
- data/spec/lib/vector2d/transformations_spec.rb +14 -0
- data/spec/spec_helper.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e66f7c5a4f7dc7d945041bc94089919d161dd81f
|
4
|
+
data.tar.gz: 72e52f85daded8b240945fa886fb2c996baa6f3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16e3e2e590a4542559859ed212df578c4ccd73d2b1e4117b9ad9a70e20b793c10b5f320d5447e03df8d661dd1bcfb7967f9e69d281ba7a96c3a97efe93ed2281
|
7
|
+
data.tar.gz: 7d6aa7f2dfdf2644131fd50f860e978bf4ce6afa5381c6193859bfdfcf9d1d0882641ee2fee3328bf7a3de271763670e2cdc0577274310d2f46dea55e23a8ba4
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vector2d (2.0.
|
4
|
+
vector2d (2.0.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
+
codeclimate-test-reporter (0.3.0)
|
10
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
9
11
|
diff-lcs (1.2.5)
|
12
|
+
docile (1.1.4)
|
13
|
+
multi_json (1.10.1)
|
10
14
|
rake (10.3.2)
|
11
15
|
rspec (2.14.1)
|
12
16
|
rspec-core (~> 2.14.0)
|
@@ -16,11 +20,17 @@ GEM
|
|
16
20
|
rspec-expectations (2.14.5)
|
17
21
|
diff-lcs (>= 1.1.3, < 2.0)
|
18
22
|
rspec-mocks (2.14.6)
|
23
|
+
simplecov (0.8.2)
|
24
|
+
docile (~> 1.1.0)
|
25
|
+
multi_json
|
26
|
+
simplecov-html (~> 0.8.0)
|
27
|
+
simplecov-html (0.8.0)
|
19
28
|
|
20
29
|
PLATFORMS
|
21
30
|
ruby
|
22
31
|
|
23
32
|
DEPENDENCIES
|
33
|
+
codeclimate-test-reporter
|
24
34
|
rake (~> 10.3)
|
25
35
|
rspec (~> 2.1)
|
26
36
|
vector2d!
|
data/README.md
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
# Vector2d [](https://travis-ci.org/elektronaut/vector2d) [](https://codeclimate.com/github/elektronaut/vector2d)
|
1
|
+
# Vector2d [](https://travis-ci.org/elektronaut/vector2d) [](https://codeclimate.com/github/elektronaut/vector2d) [](https://codeclimate.com/github/elektronaut/vector2d)
|
2
2
|
|
3
3
|
Vector2d handles two-dimensional coordinates and vectors.
|
4
4
|
Vectors are immutable, meaning this is a purely functional library.
|
5
5
|
|
6
6
|
## Quick example
|
7
7
|
|
8
|
-
|
8
|
+
```ruby
|
9
|
+
require 'vector2d'
|
9
10
|
|
10
|
-
|
11
|
+
vector = Vector2d(50, 70)
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
vector.aspect_ratio # => 0.714285714285714
|
14
|
+
vector.length # => 86.0232526704263
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
vector * 2 # => Vector2d(100,140)
|
17
|
+
vector + Vector2d(20, 30) # => Vector2d(70,100)
|
17
18
|
|
18
|
-
|
19
|
+
vector.fit(Vector2d(64, 64)) # => Vector2d(64,45)
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
Vector2d.parse([50, 70]) # => Vector2d(50,70)
|
22
|
+
Vector2d.parse("50x70") # => Vector2d(50,70)
|
23
|
+
```
|
22
24
|
|
23
25
|
## Documentation
|
24
26
|
|
@@ -26,4 +28,6 @@ Vectors are immutable, meaning this is a purely functional library.
|
|
26
28
|
|
27
29
|
## License
|
28
30
|
|
31
|
+
Copyright (c) 2006-2014 Inge Jørgensen
|
32
|
+
|
29
33
|
Vector2d is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/lib/vector2d/properties.rb
CHANGED
@@ -4,7 +4,7 @@ class Vector2d
|
|
4
4
|
module Properties
|
5
5
|
# Angle of vector.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# Vector2d(2, 3).angle # => 0.9827..
|
8
8
|
#
|
9
9
|
def angle
|
10
10
|
Math.atan2(y, x)
|
@@ -12,7 +12,7 @@ class Vector2d
|
|
12
12
|
|
13
13
|
# Aspect ratio of vector.
|
14
14
|
#
|
15
|
-
#
|
15
|
+
# Vector2d(2, 3).aspect_ratio # => 0.6667..
|
16
16
|
#
|
17
17
|
def aspect_ratio
|
18
18
|
(x.to_f / y.to_f).abs
|
@@ -20,7 +20,7 @@ class Vector2d
|
|
20
20
|
|
21
21
|
# Length of vector.
|
22
22
|
#
|
23
|
-
#
|
23
|
+
# Vector2d(2, 3).length # => 3.6055..
|
24
24
|
#
|
25
25
|
def length
|
26
26
|
Math.sqrt(squared_length)
|
@@ -28,7 +28,7 @@ class Vector2d
|
|
28
28
|
|
29
29
|
# Squared length of vector.
|
30
30
|
#
|
31
|
-
#
|
31
|
+
# Vector2d(2, 3).squared_length # => 13
|
32
32
|
#
|
33
33
|
def squared_length
|
34
34
|
x * x + y * y
|
@@ -36,8 +36,8 @@ class Vector2d
|
|
36
36
|
|
37
37
|
# Is this a normalized vector?
|
38
38
|
#
|
39
|
-
#
|
40
|
-
#
|
39
|
+
# Vector2d(0, 1).normalized? # => true
|
40
|
+
# Vector2d(2, 3).normalized? # => false
|
41
41
|
#
|
42
42
|
def normalized?
|
43
43
|
self.length.to_f == 1.0
|
@@ -2,6 +2,22 @@
|
|
2
2
|
|
3
3
|
class Vector2d
|
4
4
|
module Transformations
|
5
|
+
# Rounds vector to up nearest integer.
|
6
|
+
#
|
7
|
+
# Vector2d(2.4, 3.6).ceil # => Vector2d(3,4)
|
8
|
+
#
|
9
|
+
def ceil
|
10
|
+
self.class.new(x.ceil, y.ceil)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Rounds vector to up nearest integer.
|
14
|
+
#
|
15
|
+
# Vector2d(2.4, 3.6).floor # => Vector2d(2,3)
|
16
|
+
#
|
17
|
+
def floor
|
18
|
+
self.class.new(x.floor, y.floor)
|
19
|
+
end
|
20
|
+
|
5
21
|
# Normalizes the vector.
|
6
22
|
#
|
7
23
|
# vector = Vector2d(2, 3)
|
data/lib/vector2d/version.rb
CHANGED
@@ -5,6 +5,20 @@ require 'spec_helper'
|
|
5
5
|
describe Vector2d::Transformations do
|
6
6
|
subject(:vector) { Vector2d.new(2, 3) }
|
7
7
|
|
8
|
+
describe "#ceil" do
|
9
|
+
subject(:vector) { Vector2d.new(2.3, 3.3) }
|
10
|
+
it "rounds the vector up" do
|
11
|
+
expect(vector.ceil).to eq(Vector2d.new(3, 4))
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#floor" do
|
16
|
+
subject(:vector) { Vector2d.new(2.7, 3.6) }
|
17
|
+
it "rounds the vector down" do
|
18
|
+
expect(vector.floor).to eq(Vector2d.new(2, 3))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
describe "#normalize" do
|
9
23
|
it "normalizes the vector" do
|
10
24
|
expect(vector.normalize.x).to be_within(0.0001).of(0.5547)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vector2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Inge Jørgensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|