path_compare 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 00d8183e34106b469b75c7e16fe0c2e6b4593bc0ec2e845f96b4feea5a5839d0
4
+ data.tar.gz: 38cbf8a9ffface470adce6e392456c07c98ea88af74ccb0eaa95233d701ea423
5
+ SHA512:
6
+ metadata.gz: b9a6ce95d5f2951a2c3b0f905f80bde7e7995613aa2f1b2ac72c98e122087f9a6d946177ffc74c0ad5f5ac1d04415e0c6a8138e90752618c3d7e56699cc6f069
7
+ data.tar.gz: 1360f82725174e04d53641f8fbc8247665b7df5f3bb3cdc955d1034c2ff2b29863dfc1e271901c67551eaff3d57371a91c0b05fd289f7243413346bf4c990a77
data/.gitignore ADDED
@@ -0,0 +1,131 @@
1
+
2
+ # Created by https://www.gitignore.io/api/ruby,rubymine
3
+
4
+ ### Ruby ###
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ # Used by dotenv library to load environment variables.
18
+ # .env
19
+
20
+ ## Specific to RubyMotion:
21
+ .dat*
22
+ .repl_history
23
+ build/
24
+ *.bridgesupport
25
+ build-iPhoneOS/
26
+ build-iPhoneSimulator/
27
+ .idea/*
28
+
29
+ ## Specific to RubyMotion (use of CocoaPods):
30
+ #
31
+ # We recommend against adding the Pods directory to your .gitignore. However
32
+ # you should judge for yourself, the pros and cons are mentioned at:
33
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
34
+ #
35
+ # vendor/Pods/
36
+
37
+ ## Documentation cache and generated files:
38
+ /.yardoc/
39
+ /_yardoc/
40
+ /doc/
41
+ /rdoc/
42
+
43
+ ## Environment normalization:
44
+ /.bundle/
45
+ /vendor/bundle
46
+ /lib/bundler/man/
47
+
48
+ # for a library or gem, you might want to ignore these files since the code is
49
+ # intended to run in multiple environments; otherwise, check them in:
50
+ # Gemfile.lock
51
+ # .ruby-version
52
+ # .ruby-gemset
53
+
54
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
55
+ .rvmrc
56
+
57
+ ### RubyMine ###
58
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
59
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
60
+
61
+ # User-specific stuff
62
+ .idea/**/workspace.xml
63
+ .idea/**/tasks.xml
64
+ .idea/**/usage.statistics.xml
65
+ .idea/**/dictionaries
66
+ .idea/**/shelf
67
+
68
+ # Sensitive or high-churn files
69
+ .idea/**/dataSources/
70
+ .idea/**/dataSources.ids
71
+ .idea/**/dataSources.local.xml
72
+ .idea/**/sqlDataSources.xml
73
+ .idea/**/dynamic.xml
74
+ .idea/**/uiDesigner.xml
75
+ .idea/**/dbnavigator.xml
76
+
77
+ # Gradle
78
+ .idea/**/gradle.xml
79
+ .idea/**/libraries
80
+
81
+ # Gradle and Maven with auto-import
82
+ # When using Gradle or Maven with auto-import, you should exclude module files,
83
+ # since they will be recreated, and may cause churn. Uncomment if using
84
+ # auto-import.
85
+ # .idea/modules.xml
86
+ # .idea/*.iml
87
+ # .idea/modules
88
+
89
+ # CMake
90
+ cmake-build-*/
91
+
92
+ # Mongo Explorer plugin
93
+ .idea/**/mongoSettings.xml
94
+
95
+ # File-based project format
96
+ *.iws
97
+
98
+ # IntelliJ
99
+ out/
100
+
101
+ # mpeltonen/sbt-idea plugin
102
+ .idea_modules/
103
+
104
+ # JIRA plugin
105
+ atlassian-ide-plugin.xml
106
+
107
+ # Cursive Clojure plugin
108
+ .idea/replstate.xml
109
+
110
+ # Crashlytics plugin (for Android Studio and IntelliJ)
111
+ com_crashlytics_export_strings.xml
112
+ crashlytics.properties
113
+ crashlytics-build.properties
114
+ fabric.properties
115
+
116
+ # Editor-based Rest Client
117
+ .idea/httpRequests
118
+
119
+ ### RubyMine Patch ###
120
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
121
+
122
+ # *.iml
123
+ # modules.xml
124
+ # .idea/misc.xml
125
+ # *.ipr
126
+
127
+ # Sonarlint plugin
128
+ .idea/sonarlint
129
+
130
+
131
+ # End of https://www.gitignore.io/api/ruby,rubymine
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +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 path_compare.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Luke Picciau
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 ADDED
@@ -0,0 +1,17 @@
1
+ # PathCompare
2
+
3
+ A gem that takes 2 linestring paths and returns a value comparing how similar they are.
4
+
5
+ This library is not super accurate but it should be good enough for a lot of things. Please don't use this for anything needing high accuracy results.
6
+
7
+ ## Installation
8
+
9
+ TODO
10
+
11
+ ## Usage
12
+
13
+ TODO
14
+
15
+ ## License
16
+
17
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "path_compare"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "path_compare/version"
2
+ require "path_compare/path_compare"
@@ -0,0 +1,53 @@
1
+ module PathCompare
2
+ require 'json'
3
+ # p1 and p2 given as geojson strings
4
+ def self.compare(p1, p2)
5
+ p1 = JSON.parse(p1)['coordinates'].first
6
+ p2 = JSON.parse(p2)['coordinates'].first
7
+ p1 = even_split(p1, 10)
8
+ p2 = even_split(p2, 10)
9
+
10
+ point_distances = []
11
+ p1.each_with_index do |coord, index|
12
+ unless p2.size < index + 1 #TODO: Handle different length paths
13
+ point_distances << Math.sqrt((coord[0] - p2[index][0]) ** 2) + Math.sqrt((coord[1] - p2[index][1]) ** 2)
14
+ end
15
+ end
16
+ return point_distances.sum / point_distances.size
17
+ end
18
+
19
+ # Splits a linestring in to points split_size apart. (Not quite but it should be close)
20
+ def self.even_split(coords, split_size)
21
+ new_coords = []
22
+ current_distance = 0
23
+ target_distance = split_size
24
+ last_coord = coords.first
25
+ coords.each do |coord|
26
+ if current_distance < target_distance
27
+ current_distance += distance(coord[0], coord[1], last_coord[0], last_coord[1])
28
+ else
29
+ new_coords << last_coord #TODO: Add a new point at exactly the right spot instead of using last point
30
+ target_distance += split_size
31
+ end
32
+ last_coord = coord
33
+ end
34
+ new_coords
35
+ end
36
+
37
+ RAD_PER_DEG = Math::PI / 180
38
+ EARTH_DIAMETER_KM = 6371
39
+ def self.distance(lat1, lon1, lat2, lon2)
40
+ dlon = lon2 - lon1
41
+ dlat = lat2 - lat1
42
+
43
+ a = calc(dlat, lat1, lat2, dlon)
44
+
45
+ 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a)) * EARTH_DIAMETER_KM * 1000
46
+ end
47
+ def self.deg_to_rad(num)
48
+ num * RAD_PER_DEG
49
+ end
50
+ def self.calc(dlat, lat1, lat2, dlon)
51
+ (Math.sin(deg_to_rad(dlat)/2))**2 + Math.cos(deg_to_rad(lat1)) * Math.cos((deg_to_rad(lat2))) * (Math.sin(deg_to_rad(dlon)/2))**2
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module PathCompare
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "path_compare/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "path_compare"
8
+ spec.version = PathCompare::VERSION
9
+ spec.authors = ["Luke Picciau"]
10
+ spec.email = ["luke.b.picciau@gmail.com"]
11
+
12
+ spec.summary = "Gem to compare 2 paths and return the similarity"
13
+ spec.description = "Gem to compare 2 paths and return the similarity"
14
+ spec.homepage = "https://gitlab.com/Qwertie/path_compare"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: path_compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Picciau
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Gem to compare 2 paths and return the similarity
56
+ email:
57
+ - luke.b.picciau@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".idea/inspectionProfiles/Project_Default.xml"
64
+ - ".idea/misc.xml"
65
+ - ".idea/modules.xml"
66
+ - ".idea/path_compare.iml"
67
+ - ".idea/vcs.xml"
68
+ - ".travis.yml"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/console
74
+ - bin/setup
75
+ - lib/path_compare.rb
76
+ - lib/path_compare/path_compare.rb
77
+ - lib/path_compare/version.rb
78
+ - path_compare.gemspec
79
+ homepage: https://gitlab.com/Qwertie/path_compare
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.7
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Gem to compare 2 paths and return the similarity
103
+ test_files: []