vector2d 2.2.3 → 2.3.0

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.
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Vector2d::Fitting do
6
6
  let(:original) { Vector2d.new(300, 300) }
@@ -10,26 +10,23 @@ describe Vector2d::Fitting do
10
10
 
11
11
  context "when vector is smaller" do
12
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
13
+
14
+ its(:x) { is_expected.to eq(150) }
15
+ its(:y) { is_expected.to eq(100) }
17
16
  end
18
17
 
19
18
  context "when vector is wider" do
20
19
  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
20
+
21
+ its(:x) { is_expected.to eq(300) }
22
+ its(:y) { is_expected.to eq(225) }
25
23
  end
26
24
 
27
25
  context "when vector is higher" do
28
26
  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
27
+
28
+ its(:x) { is_expected.to eq(225) }
29
+ its(:y) { is_expected.to eq(300) }
33
30
  end
34
31
  end
35
32
 
@@ -38,39 +35,36 @@ describe Vector2d::Fitting do
38
35
 
39
36
  context "when scaling by height" do
40
37
  let(:comp) { Vector2d.new(200, 150) }
41
- it "should fit within the other vector" do
42
- expect(vector.x).to eq(150)
43
- expect(vector.y).to eq(150)
44
- end
38
+
39
+ its(:x) { is_expected.to eq(150) }
40
+ its(:y) { is_expected.to eq(150) }
45
41
  end
46
42
 
47
43
  context "when scaling by width" do
48
44
  let(:comp) { Vector2d.new(150, 200) }
49
- it "should fit within the other vector" do
50
- expect(vector.x).to eq(150)
51
- expect(vector.y).to eq(150)
52
- end
45
+
46
+ its(:x) { is_expected.to eq(150) }
47
+ its(:y) { is_expected.to eq(150) }
53
48
  end
54
49
  end
55
50
 
56
51
  describe "#fit_either" do
57
- let(:original) { Vector2d.new(300, 300) }
58
52
  subject(:vector) { original.fit_either(comp) }
59
53
 
54
+ let(:original) { Vector2d.new(300, 300) }
55
+
60
56
  context "when width is largest" do
61
57
  let(:comp) { Vector2d.new(200, 150) }
62
- it "should be the same width" do
63
- expect(vector.x).to eq(200)
64
- expect(vector.y).to eq(200)
65
- end
58
+
59
+ its(:x) { is_expected.to eq(200) }
60
+ its(:y) { is_expected.to eq(200) }
66
61
  end
67
62
 
68
63
  context "when height is largest" do
69
64
  let(:comp) { Vector2d.new(150, 200) }
70
- it "should be the same height" do
71
- expect(vector.x).to eq(200)
72
- expect(vector.y).to eq(200)
73
- end
65
+
66
+ its(:x) { is_expected.to eq(200) }
67
+ its(:y) { is_expected.to eq(200) }
74
68
  end
75
69
  end
76
- end
70
+ end
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Vector2d::Properties do
6
6
  subject(:vector) { Vector2d.new(2, 3) }
@@ -31,13 +31,17 @@ describe Vector2d::Properties do
31
31
 
32
32
  describe "#normalized?" do
33
33
  subject { vector.normalized? }
34
+
34
35
  context "when vector is normalized" do
35
36
  let(:vector) { Vector2d.new(2, 3).normalize }
36
- it { is_expected.to eq(true) }
37
+
38
+ it { is_expected.to be(true) }
37
39
  end
40
+
38
41
  context "when vector isn't normalized" do
39
42
  let(:vector) { Vector2d.new(2, 3) }
40
- it { is_expected.to eq(false) }
43
+
44
+ it { is_expected.to be(false) }
41
45
  end
42
46
  end
43
47
  end
@@ -1,29 +1,48 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Vector2d::Transformations do
6
6
  subject(:vector) { Vector2d.new(2, 3) }
7
7
 
8
8
  describe "#ceil" do
9
9
  subject(:vector) { Vector2d.new(2.3, 3.3) }
