gps_tools 0.1.0 → 0.1.1

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
2
  SHA256:
3
- metadata.gz: f34883d049d7636e5425c8e21baa8b2d3db4329cbc5e0e19e5a68fdae380b2ee
4
- data.tar.gz: e1bfa8b3b062c361c6137231262003e368d4b33a5855a7faa48217bcc5d6bb86
3
+ metadata.gz: ab1aed7260c6af3b0c702d324ac9f5f2b1def10dca3c0b1f9e8365e575360a8b
4
+ data.tar.gz: 3b0fd3d99b8a363afddcf289f6b2b1bd8f3a8396271c176060c37d043400f879
5
5
  SHA512:
6
- metadata.gz: db5312a54634fd9acea85c51f20789f463dcf952dc4e22d4cc4a249699866d84107abad20cb359b0d770aed11bf4841105faaf8cf39c757aabbc9293287ba201
7
- data.tar.gz: f8d2e305358eeffd2acd3e1530ac2c9a0bde6f0a07d2dac3309bcdc24b1e00bd0c672708352d243c1374a576e7092291b205899cd54aa4f5ea5d59c38df9b4b6
6
+ metadata.gz: 11813f0d7162599d79b9a304a26844560f5becd4959ad4ffc4ff5f443102636f7ade3eaa0cac716220858707582e44a6ec0d3ea60ac53edaaf0fe728d82d089b
7
+ data.tar.gz: ec6395e448fd121fa1ada673c678a814663feacc2f215c140f950fb7df37f53b67310698913064e7945c90a1eab2366750c66ae8c50df19b3f6ccd7e0ee88f77
data/lib/gps_tools.rb CHANGED
@@ -1,13 +1,11 @@
1
- require 'gps_tools/distance'
2
- require 'gps_tools/geometry'
3
-
4
1
  class GPSTools
5
2
  ##
6
3
  # Returns the distance in miles (unit = "mile"), kilometers (unit = "km"), or nautical miles (unit = "nm")
7
4
  # between two gps coordinates, coord1 and coord2
8
5
  def self.distance(coord1, coord2, unit = "mile")
9
6
  distance_tool = Distance.new(unit)
10
- return distance_tool.get_distance(coord1[0], coord1[1], coord2[0], coord2[1])
7
+ distance = distance_tool.get_distance(coord1[0], coord1[1], coord2[0], coord2[1])
8
+ return distance
11
9
  end
12
10
 
13
11
  ##
@@ -17,4 +15,29 @@ class GPSTools
17
15
  geometry = Geometry.new()
18
16
  return geometry.in_polygon?(polygon, coord)
19
17
  end
20
- end
18
+
19
+ ##
20
+ # Returns a new array containing all coordinates within the given polygon
21
+ def self.filter_by_polygon(polygon, coords)
22
+ geometry = Geometry.new()
23
+ return geometry.filter_by_polygon(polygon, coords)
24
+ end
25
+
26
+ ##
27
+ # Returns a boolean that identifies if a given gps coordinate, coord, is within
28
+ # a given radius of a center point, center
29
+ def self.in_radius?(radius, center, coord)
30
+ geometry = Geometry.new()
31
+ return geometry.in_radius?(radius, center, coord)
32
+ end
33
+
34
+ ##
35
+ # Returns a new array containing all coordinates within the given radius
36
+ def self.filter_by_radius(radius, center, coords)
37
+ geometry = Geometery.new()
38
+ return geometry.filter_by_radius(radius, center, coords)
39
+ end
40
+ end
41
+
42
+ require 'gps_tools/distance'
43
+ require 'gps_tools/geometry'
@@ -1,4 +1,4 @@
1
- class Distance
1
+ class GPSTools::Distance
2
2
  def initialize(unit = "mile")
3
3
  @unit = unit
4
4
  case @unit
@@ -11,6 +11,9 @@ class Distance
11
11
  end
12
12
  end
13
13
 
14
+ ##
15
+ # Returns the distance in miles (unit = "mile"), kilometers (unit = "km"), or nautical miles (unit = "nm")
16
+ # between two gps coordinates, coord1 and coord2
14
17
  def get_distance(coord1, coord2)
15
18
  lat1 = coord1[0]
16
19
  long1 = coord1[1]
@@ -23,7 +26,8 @@ class Distance
23
26
  a = Math.sin(degrees_to_radians(lat_diff)/2) * Math.sin(degrees_to_radians(lat_diff)/2) + Math.sin(degrees_to_radians(long_diff)/2) * Math.sin(degrees_to_radians(long_diff)/2) * Math.cos(degrees_to_radians(lat1)) * Math.cos(degrees_to_radians(lat2))
24
27
  c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
25
28
 
26
- return @earth_radius * c
29
+ distance = @earth_radius * c
30
+ return distance
27
31
  end
28
32
 
29
33
  private
@@ -1,9 +1,7 @@
1
- class Geometry
2
- def in_radius?(radius, center, coord)
3
- distance = Distance.new.get_distance(center, coord)
4
- distance <= radius
5
- end
6
-
1
+ class GPSTools::Geometry
2
+ ##
3
+ # Returns a boolean that identifies if a given gps coordinate, coord, is within
4
+ # a given polygon (array of [lat, lng])
7
5
  def in_polygon?(polygon, coord)
8
6
  n = polygon.length
9
7
 
@@ -41,6 +39,26 @@ class Geometry
41
39
  intersections % 2 == 1
42
40
  end
43
41
 
42
+ ##
43
+ # Returns a new array containing all coordinates within the given polygon
44
+ def filter_by_polygon(polygon, coords)
45
+ coords.select { |coord| in_polygon?(polygon, coord) }
46
+ end
47
+
48
+ ##
49
+ # Returns a boolean that identifies if a given gps coordinate, coord, is within
50
+ # a given radius of a center point, center
51
+ def in_radius?(radius, center, coord)
52
+ distance = GPSTools::Distance.new.get_distance(center, coord)
53
+ distance <= radius
54
+ end
55
+
56
+ ##
57
+ # Returns a new array containing all coordinates within the given radius
58
+ def filter_by_radius(radius, center, coords)
59
+ coords.select{ |coord| in_radius?(radius, center, coord) }
60
+ end
61
+
44
62
  private
45
63
  def max(a, b)
46
64
  a > b ? a : b
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gps_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Van Fleet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-04 00:00:00.000000000 Z
11
+ date: 2021-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -39,14 +39,7 @@ licenses:
39
39
  - MIT
40
40
  metadata: {}
41
41
  post_install_message:
42
- rdoc_options:
43
- - "-m"
44
- - README.rdoc
45
- - "-x"
46
- - lib/(?!gps_tools.rb).*
47
- - lib/gps_tools.rb
48
- - LICENSE
49
- - README.rdoc
42
+ rdoc_options: []
50
43
  require_paths:
51
44
  - lib
52
45
  required_ruby_version: !ruby/object:Gem::Requirement