vector2d 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/vector2d/transformations.rb +11 -2
- data/lib/vector2d/version.rb +1 -1
- data/spec/lib/vector2d/transformations_spec.rb +14 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4a4ed3c9fc3c47783fa81e5959d89b1cbadc94a
|
4
|
+
data.tar.gz: 93c385328a4335f272844e31ba882814746c1f92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7279a2e6b24a90359ef10068d8e54b1887699af0218b51ea977665a6c7f919e6f4597e106ba137cd9e75bc4d289983ca33c5f28da8a88a61b3a31188fa5d65cd
|
7
|
+
data.tar.gz: 71ece7a02af784784c5d5f757744d6fea21de21dc513507c5ba92ccf0b8f93632c122bdb9d3e6ac58c055fa72a2b5989a82c34468be8e3576f172e9033c22f91
|
data/Gemfile.lock
CHANGED
@@ -52,12 +52,21 @@ class Vector2d
|
|
52
52
|
self.class.new(-x, -y)
|
53
53
|
end
|
54
54
|
|
55
|
+
# Rotates the vector
|
56
|
+
#
|
57
|
+
# Vector2d(1, 0).rotate(Math:PI/2) => Vector2d(1,0)
|
58
|
+
#
|
59
|
+
def rotate(angle)
|
60
|
+
Vector2d.new(x * Math.cos(angle) - y * Math.sin(angle), x * Math.sin(angle) + y * Math.cos(angle))
|
61
|
+
end
|
62
|
+
|
55
63
|
# Rounds vector to nearest integer.
|
56
64
|
#
|
57
65
|
# Vector2d(2.4, 3.6).round # => Vector2d(2,4)
|
66
|
+
# Vector2d(2.4444, 3.666).round(2) # => Vector2d(2.44, 3.67)
|
58
67
|
#
|
59
|
-
def round
|
60
|
-
self.class.new(x.round, y.round)
|
68
|
+
def round(digits=0)
|
69
|
+
self.class.new(x.round(digits), y.round(digits))
|
61
70
|
end
|
62
71
|
|
63
72
|
# Truncates to max length if vector is longer than max.
|
data/lib/vector2d/version.rb
CHANGED
@@ -47,10 +47,21 @@ describe Vector2d::Transformations do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "#rotate" do
|
51
|
+
let(:vector) { Vector2d.new(1, 0) }
|
52
|
+
it "rotates the vector" do
|
53
|
+
expect(vector.rotate(Math::PI).round(1)).to eq(Vector2d.new(-1, 0))
|
54
|
+
expect(vector.rotate(Math::PI/2).round(1)).to eq(Vector2d.new(0, 1))
|
55
|
+
expect(vector.rotate(-Math::PI/2).round(1)).to eq(Vector2d.new(0, -1))
|
56
|
+
expect(vector.rotate(Math::PI/4).round(3)).to eq(Vector2d.new(0.707, 0.707))
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
describe "#round" do
|
51
|
-
subject(:vector) { Vector2d.new(2.
|
61
|
+
subject(:vector) { Vector2d.new(2.3333, 3.666) }
|
52
62
|
it "rounds the vector" do
|
53
63
|
expect(vector.round).to eq(Vector2d.new(2, 4))
|
64
|
+
expect(vector.round(2)).to eq (Vector2d.new(2.33, 3.67))
|
54
65
|
end
|
55
66
|
end
|
56
67
|
|
@@ -68,4 +79,6 @@ describe Vector2d::Transformations do
|
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end
|
82
|
+
|
83
|
+
|
71
84
|
end
|
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.1.0
|
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-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -88,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
91
|
+
rubygems_version: 2.4.1
|
92
92
|
signing_key:
|
93
93
|
specification_version: 4
|
94
94
|
summary: Library for handling two-dimensional vectors
|