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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/vector2d/fitting.rb +14 -1
- data/lib/vector2d/version.rb +1 -1
- data/spec/lib/vector2d/fitting_spec.rb +29 -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: c2b44fba53d35dd9b96e94e2b17075b3be510f93
|
4
|
+
data.tar.gz: 4acdcb759c4d3fb6fc86adf0c4a8bfafe03b17cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5310a339406432a7007e3da8e1aee32dad8eb79cf4d878e1b9abe267ba10bc1019d023ce6a98ea8728165c0cef0c0bbafc3f31da255d35258d1d2e85bce1e347
|
7
|
+
data.tar.gz: 01fa40750bfa9ce96d6033652c8079709a977303286fd08fff142a0088fe9ccc5f630f567ed03fd4f1f142e51518267e6b7994a9fe628c630a00a9b02930cc15
|
data/Gemfile.lock
CHANGED
data/lib/vector2d/fitting.rb
CHANGED
@@ -2,7 +2,20 @@
|
|
2
2
|
|
3
3
|
class Vector2d
|
4
4
|
module Fitting
|
5
|
-
|
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)
|
data/lib/vector2d/version.rb
CHANGED
@@ -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 "#
|
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.
|
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-
|
11
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|