gpx 0.9.0 → 1.0.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.
@@ -2,74 +2,51 @@ require 'minitest/autorun'
2
2
  require 'gpx'
3
3
 
4
4
  class TrackFileTest < Minitest::Test
5
- TRACK_FILE = File.join(File.dirname(__FILE__), "gpx_files/tracks.gpx")
6
- OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), "gpx_files/arches.gpx")
7
-
8
- def setup
9
- @track_file = GPX::GPXFile.new(:gpx_file => TRACK_FILE)
10
- @other_track_file = GPX::GPXFile.new(:gpx_file => OTHER_TRACK_FILE)
11
- end
12
-
13
- def test_track_read
14
- assert_equal(3, @track_file.tracks.size)
15
- assert_equal("First Track", @track_file.tracks[0].name)
16
- assert_equal("Second Track", @track_file.tracks[1].name)
17
- assert_equal("Third Track", @track_file.tracks[2].name)
18
- end
19
-
20
- def test_track_segment_and_point_counts
21
- # One segment with 398 points...
22
- assert_equal(1, @track_file.tracks[0].segments.size)
23
- assert_equal(389, @track_file.tracks[0].segments.first.points.size)
24
-
25
- # One segment with 299 points...
26
- assert_equal(1, @track_file.tracks[1].segments.size)
27
- assert_equal(299, @track_file.tracks[1].segments.first.points.size)
28
-
29
- # Many segments of many different sizes
30
- segment_sizes = %w{ 2 2 5 4 2 1 197 31 54 1 15 54 19 26 109 18 9 2 8 3 10 23 21 11 25 32 66 21 2 3 3 4 6 4 4 4 3 3 6 6 27 13 2 }
31
- assert_equal(43, @track_file.tracks[2].segments.size)
32
- @track_file.tracks[2].segments.each_with_index do |seg, i|
33
- assert_equal(segment_sizes[i].to_i, seg.points.size)
34
- end
35
- last_segment = @track_file.tracks[2].segments.last
36
- assert_equal(1680.041, last_segment.points.last.elevation)
37
-
38
-
39
- second_to_last_segment = @track_file.tracks[2].segments[-2]
40
- assert_equal("2006-01-02T00:00:51Z", second_to_last_segment.points.last.time.strftime("%Y-%m-%dT%H:%M:%SZ"))
41
- assert_equal(39.998045, second_to_last_segment.points.last.lat)
42
- assert_equal(-105.292368, second_to_last_segment.points.last.lon)
43
- end
44
-
45
- def test_find_nearest_point_by_time
46
- time = Time.parse("2005-12-31T22:02:01Z")
47
- pt = @track_file.tracks[0].closest_point(time)
48
- #puts "pt: #{pt.lat_lon}"
49
-
50
- end
51
-
52
- def test_find_distance
53
- #puts "Distance: #{@other_track_file.distance(:units => 'miles')} miles"
54
- #puts "Distance: #{@track_file.distance(:units => 'miles')} miles"
55
- end
56
- def test_high_low_elevation
57
- #puts "Lowest: #{@track_file.lowest_point.elevation} m"
58
- #puts "Highest: #{@track_file.highest_point.elevation} m"
59
- end
60
-
61
- def test_duration
62
- #puts "Duration 1: #{@other_track_file.duration} "
63
- #puts "Duration 2: #{@track_file.duration} "
64
- end
65
-
66
- def test_average_speed
67
- #puts "Speed 1: #{@other_track_file.average_speed} "
68
- #puts "Speed 2: #{@track_file.average_speed} "
69
- end
70
-
71
- def test_write
72
- @other_track_file.write("tests/output/myoutput.gpx")
73
- end
74
-
5
+ TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/tracks.gpx')
6
+ OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/arches.gpx')
7
+
8
+ def setup
9
+ @track_file = GPX::GPXFile.new(gpx_file: TRACK_FILE)
10
+ @other_track_file = GPX::GPXFile.new(gpx_file: OTHER_TRACK_FILE)
11
+ end
12
+
13
+ def test_track_read
14
+ assert_equal(3, @track_file.tracks.size)
15
+ assert_equal('First Track', @track_file.tracks[0].name)
16
+ assert_equal('Second Track', @track_file.tracks[1].name)
17
+ assert_equal('Third Track', @track_file.tracks[2].name)
18
+ end
19
+
20
+ def test_track_segment_and_point_counts
21
+ # One segment with 398 points...
22
+ assert_equal(1, @track_file.tracks[0].segments.size)
23
+ assert_equal(389, @track_file.tracks[0].segments.first.points.size)
24
+
25
+ # One segment with 299 points...
26
+ assert_equal(1, @track_file.tracks[1].segments.size)
27
+ assert_equal(299, @track_file.tracks[1].segments.first.points.size)
28
+
29
+ # Many segments of many different sizes
30
+ segment_sizes = %w[2 2 5 4 2 1 197 31 54 1 15 54 19 26 109 18 9 2 8 3 10 23 21 11 25 32 66 21 2 3 3 4 6 4 4 4 3 3 6 6 27 13 2]
31
+ assert_equal(43, @track_file.tracks[2].segments.size)
32
+ @track_file.tracks[2].segments.each_with_index do |seg, i|
33
+ assert_equal(segment_sizes[i].to_i, seg.points.size)
34
+ end
35
+ last_segment = @track_file.tracks[2].segments.last
36
+ assert_equal(1680.041, last_segment.points.last.elevation)
37
+
38
+ second_to_last_segment = @track_file.tracks[2].segments[-2]
39
+ assert_equal('2006-01-02T00:00:51Z', second_to_last_segment.points.last.time.strftime('%Y-%m-%dT%H:%M:%SZ'))
40
+ assert_equal(39.998045, second_to_last_segment.points.last.lat)
41
+ assert_equal(-105.292368, second_to_last_segment.points.last.lon)
42
+ end
43
+
44
+ def test_write
45
+ output_path = 'tests/output/myoutput.gpx'
46
+ @other_track_file.write(output_path)
47
+ new_track_file = GPX::GPXFile.new(gpx_file: output_path)
48
+ orig_segments = @other_track_file.tracks.first.segments
49
+ new_segments = new_track_file.tracks.first.segments
50
+ assert_equal(orig_segments.first.points.map(&:lat_lon), new_segments.first.points.map(&:lat_lon))
51
+ end
75
52
  end