10
+
10
11
  it "rounds the vector up" do
11
12
  expect(vector.ceil).to eq(Vector2d.new(3, 4))
12
13
  end
13
14
  end
14
15
 
16
+ describe "#clamp" do
17
+ subject(:vector) { Vector2d.new(2, 8) }
18
+
19
+ it "clamps each axis" do
20
+ expect(vector.clamp(Vector2d.new(3, 3), Vector2d.new(6, 6)))
21
+ .to eq(Vector2d.new(3, 6))
22
+ end
23
+
24
+ it "coerces the bounds" do
25
+ expect(vector.clamp(3, 6)).to eq(Vector2d.new(3, 6))
26
+ end
27
+
28
+ it "leaves a vector within the bounds alone" do
29
+ expect(vector.clamp(0, 10)).to eq(vector)
30
+ end
31
+ end
32
+
15
33
  describe "#floor" do
16
34
  subject(:vector) { Vector2d.new(2.7, 3.6) }
35
+
17
36
  it "rounds the vector down" do
18
37
  expect(vector.floor).to eq(Vector2d.new(2, 3))
19
38
  end
20
39
  end
21
40
 
22
41
  describe "#normalize" do
23
- it "normalizes the vector" do
24
- expect(vector.normalize.x).to be_within(0.0001).of(0.5547)
25
- expect(vector.normalize.y).to be_within(0.0001).of(0.8320)
26
- end
42
+ subject { vector.normalize }
43
+
44
+ its(:x) { is_expected.to be_within(0.0001).of(0.5547) }
45
+ its(:y) { is_expected.to be_within(0.0001).of(0.8320) }
27
46
  end
28
47
 
29
48
  describe "#perpendicular" do
@@ -34,9 +53,16 @@ describe Vector2d::Transformations do
34
53
 
35
54
  describe "#resize" do
36
55
  subject(:resized) { vector.resize(2.0) }
56
+
37
57
  it "modifies the vector length" do
38
58
  expect(resized.length).to be_within(0.0001).of(2.0)
59
+ end
60
+
61
+ it "modifies the x property" do
39
62
  expect(resized.x).to be_within(0.0001).of(1.1094)
63
+ end
64
+
65
+ it "modifies the y property" do
40
66
  expect(resized.y).to be_within(0.0001).of(1.6641)
41
67
  end
42
68
  end
@@ -48,37 +74,66 @@ describe Vector2d::Transformations do
48
74
  end
49
75
 
50
76
  describe "#rotate" do
77
+ subject { vector.rotate(rotation).round(3) }
78
+
51
79
  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))
80
+
81
+ context "when roating by PI" do
82
+ let(:rotation) { Math::PI }
83
+
84
+ it { is_expected.to eq(Vector2d.new(-1, 0)) }
85
+ end
86
+
87
+ context "when roating by PI/2" do
88
+ let(:rotation) { Math::PI / 2 }
89
+
90
+ it { is_expected.to eq(Vector2d.new(0, 1)) }
91
+ end
92
+
93
+ context "when roating by -PI/2" do
94
+ let(:rotation) { -Math::PI / 2 }
95
+
96
+ it { is_expected.to eq(Vector2d.new(0, -1)) }
97
+ end
98
+
99
+ context "when roating by PI/4" do
100
+ let(:rotation) { Math::PI / 4 }
101
+
102
+ it { is_expected.to eq(Vector2d.new(0.707, 0.707)) }
57
103
  end
58
104
  end
59
105
 
60
106
  describe "#round" do
61
- subject(:vector) { Vector2d.new(2.3333, 3.666) }
62
- it "rounds the vector" do
63
- expect(vector.round).to eq(Vector2d.new(2, 4))
64
- expect(vector.round(2)).to eq (Vector2d.new(2.33, 3.67))
107
+ let(:vector) { Vector2d.new(2.3333, 3.666) }
108
+
109
+ context "without argument" do
110
+ subject { vector.round }
111
+
112
+ it { is_expected.to eq(Vector2d.new(2, 4)) }
113
+ end
114
+
115
+ context "with precision" do
116
+ subject { vector.round(2) }
117
+
118
+ it { is_expected.to eq(Vector2d.new(2.33, 3.67)) }
65
119
  end
