quadtree 1.0.2 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/.rubocop_todo.yml +76 -0
- data/CODE_OF_CONDUCT.md +74 -74
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +7 -2
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/quadtree.rb +9 -6
- data/lib/quadtree/axis_aligned_bounding_box.rb +91 -18
- data/lib/quadtree/point.rb +155 -60
- data/lib/quadtree/quadtree.rb +156 -50
- data/lib/quadtree/unknown_type_error.rb +8 -0
- data/lib/quadtree/version.rb +5 -1
- data/quadtree.gemspec +50 -22
- metadata +75 -22
- data/.editorconfig +0 -12
- data/.gitignore +0 -208
- data/.rspec +0 -3
- data/.travis.yml +0 -5
- data/bin/console +0 -7
- data/bin/setup +0 -8
- data/bitbucket-pipelines.yml +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cc1a164a8db13d4faf288086e402c3f640e7df3565c06fca0bcc412349e1c82
|
4
|
+
data.tar.gz: 7775b6a0a06fda4e720e8506e0bc6d5366a47097547df4ef92425d81e5d57756
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc066fdc14f81a13648370cf5f11391287c5ecca6914982c90b85491acfc74399acfbe52bff2c88a621a989624c4d2177d6743b5deb6e492ede6e9093f620c6
|
7
|
+
data.tar.gz: 87ccb5227454748c3c9a7eb9611a332976d9677023b8106b9de132e1a768b5a9cdcbdadd806cb4317585ad28e859fb7d8cb099ddb39f9e242ac9583abdaa65ba
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
4
|
+
Enabled: true
|
5
|
+
Layout/SpaceAroundMethodCallOperator:
|
6
|
+
Enabled: true
|
7
|
+
Lint/DeprecatedOpenSSLConstant:
|
8
|
+
Enabled: true
|
9
|
+
Lint/MixedRegexpCaptureTypes:
|
10
|
+
Enabled: true
|
11
|
+
Lint/RaiseException:
|
12
|
+
Enabled: true
|
13
|
+
Lint/StructNewOverride:
|
14
|
+
Enabled: true
|
15
|
+
Style/ExponentialNotation:
|
16
|
+
Enabled: true
|
17
|
+
Style/HashEachMethods:
|
18
|
+
Enabled: true
|
19
|
+
Style/HashTransformKeys:
|
20
|
+
Enabled: true
|
21
|
+
Style/HashTransformValues:
|
22
|
+
Enabled: true
|
23
|
+
Style/RedundantRegexpCharacterClass:
|
24
|
+
Enabled: true
|
25
|
+
Style/RedundantRegexpEscape:
|
26
|
+
Enabled: true
|
27
|
+
Style/SlicingWithRange:
|
28
|
+
Enabled: true
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-06-04 20:16:28 +0300 using RuboCop version 0.85.0.
|
4
|
+
|
5
|
+
# Configuration parameters: EnforcedStyle.
|
6
|
+
# SupportedStyles: native, lf, crlf
|
7
|
+
Layout/EndOfLine:
|
8
|
+
EnforcedStyle: native
|
9
|
+
|
10
|
+
# Configuration parameters: IgnoredMethods.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Enabled: true
|
13
|
+
Max: 25
|
14
|
+
Exclude:
|
15
|
+
- lib/quadtree/quadtree.rb
|
16
|
+
|
17
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
18
|
+
# ExcludedMethods: refine
|
19
|
+
Metrics/BlockLength:
|
20
|
+
CountComments: false
|
21
|
+
#Max: 47
|
22
|
+
|
23
|
+
# Configuration parameters: CountComments.
|
24
|
+
Metrics/ClassLength:
|
25
|
+
CountComments: false
|
26
|
+
Exclude:
|
27
|
+
- lib/quadtree/quadtree.rb
|
28
|
+
|
29
|
+
# Configuration parameters: IgnoredMethods.
|
30
|
+
Metrics/CyclomaticComplexity:
|
31
|
+
Enabled: true
|
32
|
+
Exclude:
|
33
|
+
- lib/quadtree/quadtree.rb
|
34
|
+
|
35
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
36
|
+
Metrics/MethodLength:
|
37
|
+
CountComments: false
|
38
|
+
Exclude:
|
39
|
+
- lib/quadtree/quadtree.rb
|
40
|
+
|
41
|
+
# Configuration parameters: CountKeywordArgs.
|
42
|
+
Metrics/ParameterLists:
|
43
|
+
Enabled: true
|
44
|
+
Exclude:
|
45
|
+
- lib/quadtree/quadtree.rb
|
46
|
+
|
47
|
+
# Configuration parameters: IgnoredMethods.
|
48
|
+
Metrics/PerceivedComplexity:
|
49
|
+
Enabled: true
|
50
|
+
Exclude:
|
51
|
+
- lib/quadtree/quadtree.rb
|
52
|
+
|
53
|
+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
54
|
+
# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp
|
55
|
+
Naming/MethodParameterName:
|
56
|
+
Enabled: true
|
57
|
+
Exclude:
|
58
|
+
- lib/quadtree/point.rb
|
59
|
+
|
60
|
+
# Configuration parameters: AllowedChars.
|
61
|
+
Style/AsciiComments:
|
62
|
+
Enabled: true
|
63
|
+
Exclude:
|
64
|
+
- lib/quadtree/point.rb
|
65
|
+
|
66
|
+
Style/Documentation:
|
67
|
+
Enabled: true
|
68
|
+
|
69
|
+
# Configuration parameters: Strict.
|
70
|
+
Style/NumericLiterals:
|
71
|
+
Enabled: true
|
72
|
+
|
73
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
74
|
+
# URISchemes: http, https
|
75
|
+
Layout/LineLength:
|
76
|
+
Enabled: true
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,74 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at jan.lindblom@mittmedia.se. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: http://contributor-covenant.org
|
74
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jan.lindblom@mittmedia.se. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
source "https://rubygems.org"
|
2
|
-
|
3
|
-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in quadtree.gemspec
|
6
|
-
gemspec
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in quadtree.gemspec
|
6
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2018 Jan Lindblom
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jan Lindblom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Quadtree
|
2
2
|
|
3
|
+
![Build Status](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoidk1aMm1Ya212SjRsU1pVdWNVZ2FRTDVPUXlVM2NsY0dWU2UxL1dEUlh2VTdxdURhcmxRK1JDTGg5OXJxeURKeFRiZXV5VEtTbmRBZCt6bTdDTms1Rm5ZPSIsIml2UGFyYW1ldGVyU3BlYyI6ImlUamttMGtUckZRT0tvM0EiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)
|
4
|
+
[![Bitbucket Pipelines](https://img.shields.io/bitbucket/pipelines/janlindblom/ruby-quadtree.png)](https://bitbucket.org/janlindblom/ruby-quadtree)
|
5
|
+
[![Gem](https://img.shields.io/gem/v/quadtree.png)](https://rubygems.org/gems/quadtree)
|
6
|
+
[![Documentation](https://img.shields.io/badge/docs-rdoc.info-yellow.png)](http://www.rubydoc.info/gems/quadtree/frames)
|
7
|
+
|
3
8
|
Quadtrees in Ruby. For searching spatially related nodes in some space, you know.
|
4
9
|
|
5
10
|
## Installation
|
@@ -47,7 +52,7 @@ qt.query_range(boundary2)
|
|
47
52
|
|
48
53
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
49
54
|
|
50
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number using `rake version:create` or `rake version:bump`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
56
|
|
52
57
|
## Contributing
|
53
58
|
|
@@ -59,4 +64,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
59
64
|
|
60
65
|
## Code of Conduct
|
61
66
|
|
62
|
-
Everyone interacting in the Quadtree project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://
|
67
|
+
Everyone interacting in the Quadtree project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://bitbucket.org/janlindblom/ruby-quadtree/src/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,13 +1,69 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "rake/version_task"
|
1
5
|
require "bundler/gem_tasks"
|
2
6
|
require "rspec/core/rake_task"
|
3
7
|
require "yard"
|
4
8
|
require "yard/rake/yardoc_task"
|
9
|
+
require 'rubocop/rake_task'
|
10
|
+
require "quadtree"
|
5
11
|
|
6
12
|
RSpec::Core::RakeTask.new(:spec)
|
7
13
|
|
14
|
+
spec = Gem::Specification.new do |s|
|
15
|
+
s.name = "quadtree"
|
16
|
+
s.version = Quadtree::VERSION
|
17
|
+
s.authors = ["Jan Lindblom"]
|
18
|
+
s.email = ["janlindblom@fastmail.fm"]
|
19
|
+
|
20
|
+
s.summary = %q{Quadtrees in Ruby.}
|
21
|
+
s.homepage = "https://bitbucket.org/janlindblom/ruby-quadtree"
|
22
|
+
s.license = "MIT"
|
23
|
+
|
24
|
+
s.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(bin|test|spec|features)/}) ||
|
26
|
+
f == ".travis.yml" ||
|
27
|
+
f == ".gitignore" ||
|
28
|
+
f == ".editorconfig" ||
|
29
|
+
f == ".rspec" ||
|
30
|
+
f == "bitbucket-pipelines.yml" ||
|
31
|
+
f == "buildspec.yml" ||
|
32
|
+
f == ".gitlab-ci.yml"
|
33
|
+
end
|
34
|
+
s.bindir = "exe"
|
35
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
|
38
|
+
s.required_ruby_version = '>= 2.3.0'
|
39
|
+
|
40
|
+
s.add_development_dependency "bundler", "~> 2"
|
41
|
+
s.add_development_dependency "rake", "~> 13.0"
|
42
|
+
s.add_development_dependency "rspec", "~> 3.9"
|
43
|
+
s.add_development_dependency "pry", "~> 0.13"
|
44
|
+
s.add_development_dependency "yard", "~> 0.9"
|
45
|
+
s.add_development_dependency "simplecov", "~> 0.18"
|
46
|
+
s.add_development_dependency "rspec_junit_formatter", "~> 0.4"
|
47
|
+
s.add_development_dependency "rubocop", "~> 0.85"
|
48
|
+
s.add_runtime_dependency "version", "~> 1.1"
|
49
|
+
end
|
50
|
+
|
51
|
+
Rake::VersionTask.new do |task|
|
52
|
+
task.with_gemspec = spec
|
53
|
+
task.with_git = false
|
54
|
+
end
|
55
|
+
|
8
56
|
YARD::Rake::YardocTask.new do |t|
|
9
57
|
t.files = ['lib/**/*.rb']
|
10
58
|
t.stats_options = ['--list-undoc']
|
11
59
|
end
|
12
60
|
|
61
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
62
|
+
task.patterns = ['lib/**/*.rb']
|
63
|
+
# only show the files with failures
|
64
|
+
task.formatters = ['worst']
|
65
|
+
# don't abort rake on failure
|
66
|
+
task.fail_on_error = false
|
67
|
+
end
|
68
|
+
|
13
69
|
task :default => :spec
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.8
|
data/lib/quadtree.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
3
|
+
require 'version'
|
4
|
+
require 'quadtree/version'
|
5
|
+
|
6
|
+
require 'quadtree/unknown_type_error'
|
7
|
+
|
8
|
+
require 'quadtree/point'
|
9
|
+
require 'quadtree/axis_aligned_bounding_box'
|
10
|
+
require 'quadtree/quadtree'
|
6
11
|
|
7
12
|
# Quadtrees.
|
8
13
|
#
|
9
|
-
# @since 1.0.0
|
10
14
|
# @author Jan Lindblom <janlindblom@fastmail.fm>
|
11
15
|
module Quadtree
|
12
|
-
|
13
16
|
end
|
@@ -1,32 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Quadtree
|
2
4
|
# Axis-aligned bounding box with half dimension and center.
|
3
5
|
class AxisAlignedBoundingBox
|
4
|
-
|
5
|
-
#
|
6
|
+
# Center {Point} of this instance.
|
7
|
+
#
|
8
|
+
# @return [Point] the {Point} marking the center of this instance.
|
6
9
|
attr_accessor :center
|
7
|
-
|
10
|
+
|
11
|
+
# Half dimension of this instance (distance from the center {Point} to the
|
12
|
+
# edge).
|
13
|
+
#
|
14
|
+
# @return [Float] distance from the center {Point} to the edge.
|
8
15
|
attr_accessor :half_dimension
|
9
16
|
|
10
|
-
# @param [Point]
|
11
|
-
# @param [Float]
|
17
|
+
# @param center [Point]
|
18
|
+
# @param half_dimension [Float]
|
12
19
|
def initialize(center, half_dimension)
|
13
20
|
@center = center
|
14
21
|
@half_dimension = half_dimension.to_f
|
15
22
|
end
|
16
23
|
|
17
|
-
#
|
18
|
-
#
|
24
|
+
#
|
25
|
+
# Create a Hash for this {AxisAlignedBoundingBox}.
|
26
|
+
#
|
27
|
+
# @return [Hash] Hash representation of this {AxisAlignedBoundingBox}.
|
28
|
+
#
|
29
|
+
def to_h
|
30
|
+
{
|
31
|
+
'center': center.to_h,
|
32
|
+
'half_dimension': half_dimension
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Create a Hash for this {AxisAlignedBoundingBox}.
|
38
|
+
#
|
39
|
+
# @return [Hash] Hash representation of this {AxisAlignedBoundingBox}.
|
40
|
+
#
|
41
|
+
def to_hash
|
42
|
+
to_h
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Create a JSON String representation of this {AxisAlignedBoundingBox}.
|
47
|
+
#
|
48
|
+
# @return [String] JSON String of this {AxisAlignedBoundingBox}.
|
49
|
+
#
|
50
|
+
def to_json(*_args)
|
51
|
+
require 'json'
|
52
|
+
to_h.to_json
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Create a String for this {AxisAlignedBoundingBox}.
|
57
|
+
#
|
58
|
+
# @return [String] String representation of this {AxisAlignedBoundingBox}.
|
59
|
+
#
|
60
|
+
def to_s
|
61
|
+
to_h.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Construct a {AxisAlignedBoundingBox} from a JSON String.
|
66
|
+
#
|
67
|
+
# @param [String] json_data input JSON String.
|
68
|
+
#
|
69
|
+
# @return [AxisAlignedBoundingBox] the {AxisAlignedBoundingBox} contained in the JSON String.
|
70
|
+
#
|
71
|
+
def self.from_json(json_data)
|
72
|
+
new(Point.from_json(json_data['center']), json_data['half_dimension'])
|
73
|
+
end
|
74
|
+
|
75
|
+
# Check if this instance contains a given {Point}.
|
76
|
+
#
|
77
|
+
# @param point [Point] the {Point} to check for.
|
78
|
+
# @return [Boolean] +true+ if given {Point} is contained, +false+
|
79
|
+
# otherwise.
|
19
80
|
def contains_point?(point)
|
20
|
-
if point.x >=
|
21
|
-
|
81
|
+
if point.x >= center.x - half_dimension &&
|
82
|
+
point.x <= center.x + half_dimension
|
83
|
+
if point.y >= center.y - half_dimension &&
|
84
|
+
point.y <= center.y + half_dimension
|
22
85
|
return true
|
23
86
|
end
|
24
87
|
end
|
25
88
|
false
|
26
89
|
end
|
27
90
|
|
28
|
-
#
|
29
|
-
#
|
91
|
+
# Check if this instance intersects with another instance.
|
92
|
+
#
|
93
|
+
# @param other [AxisAlignedBoundingBox] the other instance to check for.
|
94
|
+
# @return [Boolean] +true+ if these intersects, +false+ otherwise.
|
30
95
|
def intersects?(other)
|
31
96
|
other_lt_corner = Point.new(other.left, other.top)
|
32
97
|
other_rt_corner = Point.new(other.right, other.top)
|
@@ -34,40 +99,48 @@ module Quadtree
|
|
34
99
|
other_rb_corner = Point.new(other.right, other.bottom)
|
35
100
|
|
36
101
|
[other_lt_corner, other_rt_corner, other_lb_corner, other_rb_corner].each do |corner|
|
37
|
-
return true if
|
102
|
+
return true if contains_point?(corner)
|
38
103
|
end
|
39
104
|
false
|
40
105
|
end
|
41
106
|
|
42
|
-
#
|
107
|
+
# Get the X coordinate of the left edge of this instance.
|
108
|
+
#
|
109
|
+
# @return [Float] the X coordinate of the left edge of this instance.
|
43
110
|
def left
|
44
111
|
@center.x - @half_dimension
|
45
112
|
end
|
46
113
|
|
47
|
-
#
|
114
|
+
# Get the X coordinate of the right edge of this instance.
|
115
|
+
#
|
116
|
+
# @return [Float] the X coordinate of the right edge of this instance.
|
48
117
|
def right
|
49
118
|
@center.x + @half_dimension
|
50
119
|
end
|
51
120
|
|
52
|
-
# Get the Y coordinate of the top edge of this
|
121
|
+
# Get the Y coordinate of the top edge of this instance.
|
53
122
|
#
|
54
|
-
# @return [Float] the Y coordinate of the top edge of this
|
123
|
+
# @return [Float] the Y coordinate of the top edge of this instance.
|
55
124
|
def top
|
56
125
|
@center.y + @half_dimension
|
57
126
|
end
|
58
127
|
|
59
|
-
# Get the Y coordinate of the bottom edge of this
|
128
|
+
# Get the Y coordinate of the bottom edge of this instance.
|
60
129
|
#
|
61
|
-
# @return [Float] the Y coordinate of the bottom edge of this
|
130
|
+
# @return [Float] the Y coordinate of the bottom edge of this instance.
|
62
131
|
def bottom
|
63
132
|
@center.y - @half_dimension
|
64
133
|
end
|
65
134
|
|
135
|
+
# Get the width of this instance.
|
136
|
+
#
|
66
137
|
# @return [Float]
|
67
138
|
def width
|
68
139
|
span
|
69
140
|
end
|
70
141
|
|
142
|
+
# Get the height of this instance.
|
143
|
+
#
|
71
144
|
# @return [Float]
|
72
145
|
def height
|
73
146
|
span
|