@@ -3,14 +3,18 @@ require 'gpx'
3
3
 
4
4
  class TrackPointTest < Minitest::Test
5
5
  def setup
6
- @point1 = GPX::TrackPoint.new({
7
- :lat => 37.7985474,
8
- :lon => -122.2554386
9
- })
10
- @point2 = GPX::TrackPoint.new({
11
- :lat => 37.7985583,
12
- :lon => -122.2554564
13
- })
6
+ @point1 = GPX::TrackPoint.new(
7
+ lat: 37.7985474,
8
+ lon: -122.2554386
9
+ )
10
+ @point2 = GPX::TrackPoint.new(
11
+ lat: 37.7985583,
12
+ lon: -122.2554564
13
+ )
14
+ @point3 = GPX::TrackPoint.new(
15
+ lat: 38.7985583,
16
+ lon: -121.2554564
17
+ )
14
18
  end
15
19
 
16
20
  def test_haversine_distance_from
@@ -18,13 +22,18 @@ class TrackPointTest < Minitest::Test
18
22
  assert_in_delta(0.00197862991592239, distance, 1e-18)
19
23
  end
20
24
 
21
- def test_pythagorean_distance_from
22
- distance = @point1.pythagorean_distance_from(@point2)
23
- assert_equal(3.642891416092969e-07, distance)
25
+ def test_longer_haversine_distance_from
26
+ distance = @point2.haversine_distance_from(@point3)
27
+ assert_in_delta(141.3465338444813, distance, 1e-18)
24
28
  end
25
29
 
26
30
  def test_law_of_cosines_distance_from
27
31
  distance = @point1.law_of_cosines_distance_from(@point2)
28
32
  assert_equal(0.001982307218559664, distance)
29
33
  end
34
+
35
+ def test_longer_law_of_cosines_distance_from
36
+ distance = @point2.law_of_cosines_distance_from(@point3)
37
+ assert_equal(141.3465338444991, distance)
38
+ end
30
39
  end
@@ -2,71 +2,81 @@ require 'minitest/autorun'
2
2
  require 'gpx'
3
3
 
4
4
  class TrackTest < Minitest::Test
5
- ONE_TRACK = File.join(File.dirname(__FILE__), "gpx_files/one_track.gpx")
5
+ ONE_TRACK = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
6
6
 
7
- def setup
8
- @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_TRACK)
9
- @track = @gpx_file.tracks.first
10
- end
7
+ def setup
8
+ @gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK)
9
+ @track = @gpx_file.tracks.first
10
+ end
11
11
 