66
120
  end
67
121
 
68
122
  describe "#truncate" do
69
123
  context "when argument is longer than length" do
70
124
  let(:arg) { 5.0 }
125
+
71
126
  it "does not change the length" do
72
127
  expect(vector.truncate(arg).length).to be_within(0.0001).of(3.6055)
73
128
  end
74
129
  end
130
+
75
131
  context "when argument is shorter than length" do
76
132
  let(:arg) { 2.5 }
133
+
77
134
  it "changes the length" do
78
135
  expect(vector.truncate(arg).length).to be_within(0.0001).of(arg)
79
136
  end
80
137
  end
81
138
  end
82
-
83
-
84
- end
139
+ end
@@ -1,76 +1,90 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
3
+ require "spec_helper"
4
4
 
5
5
  describe Vector2d do
6
- subject(:vector) { Vector2d.new(2, 3) }
6
+ subject(:vector) { described_class.new(2, 3) }
7
7
 
8
8
  shared_examples "a parsed vector" do |x, y|
9
- it "receives the x and y properties" do
9
+ it "receives the x property" do
10
10
  expect(subject.x).to eq(x)
11
+ end
12
+
13
+ it "receives the y property" do
11
14
  expect(subject.y).to eq(y)
12
15
  end
13
16
  end
14
17
 
15
18
  describe "helper method" do
16
19
  it "creates a vector" do
17
- expect(Vector2d(2, 3)).to eq(Vector2d.new(2, 3))
20
+ expect(Vector2d(2, 3)).to eq(described_class.new(2, 3))
18
21
  end
19
22
  end
20
23
 
21
24
  describe ".parse" do
22
25
  context "with fixnum argument" do
23
- subject(:vector) { Vector2d.parse(2) }
26
+ subject(:vector) { described_class.parse(2) }
27
+
24
28
  it_behaves_like "a parsed vector", [2, 2]
25
29
  end
26
30
 
27
31
  context "with two arguments, fixnum" do
28
- subject(:vector) { Vector2d.parse(1, 2) }
32
+ subject(:vector) { described_class.parse(1, 2) }
33
+
29
34
  it_behaves_like "a parsed vector", [1, 2]
30
35
  end
31
36
 
32
37
  context "with two arguments, float" do
33
- subject(:vector) { Vector2d.parse(1.0, 2.0) }
38
+ subject(:vector) { described_class.parse(1.0, 2.0) }
39
+
34
40
  it_behaves_like "a parsed vector", [1.0, 2.0]
35
41
  end
36
42
 
37
43
  context "with string argument, first omitted" do
38
- subject(:vector) { Vector2d.parse("x200") }
44
+ subject(:vector) { described_class.parse("x200") }
45
+
39
46
  it_behaves_like "a parsed vector", [0, 200]
40
47
  end
41
48
 
42
49
  context "with string argument, second omitted" do
43
- subject(:vector) { Vector2d.parse("200x") }
50
+ subject(:vector) { described_class.parse("200x") }
51
+
44
52
  it_behaves_like "a parsed vector", [200, 0]
45
53
  end
46
54
 
47
55
  context "with string argument, fixnum" do
48
- subject(:vector) { Vector2d.parse("1x2") }
56
+ subject(:vector) { described_class.parse("1x2") }
57
+
49
58
  it_behaves_like "a parsed vector", [1, 2]
50
59
  end
51
60
 
52
61
  context "with string argument, float" do
53
- subject(:vector) { Vector2d.parse("1.0x2.0") }
62
+ subject(:vector) { described_class.parse("1.0x2.0") }
63
+
54
64
  it_behaves_like "a parsed vector", [1.0, 2.0]
55
65
  end
56
66
 
57
67
  context "with array argument" do
58
- subject(:vector) { Vector2d.parse([1, 2]) }
68
+ subject(:vector) { described_class.parse([1, 2]) }
69
+
59
70
  it_behaves_like "a parsed vector", [1, 2]
60
71
  end
61
72
 
62
73
  context "with hash argument, symbol keys" do
63
- subject(:vector) { Vector2d.parse({:x => 1, :y => 2}) }
74
+ subject(:vector) { described_class.parse(x: 1, y: 2) }
75
+
64
76
  it_behaves_like "a parsed vector", [1, 2]
65
77
  end
66
78
 
67
79
  context "with hash argument, string keys" do
68
- subject(:vector) { Vector2d.parse({'x' => 1, 'y' => 2}) }
80
+ subject(:vector) { described_class.parse("x" => 1, "y" => 2) }
81
+
69
82
  it_behaves_like "a parsed vector", [1, 2]
70
83
  end
71
84
 
72
85
  context "with vector argument" do
73
- subject(:vector) { Vector2d.parse(Vector2d.new(1, 2)) }
86
+ subject(:vector) { described_class.parse(described_class.new(1, 2)) }
87
+
74
88
  it_behaves_like "a parsed vector", [1, 2]
75
89
  end
76
90
  end
@@ -79,18 +93,21 @@ describe Vector2d do
79
93
  subject { vector == comp }
80
94
 
81
95
  context "with both arguments equal" do
82
- let(:comp) { Vector2d.new(2, 3) }
83
- it { is_expected.to eq(true) }
96
+ let(:comp) { described_class.new(2, 3) }
97
+
98
+ it { is_expected.to be(true) }
84
99
  end
85
100
 
86
101
  context "with x differing" do
87
- let(:comp) { Vector2d.new(3, 3) }
88
- it { is_expected.to eq(false) }
102
+ let(:comp) { described_class.new(3, 3) }
103
+
104
+ it { is_expected.to be(false) }
89
105
  end
90
106
 
91
107
  context "with y differing" do
92
- let(:comp) { Vector2d.new(2, 4) }
93
- it { is_expected.to eq(false) }
108
+ let(:comp) { described_class.new(2, 4) }
109
+
110
+ it { is_expected.to be(false) }
94
111
  end
95
112
  end
96
113
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require "codeclimate-test-reporter"
4
- CodeClimate::TestReporter.start
3
+ require "simplecov"
4
+ SimpleCov.start
5
5
 
6
- require "vector2d"
6
+ require "vector2d"
7
+ require "rspec/its"
data/vector2d.gemspec CHANGED
@@ -1,31 +1,31 @@
1
- # coding: utf-8
2
- # Generated by jeweler
3
- # DO NOT EDIT THIS FILE DIRECTLY
4
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
5
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
6
2
 
7
- $:.push File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
8
4
  require "vector2d/version"
9
5
 
10
6
  Gem::Specification.new do |s|
11
- s.name = %q{vector2d}
7
+ s.name = "vector2d"
12
8
  s.version = Vector2d::VERSION
13
9
  s.authors = ["Inge Jørgensen"]
14
10
  s.email = ["inge@elektronaut.no"]
