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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7dbfd81a3fed2f7614e10055078fdbdd37755693
4
- data.tar.gz: e3e0f41142cba937a0eba3a16b94a33ebd8d3a7e
2
+ SHA256:
3
+ metadata.gz: 6f3b7e7c1ae4279b24950e17dab944782608209e7dbdc061a2382d840a34ff59
4
+ data.tar.gz: 767737d5b485094560139148118512c9f7bd5e777f804b1d724f552212ccb485
5
5
  SHA512:
6
- metadata.gz: 526d578d2c1ca5b1c47c7e5552b0fd7493188ac58bf80a21768d5c2e0ce42baab3bbbd22e256c16561f30546c8cdf3aa46426857713da6494c27809171e3cedb
7
- data.tar.gz: 5a139955b82cee23628966909c1dd8d12e46e7e8bafc539c48c9339e57fddc43bdf1712345f1576b5998a103a44df4fc1b220ace19b1b96cf8498b18ff776a87
6
+ metadata.gz: a29a8e2e16357b5b0fea79db807c604502a6c097a835071776d15369f82ec2650b31722f2e7d9f25b38b4c929a3356f9fe5ad05236b825303bccfad724f524eb
7
+ data.tar.gz: 56c976aa96b172db1a72fea707bd8ac5c7d103c8a25e970483e4d1298e0a4675965c381c5420e018edeaf9255d70e61bd41fa663e6f508ad163b385f29df0e68
@@ -0,0 +1,39 @@
1
+ ---
2
+ version: 2
3
+
4
+ updates:
5
+ - package-ecosystem: "bundler"
6
+ directory: "/"
7
+ schedule:
8
+ interval: "weekly"
9
+ day: "tuesday"
10
+ time: "06:00"
11
+ timezone: "Europe/Oslo"
12
+ cooldown:
13
+ default-days: 3
14
+ semver-major-days: 7
15
+ semver-minor-days: 5
16
+ semver-patch-days: 3
17
+ groups:
18
+ all-dependencies:
19
+ patterns:
20
+ - "*"
21
+ open-pull-requests-limit: 5
22
+
23
+ - package-ecosystem: "github-actions"
24
+ directory: "/"
25
+ schedule:
26
+ interval: "weekly"
27
+ day: "tuesday"
28
+ time: "05:30"
29
+ timezone: "Europe/Oslo"
30
+ cooldown:
31
+ default-days: 3
32
+ ignore:
33
+ - dependency-name: "*"
34
+ update-types: ["version-update:semver-major"]
35
+ groups:
36
+ all-dependencies:
37
+ patterns:
38
+ - "*"
39
+ open-pull-requests-limit: 5
@@ -0,0 +1,79 @@
1
+ ---
2
+ name: Build
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - develop
8
+ pull_request:
9
+ permissions:
10
+ contents: write
11
+ issues: write
12
+ pull-requests: write
13
+ id-token: write
14
+ jobs:
15
+ rubocop-test:
16
+ name: Rubocop
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v6.1.0
20
+ - uses: ruby/setup-ruby@v1.321.0
21
+ with:
22
+ ruby-version: "4.0"
23
+ bundler-cache: true
24
+ - name: Check code
25
+ run: bundle exec rubocop
26
+
27
+ rspec-test:
28
+ name: RSpec
29
+ runs-on: ubuntu-latest
30
+ strategy:
31
+ matrix:
32
+ ruby: ["3.3", "3.4", "4.0"]
33
+ steps:
34
+ - uses: actions/checkout@v6.1.0
35
+ - uses: ruby/setup-ruby@v1.321.0
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ bundler-cache: true
39
+ - name: Run tests
40
+ run: bundle exec rspec
41
+
42
+ automerge:
43
+ name: "Auto-merge Dependabot"
44
+ needs: [rubocop-test, rspec-test]
45
+ if: github.actor == 'dependabot[bot]'
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - name: Enable auto-merge
49
+ run: gh pr merge --auto --squash "$PR_URL"
50
+ env:
51
+ PR_URL: ${{ github.event.pull_request.html_url }}
52
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53
+
54
+ release-please:
55
+ needs: [rubocop-test, rspec-test]
56
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
57
+ runs-on: ubuntu-latest
58
+ outputs:
59
+ release_created: ${{ steps.release.outputs.release_created }}
60
+ tag_name: ${{ steps.release.outputs.tag_name }}
61
+ steps:
62
+ - uses: googleapis/release-please-action@v4
63
+ id: release
64
+ with:
65
+ token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
66
+
67
+ publish:
68
+ needs: release-please
69
+ if: ${{ needs.release-please.outputs.release_created }}
70
+ runs-on: ubuntu-latest
71
+ steps:
72
+ - uses: actions/checkout@v6.1.0
73
+ with:
74
+ ref: ${{ needs.release-please.outputs.tag_name }}
75
+ - uses: ruby/setup-ruby@v1.321.0
76
+ with:
77
+ ruby-version: "4.0"
78
+ bundler-cache: true
79
+ - uses: rubygems/release-gem@v1
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
+ coverage
1
2
  rdoc
2
3
  pkg
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "2.3.0"
3
+ }
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ plugins:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.2
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "*.gemspec"
18
+ - "**/*_spec.rb"
19
+
20
+ Naming/MethodName:
21
+ Enabled: false
22
+
23
+ Naming/MethodParameterName:
24
+ AllowedNames:
25
+ - "x"
26
+ - "y"
27
+
28
+ RSpec/IndexedLet:
29
+ Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 4.0
data/.travis.yml CHANGED
@@ -1,11 +1,10 @@
1
- addons:
2
- code_climate:
3
- repo_token: bf65d5faaf8dc80d0d58f2e7c663323734237c0a3e91cba16b1c556a98b0971e
4
1
  language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+ dist: bionic
5
5
  rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1.2
9
- - 2.2.2
6
+ - 2.4.5
7
+ - 2.6.3
8
+ - 2.7.1
10
9
  script:
11
10
  - bundle exec rspec spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## [2.3.0](https://github.com/elektronaut/vector2d/compare/vector2d-v2.2.4...vector2d/v2.3.0) (2026-08-30)
4
+
5
+
6
+ ### Features
7
+
8
+ * Add Vector2d#clamp ([de77e58](https://github.com/elektronaut/vector2d/commit/de77e584f8f5668f24186179b720b4db9a70f6d2))
@@ -0,0 +1,92 @@
1
+
2
+ # Contributor Covenant 3.0 Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We pledge to make our community welcoming, safe, and equitable for all.
7
+
8
+ We are committed to fostering an environment that respects and promotes the dignity, rights, and contributions of all individuals, regardless of characteristics including race, ethnicity, caste, color, age, physical characteristics, neurodiversity, disability, sex or gender, gender identity or expression, sexual orientation, language, philosophy or religion, national or social origin, socio-economic position, level of education, or other status. The same privileges of participation are extended to everyone who participates in good faith and in accordance with this Covenant.
9
+
10
+ ## Encouraged Behaviors
11
+
12
+ While acknowledging differences in social norms, we all strive to meet our community's expectations for positive behavior. We also understand that our words and actions may be interpreted differently than we intend based on culture, background, or native language.
13
+
14
+ With these considerations in mind, we agree to behave mindfully toward each other and act in ways that center our shared values, including:
15
+
16
+ 1. Respecting the **purpose of our community**, our activities, and our ways of gathering.
17
+ 2. Engaging **kindly and honestly** with others.
18
+ 3. Respecting **different viewpoints** and experiences.
19
+ 4. **Taking responsibility** for our actions and contributions.
20
+ 5. Gracefully giving and accepting **constructive feedback**.
21
+ 6. Committing to **repairing harm** when it occurs.
22
+ 7. Behaving in other ways that promote and sustain the **well-being of our community**.
23
+
24
+
25
+ ## Restricted Behaviors
26
+
27
+ We agree to restrict the following behaviors in our community. Instances, threats, and promotion of these behaviors are violations of this Code of Conduct.
28
+
29
+ 1. **Harassment.** Violating explicitly expressed boundaries or engaging in unnecessary personal attention after any clear request to stop.
30
+ 2. **Character attacks.** Making insulting, demeaning, or pejorative comments directed at a community member or group of people.
31
+ 3. **Stereotyping or discrimination.** Characterizing anyone’s personality or behavior on the basis of immutable identities or traits.
32
+ 4. **Sexualization.** Behaving in a way that would generally be considered inappropriately intimate in the context or purpose of the community.
33
+ 5. **Violating confidentiality**. Sharing or acting on someone's personal or private information without their permission.
34
+ 6. **Endangerment.** Causing, encouraging, or threatening violence or other harm toward any person or group.
35
+ 7. Behaving in other ways that **threaten the well-being** of our community.
36
+
37
+ ### Other Restrictions
38
+
39
+ 1. **Misleading identity.** Impersonating someone else for any reason, or pretending to be someone else to evade enforcement actions.
40
+ 2. **Failing to credit sources.** Not properly crediting the sources of content you contribute.
41
+ 3. **Promotional materials**. Sharing marketing or other commercial content in a way that is outside the norms of the community.
42
+ 4. **Irresponsible communication.** Failing to responsibly present content which includes, links or describes any other restricted behaviors.
43
+
44
+
45
+ ## Reporting an Issue
46
+
47
+ Tensions can occur between community members even when they are trying their best to collaborate. Not every conflict represents a code of conduct violation, and this Code of Conduct reinforces encouraged behaviors and norms that can help avoid conflicts and minimize harm.
48
+
49
+ When an incident does occur, it is important to report it promptly. To report a possible violation, **contact the project maintainer at inge@elektronaut.no.**
50
+
51
+ Community Moderators take reports of violations seriously and will make every effort to respond in a timely manner. They will investigate all reports of code of conduct violations, reviewing messages, logs, and recordings, or interviewing witnesses and other participants. Community Moderators will keep investigation and enforcement actions as transparent as possible while prioritizing safety and confidentiality. In order to honor these values, enforcement actions are carried out in private with the involved parties, but communicating to the whole community may be part of a mutually agreed upon resolution.
52
+
53
+
54
+ ## Addressing and Repairing Harm
55
+
56
+ ****
57
+
58
+ If an investigation by the Community Moderators finds that this Code of Conduct has been violated, the following enforcement ladder may be used to determine how best to repair harm, based on the incident's impact on the individuals involved and the community as a whole. Depending on the severity of a violation, lower rungs on the ladder may be skipped.
59
+
60
+ 1) Warning
61
+ 1) Event: A violation involving a single incident or series of incidents.
62
+ 2) Consequence: A private, written warning from the Community Moderators.
63
+ 3) Repair: Examples of repair include a private written apology, acknowledgement of responsibility, and seeking clarification on expectations.
64
+ 2) Temporarily Limited Activities
65
+ 1) Event: A repeated incidence of a violation that previously resulted in a warning, or the first incidence of a more serious violation.
66
+ 2) Consequence: A private, written warning with a time-limited cooldown period designed to underscore the seriousness of the situation and give the community members involved time to process the incident. The cooldown period may be limited to particular communication channels or interactions with particular community members.
67
+ 3) Repair: Examples of repair may include making an apology, using the cooldown period to reflect on actions and impact, and being thoughtful about re-entering community spaces after the period is over.
68
+ 3) Temporary Suspension
69
+ 1) Event: A pattern of repeated violation which the Community Moderators have tried to address with warnings, or a single serious violation.
70
+ 2) Consequence: A private written warning with conditions for return from suspension. In general, temporary suspensions give the person being suspended time to reflect upon their behavior and possible corrective actions.
71
+ 3) Repair: Examples of repair include respecting the spirit of the suspension, meeting the specified conditions for return, and being thoughtful about how to reintegrate with the community when the suspension is lifted.
72
+ 4) Permanent Ban
73
+ 1) Event: A pattern of repeated code of conduct violations that other steps on the ladder have failed to resolve, or a violation so serious that the Community Moderators determine there is no way to keep the community safe with this person as a member.
74
+ 2) Consequence: Access to all community spaces, tools, and communication channels is removed. In general, permanent bans should be rarely used, should have strong reasoning behind them, and should only be resorted to if working through other remedies has failed to change the behavior.
75
+ 3) Repair: There is no possible repair in cases of this severity.
76
+
77
+ This enforcement ladder is intended as a guideline. It does not limit the ability of Community Managers to use their discretion and judgment, in keeping with the best interests of our community.
78
+
79
+
80
+ ## Scope
81
+
82
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public or other spaces. Examples of representing our community include using an official email address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
83
+
84
+
85
+ ## Attribution
86
+
87
+ This Code of Conduct is adapted from the Contributor Covenant, version 3.0, permanently available at [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
88
+
89
+ Contributor Covenant is stewarded by the Organization for Ethical Source and licensed under CC BY-SA 4.0. To view a copy of this license, visit [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
90
+
91
+ For answers to common questions about Contributor Covenant, see the FAQ at [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are provided at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). Additional enforcement and community guideline resources can be found at [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources). The enforcement ladder was inspired by the work of [Mozilla’s code of conduct team](https://github.com/mozilla/inclusion).
92
+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,30 @@
1
+ # Contributing
2
+
3
+ Bug reports and pull requests are welcome on
4
+ [GitHub](https://github.com/elektronaut/vector2d). Everyone participating is
5
+ expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
6
+
7
+ ## Getting started
8
+
9
+ Install the dependencies and run the test suite:
10
+
11
+ ```sh
12
+ bundle install
13
+ bundle exec rspec
14
+ ```
15
+
16
+ Check style before pushing:
17
+
18
+ ```sh
19
+ bundle exec rubocop
20
+ ```
21
+
22
+ ## Pull requests
23
+
24
+ - Add tests for any behavior you change.
25
+ - Write commit messages using
26
+ [Conventional Commits](https://www.conventionalcommits.org). The
27
+ changelog and releases are generated from them, so the `feat:` and
28
+ `fix:` prefixes decide what ends up in the next release.
29
+ - Leave the version and the changelog alone. Both are updated
30
+ automatically when a release is cut.
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  gemspec
4
6
 
5
- group :test do
6
- gem "codeclimate-test-reporter", require: false
7
- end
7
+ group :development, :test do
8
+ gem "rake"
9
+ gem "rspec", "~> 3.8"
10
+ gem "rspec-its", "~> 2.0"
11
+ gem "rubocop", require: false
12
+ gem "rubocop-rake", require: false
13
+ gem "rubocop-rspec", require: false
14
+ gem "simplecov", "~> 1.1.1"
15
+ end
data/Gemfile.lock CHANGED
@@ -1,43 +1,81 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vector2d (2.2.3)
5
- contracts (~> 0.9.0)
4
+ vector2d (2.3.0)
6
5
 
7
6
  GEM
8
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
9
8
  specs:
10
- codeclimate-test-reporter (0.4.7)
11
- simplecov (>= 0.7.1, < 1.0.0)
12
- contracts (0.9)
13
- diff-lcs (1.2.5)
14
- docile (1.1.5)
15
- json (1.8.3)
16
- rake (10.4.2)
17
- rspec (3.3.0)
18
- rspec-core (~> 3.3.0)
19
- rspec-expectations (~> 3.3.0)
20
- rspec-mocks (~> 3.3.0)
21
- rspec-core (3.3.2)
22
- rspec-support (~> 3.3.0)
23
- rspec-expectations (3.3.1)
9
+ ast (2.4.3)
10
+ diff-lcs (1.6.2)
11
+ json (2.21.2)
12
+ language_server-protocol (3.17.0.6)
13
+ lint_roller (1.1.0)
14
+ parallel (1.28.0)
15
+ parser (3.3.12.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ prism (1.9.0)
19
+ racc (1.8.1)
20
+ rainbow (3.1.1)
21
+ rake (13.4.2)
22
+ regexp_parser (2.12.0)
23
+ rspec (3.13.2)
24
+ rspec-core (~> 3.13.0)
25
+ rspec-expectations (~> 3.13.0)
26
+ rspec-mocks (~> 3.13.0)
27
+ rspec-core (3.13.6)
28
+ rspec-support (~> 3.13.0)
29
+ rspec-expectations (3.13.5)
24
30
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.3.0)
26
- rspec-mocks (3.3.2)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-its (2.0.0)
33
+ rspec-core (>= 3.13.0)
34
+ rspec-expectations (>= 3.13.0)
35
+ rspec-mocks (3.13.7)
27
36
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.3.0)
29
- rspec-support (3.3.0)
30
- simplecov (0.10.0)
31
- docile (~> 1.1.0)
32
- json (~> 1.8)
33
- simplecov-html (~> 0.10.0)
34
- simplecov-html (0.10.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-support (3.13.7)
39
+ rubocop (1.89.0)
40
+ json (~> 2.3)
41
+ language_server-protocol (~> 3.17.0.2)
42
+ lint_roller (~> 1.1.0)
43
+ parallel (>= 1.10)
44
+ parser (>= 3.3.0.2)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 2.9.3, < 3.0)
47
+ rubocop-ast (>= 1.49.0, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 2.4.0, < 4.0)
50
+ rubocop-ast (1.50.0)
51
+ parser (>= 3.3.7.2)
52
+ prism (~> 1.7)
53
+ rubocop-rake (0.7.1)
54
+ lint_roller (~> 1.1)
55
+ rubocop (>= 1.72.1)
56
+ rubocop-rspec (3.10.2)
57
+ lint_roller (~> 1.1)
58
+ regexp_parser (>= 2.0)
59
+ rubocop (~> 1.86, >= 1.86.2)
60
+ ruby-progressbar (1.13.0)
61
+ simplecov (1.1.1)
62
+ unicode-display_width (3.2.0)
63
+ unicode-emoji (~> 4.1)
64
+ unicode-emoji (4.2.0)
35
65
 
36
66
  PLATFORMS
67
+ arm64-darwin-23
37
68
  ruby
38
69
 
39
70
  DEPENDENCIES
40
- codeclimate-test-reporter
41
- rake (~> 10.3)
42
- rspec (~> 3.2)
71
+ rake
72
+ rspec (~> 3.8)
73
+ rspec-its (~> 2.0)
74
+ rubocop
75
+ rubocop-rake
76
+ rubocop-rspec
77
+ simplecov (~> 1.1.1)
43
78
  vector2d!
79
+
80
+ BUNDLED WITH
81
+ 4.0.4
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # Vector2d [![Build Status](https://travis-ci.org/elektronaut/vector2d.png)](https://travis-ci.org/elektronaut/vector2d) [![Code Climate](https://codeclimate.com/github/elektronaut/vector2d.png)](https://codeclimate.com/github/elektronaut/vector2d) [![Code Climate](https://codeclimate.com/github/elektronaut/vector2d/coverage.png)](https://codeclimate.com/github/elektronaut/vector2d)
1
+ [![Version](https://img.shields.io/gem/v/vector2d.svg?style=flat)](https://rubygems.org/gems/vector2d)
2
+ [![Build](https://github.com/elektronaut/vector2d/actions/workflows/build.yml/badge.svg)](https://github.com/elektronaut/vector2d/actions/workflows/build.yml)
3
+
4
+ # Vector2d
2
5
 
3
6
  Vector2d handles two-dimensional coordinates and vectors.
4
7
  Vectors are immutable, meaning this is a purely functional library.
@@ -24,10 +27,16 @@ Vector2d.parse("50x70") # => Vector2d(50,70)
24
27
 
25
28
  ## Documentation
26
29
 
27
- [API documentation](http://rdoc.info/github/elektronaut/vector2d)
30
+ [API documentation](https://rubydoc.info/gems/vector2d)
28
31
 
29
- ## License
32
+ ## Contributing
30
33
 
31
- Copyright (c) 2006-2014 Inge Jørgensen
34
+ Bug reports and pull requests are welcome on
35
+ [GitHub](https://github.com/elektronaut/vector2d). See
36
+ [CONTRIBUTING.md](CONTRIBUTING.md) for how to run the tests and how
37
+ commits are formatted, and note that this project ships with a
38
+ [code of conduct](CODE_OF_CONDUCT.md).
39
+
40
+ ## License
32
41
 
33
- Vector2d is released under the [MIT License](http://www.opensource.org/licenses/MIT).
42
+ Released under the [MIT License](LICENSE).
data/Rakefile CHANGED
@@ -1,7 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
6
+ # release-please creates the tag and the release commit.
7
+ Rake::Task["release:source_control_push"].clear
8
+
4
9
  RSpec::Core::RakeTask.new
5
10
 
6
- task :default => :spec
7
- task :test => :spec
11
+ task default: :spec
12
+
13
+ desc "Run tests"
14
+ task test: :spec
@@ -1,21 +1,16 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  class Vector2d
4
4
  module Calculations
5
- include Contracts
6
-
7
5
  module ClassMethods
8
- include Contracts
9
-
10
6
  # Calculates cross product of two vectors.
11
7
  #
12
8
  # v1 = Vector2d(2, 1)
13
9
  # v2 = Vector2d(2, 3)
14
10
  # Vector2d.cross_product(v1, v2) # => 4
15
11
  #
16
- Contract Vector2d, Vector2d => Num
17
12
  def cross_product(vector1, vector2)
18
- vector1.x * vector2.y - vector1.y * vector2.x
13
+ (vector1.x * vector2.y) - (vector1.y * vector2.x)
19
14
  end
20
15
 
21
16
  # Calculates dot product of two vectors.
@@ -24,9 +19,8 @@ class Vector2d
24
19
  # v2 = Vector2d(2, 3)
25
20
  # Vector2d.dot_product(v1, v2) # => 10
26
21
  #
27
- Contract Vector2d, Vector2d => Num
28
22
  def dot_product(vector1, vector2)
29
- vector1.x * vector2.x + vector1.y * vector2.y
23
+ (vector1.x * vector2.x) + (vector1.y * vector2.y)
30
24
  end
31
25
 
32
26
  # Calculates angle between two vectors in radians.
@@ -35,11 +29,10 @@ class Vector2d
35
29
  # v2 = Vector2d(4, 5)
36
30
  # Vector2d.angle_between(v1, v2) # => 0.0867..
37
31
  #
38
- Contract Vector2d, Vector2d => Num
39
32
  def angle_between(vector1, vector2)
40
33
  one = vector1.normalized? ? vector1 : vector1.normalize
41
34
  two = vector2.normalized? ? vector2 : vector2.normalize
42
- Math.acos(self.dot_product(one, two))
35
+ Math.acos(dot_product(one, two))
43
36
  end
44
37
  end
45
38
 
@@ -48,7 +41,6 @@ class Vector2d
48
41
  # Vector2d(1, 2) * Vector2d(2, 3) # => Vector2d(2, 6)
49
42
  # Vector2d(1, 2) * 2 # => Vector2d(2, 4)
50
43
  #
51
- Contract VectorLike => Vector2d
52
44
  def *(other)
53
45
  calculate_each(:*, other)
54
46
  end
@@ -58,7 +50,6 @@ class Vector2d
58
50
  # Vector2d(4, 2) / Vector2d(2, 1) # => Vector2d(2, 2)
59
51
  # Vector2d(4, 2) / 2 # => Vector2d(2, 1)
60
52
  #
61
- Contract VectorLike => Vector2d
62
53
  def /(other)
63
54
  calculate_each(:/, other)
64
55
  end
@@ -68,7 +59,6 @@ class Vector2d
68
59
  # Vector2d(1, 2) + Vector2d(2, 3) # => Vector2d(3, 5)
69
60
  # Vector2d(1, 2) + 2 # => Vector2d(3, 4)
70
61
  #
71
- Contract VectorLike => Vector2d
72
62
  def +(other)
73
63
  calculate_each(:+, other)
74
64
  end
@@ -78,7 +68,6 @@ class Vector2d
78
68
  # Vector2d(2, 3) - Vector2d(2, 1) # => Vector2d(0, 2)
79
69
  # Vector2d(4, 3) - 1 # => Vector2d(3, 2)
80
70
  #
81
- Contract VectorLike => Vector2d
82
71
  def -(other)
83
72
  calculate_each(:-, other)
84
73
  end
@@ -89,7 +78,6 @@ class Vector2d
89
78
  # v2 = Vector2d(5, 6)
90
79
  # v1.distance(v2) # => 1.4142..
91
80
  #
92
- Contract VectorLike => Num
93
81
  def distance(other)
94
82
  Math.sqrt(squared_distance(other))
95
83
  end
@@ -100,12 +88,11 @@ class Vector2d
100
88
  # v2 = Vector2d(5, 6)
101
89
  # v1.distance_squared(v2) # => 18
102
90
  #
103
- Contract VectorLike => Num
104
91
  def squared_distance(other)
105
- v, _ = coerce(other)
92
+ v, = coerce(other)
106
93
  dx = v.x - x
107
94
  dy = v.y - y
108
- dx * dx + dy * dy
95
+ (dx * dx) + (dy * dy)
109
96
  end
110
97
 
111
98
  # Dot product of this vector and another vector.
@@ -114,9 +101,8 @@ class Vector2d
114
101
  # v2 = Vector2d(2, 3)
115
102
  # v1.dot_product(v2) # => 10
116
103
  #
117
- Contract VectorLike => Num
118
104
  def dot_product(other)
119
- v, _ = coerce(other)
105
+ v, = coerce(other)
120
106
  self.class.dot_product(self, v)
121
107
  end
122
108
 
@@ -126,9 +112,8 @@ class Vector2d
126
112
  # v2 = Vector2d(2, 3)
127
113
  # v1.cross_product(v2) # => 4
128
114
  #
129
- Contract VectorLike => Num
130
115
  def cross_product(other)
131
- v, _ = coerce(other)
116
+ v, = coerce(other)
132
117
  self.class.cross_product(self, v)
133
118
  end
134
119
 
@@ -138,16 +123,15 @@ class Vector2d
138
123
  # v2 = Vector2d(4, 5)
139
124
  # v1.angle_between(v2) # => 0.0867..
140
125
  #
141
- Contract VectorLike => Num
142
126
  def angle_between(other)
143
- v, _ = coerce(other)
127
+ v, = coerce(other)
144
128
  self.class.angle_between(self, v)
145
129
  end
146
130
 
147
131
  private
148
132
 
149
133
  def calculate_each(method, other)
150
- v, _ = coerce(other)
134
+ v, = coerce(other)
151
135
  self.class.new(
152
136
  x.send(method, v.x),
153
137
  y.send(method, v.y)