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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2b44fba53d35dd9b96e94e2b17075b3be510f93
4
- data.tar.gz: 4acdcb759c4d3fb6fc86adf0c4a8bfafe03b17cf
3
+ metadata.gz: e4a4ed3c9fc3c47783fa81e5959d89b1cbadc94a
4
+ data.tar.gz: 93c385328a4335f272844e31ba882814746c1f92
5
5
  SHA512:
6
- metadata.gz: 5310a339406432a7007e3da8e1aee32dad8eb79cf4d878e1b9abe267ba10bc1019d023ce6a98ea8728165c0cef0c0bbafc3f31da255d35258d1d2e85bce1e347
7
- data.tar.gz: 01fa40750bfa9ce96d6033652c8079709a977303286fd08fff142a0088fe9ccc5f630f567ed03fd4f1f142e51518267e6b7994a9fe628c630a00a9b02930cc15
6
+ metadata.gz: 7279a2e6b24a90359ef10068d8e54b1887699af0218b51ea977665a6c7f919e6f4597e106ba137cd9e75bc4d289983ca33c5f28da8a88a61b3a31188fa5d65cd
7
+ data.tar.gz: 71ece7a02af784784c5d5f757744d6fea21de21dc513507c5ba92ccf0b8f93632c122bdb9d3e6ac58c055fa72a2b5989a82c34468be8e3576f172e9033c22f91
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vector2d (2.0.2)
4
+ vector2d (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -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.
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Vector2d
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -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.3, 3.6) }
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.2
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-06-20 00:00:00.000000000 Z
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.2.0
91
+ rubygems_version: 2.4.1
92
92
  signing_key:
93
93
  specification_version: 4
94
94
  summary: Library for handling two-dimensional vectors