vector2d 2.0.1 → 2.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e66f7c5a4f7dc7d945041bc94089919d161dd81f
4
- data.tar.gz: 72e52f85daded8b240945fa886fb2c996baa6f3f
3
+ metadata.gz: c2b44fba53d35dd9b96e94e2b17075b3be510f93
4
+ data.tar.gz: 4acdcb759c4d3fb6fc86adf0c4a8bfafe03b17cf
5
5
  SHA512:
6
- metadata.gz: 16e3e2e590a4542559859ed212df578c4ccd73d2b1e4117b9ad9a70e20b793c10b5f320d5447e03df8d661dd1bcfb7967f9e69d281ba7a96c3a97efe93ed2281
7
- data.tar.gz: 7d6aa7f2dfdf2644131fd50f860e978bf4ce6afa5381c6193859bfdfcf9d1d0882641ee2fee3328bf7a3de271763670e2cdc0577274310d2f46dea55e23a8ba4
6
+ metadata.gz: 5310a339406432a7007e3da8e1aee32dad8eb79cf4d878e1b9abe267ba10bc1019d023ce6a98ea8728165c0cef0c0bbafc3f31da255d35258d1d2e85bce1e347
7
+ data.tar.gz: 01fa40750bfa9ce96d6033652c8079709a977303286fd08fff142a0088fe9ccc5f630f567ed03fd4f1f142e51518267e6b7994a9fe628c630a00a9b02930cc15
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vector2d (2.0.1)
4
+ vector2d (2.0.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -2,7 +2,20 @@
2
2
 
3
3
  class Vector2d
4
4
  module Fitting
5
- # Returns a new vector fitting inside another vector, retaining the aspect ratio.
5
+
6
+ # Scales down the given vector unless it fits inside.
7
+ #
8
+ # vector = Vector2d(20, 20)
9
+ # vector.contain(Vector2d(10, 10)) # => Vector2d(10,10)
10
+ # vector.contain(Vector2d(40, 20)) # => Vector2d(20,10)
11
+ # vector.contain(Vector2d(20, 40)) # => Vector2d(10,20)
12
+ #
13
+ def contain(other)
14
+ v, _ = coerce(other)
15
+ (v.x > x || v.y > y) ? other.fit(self) : other
16
+ end
17
+
18
+ # Scales the vector to fit inside another vector, retaining the aspect ratio.
6
19
  #
7
20
  # vector = Vector2d(20, 10)
8
21
  # vector.fit(Vector2d(10, 10)) # => Vector2d(10,5)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class Vector2d
4
- VERSION = "2.0.1"
4
+ VERSION = "2.0.2"
5
5
  end
@@ -5,6 +5,34 @@ require 'spec_helper'
5
5
  describe Vector2d::Fitting do
6
6
  let(:original) { Vector2d.new(300, 300) }
7
7
 
8
+ describe "#contain" do
9
+ subject(:vector) { original.contain(comp) }
10
+
11
+ context "when vector is smaller" do
12
+ let(:comp) { Vector2d.new(150, 100) }
13
+ it "should not change it" do
14
+ expect(vector.x).to eq(150)
15
+ expect(vector.y).to eq(100)
16
+ end
17
+ end
18
+
19
+ context "when vector is wider" do
20
+ let(:comp) { Vector2d.new(400, 300) }
21
+ it "should scale it down" do
22
+ expect(vector.x).to eq(300)
23
+ expect(vector.y).to eq(225)
24
+ end
25
+ end
26
+
27
+ context "when vector is higher" do
28
+ let(:comp) { Vector2d.new(300, 400) }
29
+ it "should scale it down" do
30
+ expect(vector.x).to eq(225)
31
+ expect(vector.y).to eq(300)
32
+ end
33
+ end
34
+ end
35
+
8
36
  describe "#fit" do
9
37
  subject(:vector) { original.fit(comp) }
10
38
 
@@ -25,7 +53,7 @@ describe Vector2d::Fitting do
25
53
  end
26
54
  end
27
55
 
28
- describe "#contrain_one" do
56
+ describe "#fit_either" do
29
57
  let(:original) { Vector2d.new(300, 300) }
30
58
  subject(:vector) { original.fit_either(comp) }
31
59
 
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.1
4
+ version: 2.0.2
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-16 00:00:00.000000000 Z
11
+ date: 2014-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake