ocean-names 0.4.4 → 0.4.5
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/ocean/names.rb +3 -1
- data/lib/ocean/names/polygon.rb +11 -11
- data/lib/ocean/names/version.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94e15fe50e72695853517f53d0cde86a54a804d3fceb6ff3a96e5d0c4331b75c
|
4
|
+
data.tar.gz: cee05132e42793429052b8b59a4bc7888283d8d96d47c14f8b2802e9eae010a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b7eb7b541194d980917ec66334fefad6f911fa39719481a8b589670992ddb05d003cbfe222e4252f737a6d4e76fb37bd8c1b4fbb178f5500315cb88884f5eb
|
7
|
+
data.tar.gz: 6bbd725216813df318fad41e2a5f9f12e4a568b0908fc43229f2da1627736f6a12a05774ef256e4638fd5ff8df860a96c389a3e1ca3ccbf1c24f55644c8f2c2d
|
data/Gemfile.lock
CHANGED
data/lib/ocean/names.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "ocean/names/version"
|
2
4
|
require "ocean/names/polygon"
|
3
5
|
require "oj"
|
@@ -24,7 +26,7 @@ module Ocean
|
|
24
26
|
def self.reverse_geocode(lat:, lng:)
|
25
27
|
rec = data.find do |record|
|
26
28
|
# avoid check of obviously false geometries
|
27
|
-
next unless WITHIN_BOUNDS.(record,
|
29
|
+
next unless WITHIN_BOUNDS.(record, lng, lat)
|
28
30
|
|
29
31
|
# get points from nested arrays
|
30
32
|
points = GET_POINTS.(record["geometry"])
|
data/lib/ocean/names/polygon.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ocean
|
2
4
|
module Names
|
3
5
|
class Polygon
|
4
|
-
attr_accessor :points
|
5
|
-
|
6
6
|
def initialize(points)
|
7
7
|
@points = points
|
8
8
|
@points << points[0] if points[0] != points[-1]
|
9
9
|
end
|
10
10
|
|
11
11
|
def contains?(lat:, lng:)
|
12
|
-
last_point = points[-1]
|
12
|
+
last_point = @points[-1]
|
13
13
|
|
14
14
|
odd_node = false
|
15
15
|
|
16
16
|
x = lng
|
17
17
|
y = lat
|
18
18
|
|
19
|
-
points.each do |p|
|
20
|
-
# p = [
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
@points.each do |p|
|
20
|
+
# p = [lng, lat]
|
21
|
+
x1 = p.first
|
22
|
+
y1 = p.last
|
23
|
+
x2 = last_point.first
|
24
|
+
y2 = last_point.last
|
25
25
|
|
26
|
-
if
|
27
|
-
odd_node = !odd_node if
|
26
|
+
if x1 < x && x2 >= x || x2 < x && x1 >= x
|
27
|
+
odd_node = !odd_node if y1 + (x - x1) / (x2 - x1) * (y2 - y1) < y
|
28
28
|
end
|
29
29
|
|
30
30
|
last_point = p
|
data/lib/ocean/names/version.rb
CHANGED