15
- s.homepage = %q{http://github.com/elektronaut/vector2d}
16
- s.summary = %q{Library for handling two-dimensional vectors}
17
- s.description = %q{Vector2d allows for easy handling of two-dimensionals coordinates and vectors}
11
+ s.homepage = "https://github.com/elektronaut/vector2d"
12
+ s.summary = "Library for handling two-dimensional vectors"
13
+ s.description = "Vector2d allows for easy handling of two-dimensional " \
14
+ "coordinates and vectors"
18
15
  s.license = "MIT"
19
16
 
20
17
  s.files = `git ls-files`.split("\n")
21
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = `git ls-files -- bin/*`
19
+ .split("\n")
20
+ .map { |f| File.basename(f) }
23
21
  s.require_paths = ["lib"]
24
22
 
25
- s.required_ruby_version = '>= 1.9.2'
23
+ s.required_ruby_version = ">= 3.2.0"
26
24
 
27
- # specify any dependencies here; for example:
28
- s.add_development_dependency "rake", "~> 10.3"
29
- s.add_development_dependency "rspec", "~> 3.2"
30
- s.add_dependency "contracts", "~> 0.9.0"
25
+ s.metadata = {
26
+ "bug_tracker_uri" => "https://github.com/elektronaut/vector2d/issues",
27
+ "documentation_uri" => "https://www.rubydoc.info/gems/vector2d",
28
+ "rubygems_mfa_required" => "true",
29
+ "source_code_uri" => "https://github.com/elektronaut/vector2d"
30
+ }
31
31
  end
metadata CHANGED
@@ -1,58 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector2d
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '10.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '10.3'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.2'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.2'
41
- - !ruby/object:Gem::Dependency
42
- name: contracts
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.9.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.9.0
55
- description: Vector2d allows for easy handling of two-dimensionals coordinates and
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Vector2d allows for easy handling of two-dimensional coordinates and
56
13
  vectors
57
14
  email:
58
15
  - inge@elektronaut.no
@@ -60,8 +17,16 @@ executables: []
60
17
  extensions: []
61
18
  extra_rdoc_files: []
62
19
  files:
20
+ - ".github/dependabot.yml"
21
+ - ".github/workflows/build.yml"
63
22
  - ".gitignore"
23
+ - ".release-please-manifest.json"
24
+ - ".rubocop.yml"
25
+ - ".tool-versions"
64
26
  - ".travis.yml"
27
+ - CHANGELOG.md
28
+ - CODE_OF_CONDUCT.md
29
+ - CONTRIBUTING.md
65
30
  - Gemfile
66
31
  - Gemfile.lock
67
32
  - LICENSE
@@ -74,6 +39,7 @@ files:
74
39
  - lib/vector2d/properties.rb
75
40
  - lib/vector2d/transformations.rb
76
41
  - lib/vector2d/version.rb
42
+ - release-please-config.json
77
43
  - spec/lib/vector2d/calculations_spec.rb
78
44
  - spec/lib/vector2d/coercions_spec.rb
79
45
  - spec/lib/vector2d/fitting_spec.rb
@@ -82,11 +48,14 @@ files:
82
48
  - spec/lib/vector2d_spec.rb
83
49
  - spec/spec_helper.rb
84
50
  - vector2d.gemspec
85
- homepage: http://github.com/elektronaut/vector2d
51
+ homepage: https://github.com/elektronaut/vector2d
86
52
  licenses:
87
53
  - MIT
88
- metadata: {}
89
- post_install_message:
54
+ metadata:
55
+ bug_tracker_uri: https://github.com/elektronaut/vector2d/issues
56
+ documentation_uri: https://www.rubydoc.info/gems/vector2d
57
+ rubygems_mfa_required: 'true'
58
+ source_code_uri: https://github.com/elektronaut/vector2d
90
59
  rdoc_options: []
91
60
  require_paths:
92
61
  - lib
@@ -94,23 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
63
  requirements:
95
64
  - - ">="
96
65
  - !ruby/object:Gem::Version
97
- version: 1.9.2
66
+ version: 3.2.0
98
67
  required_rubygems_version: !ruby/object:Gem::Requirement
99
68
  requirements:
100
69
  - - ">="
101
70
  - !ruby/object:Gem::Version
102
71
  version: '0'
103
72
  requirements: []
104
- rubyforge_project:
105
- rubygems_version: 2.4.5
106
- signing_key:
73
+ rubygems_version: 4.0.16
107
74
  specification_version: 4
108
75
  summary: Library for handling two-dimensional vectors
109
- test_files:
110
- - spec/lib/vector2d/calculations_spec.rb
111
- - spec/lib/vector2d/coercions_spec.rb
112
- - spec/lib/vector2d/fitting_spec.rb
113
- - spec/lib/vector2d/properties_spec.rb
114
- - spec/lib/vector2d/transformations_spec.rb
115
- - spec/lib/vector2d_spec.rb
116
- - spec/spec_helper.rb
76
+ test_files: []