12
- def test_track_read
13
- assert_equal("ACTIVE LOG", @track.name)
14
- assert_equal("Comment Log", @track.comment)
15
- assert_equal("Description Log", @track.description)
16
- assert_equal( 182, @track.points.size)
17
- assert_equal(8, @track.segments.size)
18
- assert_in_delta(3.07249668492626, @track.distance, 0.001)
19
- assert_equal(1267.155, @track.lowest_point.elevation)
20
- assert_equal(1594.003, @track.highest_point.elevation)
21
- assert_equal(38.681488, @track.bounds.min_lat)
22
- assert_equal(-109.606948, @track.bounds.min_lon)
23
- assert_equal(38.791759, @track.bounds.max_lat)
24
- assert_equal(-109.447045, @track.bounds.max_lon)
25
- assert_equal(3036.0, @track.moving_duration)
26
- end
12
+ def test_track_read
13
+ assert_equal('ACTIVE LOG', @track.name)
14
+ assert_equal('Comment Log', @track.comment)
15
+ assert_equal('Description Log', @track.description)
16
+ assert_equal(182, @track.points.size)
17
+ assert_equal(8, @track.segments.size)
18
+ assert_in_delta(3.07249668492626, @track.distance, 0.001)
19
+ assert_equal(1267.155, @track.lowest_point.elevation)
20
+ assert_equal(1594.003, @track.highest_point.elevation)
21
+ assert_equal(38.681488, @track.bounds.min_lat)
22
+ assert_equal(-109.606948, @track.bounds.min_lon)
23
+ assert_equal(38.791759, @track.bounds.max_lat)
24
+ assert_equal(-109.447045, @track.bounds.max_lon)
25
+ assert_equal(3036.0, @track.moving_duration)
26
+ end
27
27
 
28
- def test_track_crop
29
- area = GPX::Bounds.new(
30
- :min_lat => 38.710000,
31
- :min_lon => -109.600000,
32
- :max_lat => 38.791759,
33
- :max_lon => -109.450000)
34
- @track.crop(area)
35
- assert_equal("ACTIVE LOG", @track.name)
36
- assert_equal("Comment Log", @track.comment)
37
- assert_equal("Description Log", @track.description)
38
- assert_equal( 111, @track.points.size)
39
- assert_equal(4, @track.segments.size)
40
- assert_in_delta(1.62136024923607, @track.distance, 0.001)
41
- assert_equal(1557.954, @track.lowest_point.elevation)
42
- assert_equal(1582.468, @track.highest_point.elevation)
43
- assert_equal(38.782511, @track.bounds.min_lat)
44
- assert_equal(-109.599781, @track.bounds.min_lon)
45
- assert_equal(38.789527, @track.bounds.max_lat)
46
- assert_equal(-109.594996, @track.bounds.max_lon)
47
- assert_equal(1773.0, @track.moving_duration)
48
- end
28
+ def test_track_crop
29
+ area = GPX::Bounds.new(
30
+ min_lat: 38.710000,
31
+ min_lon: -109.600000,
32
+ max_lat: 38.791759,
33
+ max_lon: -109.450000
34
+ )
35
+ @track.crop(area)
36
+ assert_equal('ACTIVE LOG', @track.name)
37
+ assert_equal('Comment Log', @track.comment)
38
+ assert_equal('Description Log', @track.description)
39
+ assert_equal(111, @track.points.size)
40
+ assert_equal(4, @track.segments.size)
41
+ assert_in_delta(1.62136024923607, @track.distance, 0.001)
42
+ assert_equal(1557.954, @track.lowest_point.elevation)
43
+ assert_equal(1582.468, @track.highest_point.elevation)
44
+ assert_equal(38.782511, @track.bounds.min_lat)
45
+ assert_equal(-109.599781, @track.bounds.min_lon)
46
+ assert_equal(38.789527, @track.bounds.max_lat)
47
+ assert_equal(-109.594996, @track.bounds.max_lon)
48
+ assert_equal(1773.0, @track.moving_duration)
49
+ end
49
50
 
50
- def test_track_delete
51
- area = GPX::Bounds.new(
52
- :min_lat => 38.710000,
53
- :min_lon => -109.600000,
54
- :max_lat => 38.791759,
55
- :max_lon => -109.450000)
56
- @track.delete_area(area)
51
+ def test_track_delete
52
+ area = GPX::Bounds.new(
53
+ min_lat: 38.710000,
54
+ min_lon: -109.600000,
55
+ max_lat: 38.791759,
56
+ max_lon: -109.450000
57
+ )
58
+ @track.delete_area(area)
57
59
 
58
- assert_equal(1229.0, @track.moving_duration)
59
- #puts @track
60
- assert_equal("ACTIVE LOG", @track.name)
61
- assert_equal(71, @track.points.size)
62
- assert_equal(6, @track.segments.size)
63
- assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
64
- assert_equal(1267.155, @track.lowest_point.elevation)
65
- assert_equal(1594.003, @track.highest_point.elevation)
66
- assert_equal(38.681488, @track.bounds.min_lat)
67
- assert_equal(-109.606948, @track.bounds.min_lon)
68
- assert_equal(38.791759, @track.bounds.max_lat)
69
- assert_equal(-109.447045, @track.bounds.max_lon)
70
- end
60
+ assert_equal(1229.0, @track.moving_duration)
61
+ # puts @track
62
+ assert_equal('ACTIVE LOG', @track.name)
63
+ assert_equal(71, @track.points.size)
64
+ assert_equal(6, @track.segments.size)
65
+ assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
66
+ assert_equal(1267.155, @track.lowest_point.elevation)
67
+ assert_equal(1594.003, @track.highest_point.elevation)
68
+ assert_equal(38.681488, @track.bounds.min_lat)
69
+ assert_equal(-109.606948, @track.bounds.min_lon)
70
+ assert_equal(38.791759, @track.bounds.max_lat)
71
+ assert_equal(-109.447045, @track.bounds.max_lon)
72
+ end
71
73
 
74
+ def test_append_segment
75
+ trk = GPX::Track.new
76
+ seg = GPX::Segment.new(track: trk)
77
+ pt = GPX::TrackPoint.new(lat: -118, lon: 34)
78
+ seg.append_point(pt)
79
+ trk.append_segment(seg)
80
+ assert_equal(1, trk.points.size)
81
+ end
72
82
  end
@@ -1,48 +1,44 @@
1
- require 'minitest/autorun'
2
- require 'gpx'
3
-
4
- class WaypointTest < Minitest::Test
5
-
6
- def test_read_waypoints
7
-
8
- gpx = GPX::GPXFile.new(:gpx_file => File.join(File.dirname(__FILE__), "gpx_files/waypoints.gpx"))
9
- assert_equal(18, gpx.waypoints.size)
10
-
11
- # First Waypoint
12
- # <wpt lat="40.035557" lon="-105.248268">
13
- # <name><![CDATA[001]]></name>
14
- # <sym>Waypoint</sym>
15
- # <ele>1639.161</ele>
16
- # <cmt><![CDATA[001]]></cmt>
17
- # <desc><![CDATA[Just some waypoint...]]></desc>
18
- # </wpt>
19
-
20
- first_wpt = gpx.waypoints[0]
21
- assert_equal(40.035557, first_wpt.lat)
22
- assert_equal(-105.248268, first_wpt.lon)
23
- assert_equal('001', first_wpt.name)
24
- assert_equal('001', first_wpt.cmt)
25
- assert_equal('Just some waypoint...', first_wpt.desc)
26
- assert_equal('Waypoint', first_wpt.sym)
27
- assert_equal(1639.161, first_wpt.elevation)
28
-
29
- # Second Waypoint
30
- # <wpt lat="39.993070" lon="-105.296588">
31
- # <name><![CDATA[002]]></name>
32
- # <sym>Waypoint</sym>
33
- # <ele>1955.192</ele>
34
- # </wpt>
35
- second_wpt = gpx.waypoints[1]
36
- assert_equal(39.993070, second_wpt.lat)
37
- assert_equal(-105.296588, second_wpt.lon)
38
- assert_equal('002', second_wpt.name)
39
- assert_equal('Waypoint', second_wpt.sym)
40
- assert_equal(1955.192, second_wpt.elevation)
41
-
42
- # test loads time properly in waypoint
43
- time_wpt = gpx.waypoints[17]
44
- assert_equal(Time.xmlschema("2015-01-01T12:12:12Z"), time_wpt.time)
45
-
46
- end
47
- end
48
-
1
+ require 'minitest/autorun'
2
+ require 'gpx'
3
+
4
+ class WaypointTest < Minitest::Test
5
+ def test_read_waypoints
6
+ gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/waypoints.gpx'))
7
+ assert_equal(18, gpx.waypoints.size)
8
+
9
+ # First Waypoint
10
+ # <wpt lat="40.035557" lon="-105.248268">
11
+ # <name><![CDATA[001]]></name>
12
+ # <sym>Waypoint</sym>
13
+ # <ele>1639.161</ele>
14
+ # <cmt><![CDATA[001]]></cmt>
15
+ # <desc><![CDATA[Just some waypoint...]]></desc>
16
+ # </wpt>
17
+
18
+ first_wpt = gpx.waypoints[0]
19
+ assert_equal(40.035557, first_wpt.lat)
20
+ assert_equal(-105.248268, first_wpt.lon)
21
+ assert_equal('001', first_wpt.name)
22
+ assert_equal('001', first_wpt.cmt)
23
+ assert_equal('Just some waypoint...', first_wpt.desc)
24
+ assert_equal('Waypoint', first_wpt.sym)
25
+ assert_equal(1639.161, first_wpt.elevation)
26
+
27
+ # Second Waypoint
28
+ # <wpt lat="39.993070" lon="-105.296588">
29
+ # <name><![CDATA[002]]></name>
30
+ # <sym>Waypoint</sym>
31
+ # <ele>1955.192</ele>
32
+ # </wpt>
33
+ second_wpt = gpx.waypoints[1]
34
+ assert_equal(39.993070, second_wpt.lat)
35
+ assert_equal(-105.296588, second_wpt.lon)
36
+ assert_equal('002', second_wpt.name)
37
+ assert_equal('Waypoint', second_wpt.sym)
38
+ assert_equal(1955.192, second_wpt.elevation)
39
+
40
+ # test loads time properly in waypoint
41
+ time_wpt = gpx.waypoints[17]
42
+ assert_equal(Time.xmlschema('2015-01-01T12:12:12Z'), time_wpt.time)
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Dott
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-01-05 00:00:00.000000000 Z
13
+ date: 2018-03-06 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.7'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.7'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: rake
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -27,21 +41,21 @@ dependencies:
27
41
  - !ruby/object:Gem::Version
28
42
  version: '0'
29
43
  - !ruby/object:Gem::Dependency
30
- name: nokogiri
44
+ name: bundler
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
- - - "~>"
47
+ - - ">="
34
48
  - !ruby/object:Gem::Version
35
- version: '1.7'
36
- type: :runtime
49
+ version: '0'
50
+ type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
- - - "~>"
54
+ - - ">="
41
55
  - !ruby/object:Gem::Version
42
- version: '1.7'
56
+ version: '0'
43
57
  - !ruby/object:Gem::Dependency
44
- name: bundler
58
+ name: minitest
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - ">="
@@ -55,7 +69,7 @@ dependencies:
55
69
  - !ruby/object:Gem::Version
56
70
  version: '0'
57
71
  - !ruby/object:Gem::Dependency
58
- name: minitest
72
+ name: rubocop
59
73
  requirement: !ruby/object:Gem::Requirement
60
74
  requirements:
61
75
  - - ">="
@@ -78,6 +92,7 @@ extensions: []
78
92
  extra_rdoc_files: []
79
93
  files:
80
94
  - ".gitignore"
95
+ - ".rubocop.yml"
81
96
  - ".travis.yml"
82
97
  - CHANGELOG.md
83
98
  - Gemfile
@@ -96,7 +111,7 @@ files:
96
111
  - lib/gpx/route.rb
97
112
  - lib/gpx/segment.rb
98
113
  - lib/gpx/track.rb
99
- - lib/gpx/trackpoint.rb
114
+ - lib/gpx/track_point.rb
100
115
  - lib/gpx/version.rb
101
116
  - lib/gpx/waypoint.rb
102
117
  - tests/gpx10_test.rb
@@ -111,6 +126,7 @@ files:
111
126
  - tests/gpx_files/routes.gpx
112
127
  - tests/gpx_files/tracks.gpx
113
128
  - tests/gpx_files/waypoints.gpx
129
+ - tests/gpx_files/with_empty_tracks.gpx
114
130
  - tests/gpx_files/with_or_without_elev.gpx
115
131
  - tests/magellan_test.rb
116
132
  - tests/output_test.rb
@@ -131,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
147
  requirements:
132
148
  - - "~>"
133
149
  - !ruby/object:Gem::Version
134
- version: '2.1'
150
+ version: '2.2'
135
151
  required_rubygems_version: !ruby/object:Gem::Requirement
136
152
  requirements:
137
153
  - - ">="
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
155
  version: '0'
140
156
  requirements: []
141
157
  rubyforge_project:
142
- rubygems_version: 2.4.8
158
+ rubygems_version: 2.7.3
143
159
  signing_key:
144
160
  specification_version: 4
145
161
  summary: A basic API for reading and writing GPX files.