gpx 0.8.3 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +37 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop +1 -0
  5. data/.rubocop.yml +162 -0
  6. data/.ruby-version +1 -0
  7. data/.tool-versions +1 -0
  8. data/.travis.yml +4 -6
  9. data/CHANGELOG.md +32 -0
  10. data/Gemfile +2 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +38 -17
  13. data/Rakefile +22 -12
  14. data/UPGRADING.md +7 -0
  15. data/bin/gpx_distance +5 -6
  16. data/bin/gpx_smooth +25 -26
  17. data/gpx.gemspec +14 -11
  18. data/lib/gpx/bounds.rb +13 -31
  19. data/lib/gpx/geo_json.rb +199 -0
  20. data/lib/gpx/gpx.rb +4 -26
  21. data/lib/gpx/gpx_file.rb +140 -134
  22. data/lib/gpx/magellan_track_log.rb +34 -66
  23. data/lib/gpx/point.rb +22 -35
  24. data/lib/gpx/route.rb +10 -31
  25. data/lib/gpx/segment.rb +63 -90
  26. data/lib/gpx/track.rb +38 -42
  27. data/lib/gpx/track_point.rb +32 -0
  28. data/lib/gpx/version.rb +3 -1
  29. data/lib/gpx/waypoint.rb +10 -34
  30. data/lib/gpx.rb +13 -34
  31. data/tests/geojson_files/combined_data.json +68 -0
  32. data/tests/geojson_files/line_string_data.json +83 -0
  33. data/tests/geojson_files/multi_line_string_data.json +74 -0
  34. data/tests/geojson_files/multi_point_data.json +14 -0
  35. data/tests/geojson_files/point_data.json +22 -0
  36. data/tests/geojson_test.rb +92 -0
  37. data/tests/gpx10_test.rb +7 -6
  38. data/tests/gpx_file_test.rb +31 -19
  39. data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
  40. data/tests/gpx_files/routes_without_names.gpx +29 -0
  41. data/tests/gpx_files/with_empty_tracks.gpx +72 -0
  42. data/tests/magellan_test.rb +12 -11
  43. data/tests/output_test.rb +93 -94
  44. data/tests/route_test.rb +75 -30
  45. data/tests/segment_test.rb +104 -93
  46. data/tests/track_file_test.rb +50 -70
  47. data/tests/track_point_test.rb +22 -11
  48. data/tests/track_test.rb +73 -61
  49. data/tests/waypoint_test.rb +46 -48
  50. metadata +45 -13
  51. data/lib/gpx/trackpoint.rb +0 -60
@@ -1,109 +1,120 @@
1
- #require 'minitest/autorun'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'minitest/autorun'
3
4
  require 'yaml'
4
5
  require 'gpx'
5
6
 
6
7
  class SegmentTest < Minitest::Test
7
- ONE_SEGMENT = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
8
- ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), "gpx_files/one_segment_no_time.gpx")
8
+ ONE_SEGMENT = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx')
9
+ ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_no_time.gpx')
10
+ ONE_SEGMENT_MIXED_TIMES = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_mixed_times.gpx')
9
11
 
10
- def setup
11
- @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT)
12
- @segment = @gpx_file.tracks.first.segments.first
13
- end
12
+ def setup
13
+ @gpx_file = GPX::GPXFile.new(gpx_file: ONE_SEGMENT)
14
+ @segment = @gpx_file.tracks.first.segments.first
15
+ end
14
16
 
15
- def test_segment_read
16
- assert_equal(189, @segment.points.size)
17
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
18
- assert_equal(1144437991, @segment.latest_point.time.to_i)
19
- assert_equal(1334.447, @segment.lowest_point.elevation)
20
- assert_equal(1480.087, @segment.highest_point.elevation)
21
- assert_in_delta(6.98803359528853, @segment.distance, 0.001)
22
- assert_equal(4466.0, @segment.duration)
23
- end
17
+ def test_segment_read
18
+ assert_equal(189, @segment.points.size)
19
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
20
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
21
+ assert_equal(1334.447, @segment.lowest_point.elevation)
22
+ assert_equal(1480.087, @segment.highest_point.elevation)
23
+ assert_in_delta(6.98803359528853, @segment.distance, 0.001)
24
+ assert_equal(4466.0, @segment.duration)
25
+ end
24
26
 
25
- def test_segment_read_no_time
26
- gpx_file_no_time = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT_NO_TIME)
27
- segment_no_time = gpx_file_no_time.tracks.first.segments.first
28
- assert_equal(189, segment_no_time.points.size)
29
- assert_equal(1334.447, segment_no_time.earliest_point.elevation)
30
- assert_equal(1413.756, segment_no_time.latest_point.elevation)
31
- assert_equal(1334.447, segment_no_time.lowest_point.elevation)
32
- assert_equal(1480.087, segment_no_time.highest_point.elevation)
33
- assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
34
- assert_equal(0, segment_no_time.duration)
35
- end
27
+ def test_segment_read_no_time
28
+ gpx_file_no_time = GPX::GPXFile.new(gpx_file: ONE_SEGMENT_NO_TIME)
29
+ segment_no_time = gpx_file_no_time.tracks.first.segments.first
30
+ assert_equal(189, segment_no_time.points.size)
31
+ assert_equal(1334.447, segment_no_time.earliest_point.elevation)
32
+ assert_equal(1413.756, segment_no_time.latest_point.elevation)
33
+ assert_equal(1334.447, segment_no_time.lowest_point.elevation)
34
+ assert_equal(1480.087, segment_no_time.highest_point.elevation)
35
+ assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
36
+ assert_equal(0, segment_no_time.duration)
37
+ end
36
38
 
37
- def test_segment_crop
38
- crop_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
39
- :min_lon=> -109.010000,
40
- :max_lat=> 39.188000,
41
- :max_lon=> -108.999000)
42
- @segment.crop(crop_rectangle)
39
+ def test_segment_crop
40
+ crop_rectangle = GPX::Bounds.new(min_lat: 39.173000,
41
+ min_lon: -109.010000,
42
+ max_lat: 39.188000,
43
+ max_lon: -108.999000)
44
+ @segment.crop(crop_rectangle)
43
45
 
44
- assert_equal(106, @segment.points.size)
45
- assert_in_delta(4.11422061733046, @segment.distance, 0.001)
46
- assert_equal(1144435041, @segment.earliest_point.time.to_i)
47
- assert_equal(1144437752, @segment.latest_point.time.to_i)
48
- assert_equal(1407.027, @segment.lowest_point.elevation)
49
- assert_equal(1480.087, @segment.highest_point.elevation)
50
- assert_equal(39.173834, @segment.bounds.min_lat)
51
- assert_equal(-109.009995, @segment.bounds.min_lon)
52
- assert_equal(39.187868, @segment.bounds.max_lat)
53
- assert_equal(-108.999546, @segment.bounds.max_lon)
54
- assert_equal(2711.0, @segment.duration)
55
- end
46
+ assert_equal(106, @segment.points.size)
47
+ assert_in_delta(4.11422061733046, @segment.distance, 0.001)
48
+ assert_equal(1_144_435_041, @segment.earliest_point.time.to_i)
49
+ assert_equal(1_144_437_752, @segment.latest_point.time.to_i)
50
+ assert_equal(1407.027, @segment.lowest_point.elevation)
51
+ assert_equal(1480.087, @segment.highest_point.elevation)
52
+ assert_equal(39.173834, @segment.bounds.min_lat)
53
+ assert_equal(-109.009995, @segment.bounds.min_lon)
54
+ assert_equal(39.187868, @segment.bounds.max_lat)
55
+ assert_equal(-108.999546, @segment.bounds.max_lon)
56
+ assert_equal(2711.0, @segment.duration)
57
+ end
56
58
 
57
- def test_segment_delete
58
- delete_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
59
- :min_lon=> -109.010000,
60
- :max_lat=> 39.188000,
61
- :max_lon=> -108.999000)
62
- @segment.delete_area(delete_rectangle)
63
- assert_equal(83, @segment.points.size)
64
- assert_in_delta(3.35967118153605, @segment.distance, 0.001)
65
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
66
- assert_equal(1144437991, @segment.latest_point.time.to_i)
67
- assert_equal(1334.447, @segment.lowest_point.elevation)
68
- assert_equal(1428.176, @segment.highest_point.elevation)
69
- assert_equal(39.180572, @segment.bounds.min_lat)
70
- assert_equal(-109.016604, @segment.bounds.min_lon)
71
- assert_equal(39.188747, @segment.bounds.max_lat)
72
- assert_equal(-109.007978, @segment.bounds.max_lon)
73
- assert_equal(4466.0, @segment.duration)
74
- end
59
+ def test_segment_delete
60
+ delete_rectangle = GPX::Bounds.new(min_lat: 39.173000,
61
+ min_lon: -109.010000,
62
+ max_lat: 39.188000,
63
+ max_lon: -108.999000)
64
+ @segment.delete_area(delete_rectangle)
65
+ assert_equal(83, @segment.points.size)
66
+ assert_in_delta(3.35967118153605, @segment.distance, 0.001)
67
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
68
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
69
+ assert_equal(1334.447, @segment.lowest_point.elevation)
70
+ assert_equal(1428.176, @segment.highest_point.elevation)
71
+ assert_equal(39.180572, @segment.bounds.min_lat)
72
+ assert_equal(-109.016604, @segment.bounds.min_lon)
73
+ assert_equal(39.188747, @segment.bounds.max_lat)
74
+ assert_equal(-109.007978, @segment.bounds.max_lon)
75
+ assert_equal(4466.0, @segment.duration)
76
+ end
75
77
 
76
- def test_segment_smooth
77
- @segment.smooth_location_by_average
78
- assert_equal(189, @segment.points.size)
79
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
80
- assert_equal(1144437991, @segment.latest_point.time.to_i)
81
- assert_equal(1342.58, @segment.lowest_point.elevation)
82
- assert_equal(1479.09, @segment.highest_point.elevation)
83
- assert_in_delta(6.458085658, @segment.distance, 0.001)
84
- assert_equal(4466.0, @segment.duration)
85
- end
78
+ def test_segment_smooth
79
+ @segment.smooth_location_by_average
80
+ assert_equal(189, @segment.points.size)
81
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
82
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
83
+ assert_equal(1342.58, @segment.lowest_point.elevation)
84
+ assert_equal(1479.09, @segment.highest_point.elevation)
85
+ assert_in_delta(6.458085658, @segment.distance, 0.001)
86
+ assert_equal(4466.0, @segment.duration)
87
+ end
86
88
 
87
- def test_segment_smooth_offset
88
- @segment.smooth_location_by_average({:start => 1000, :end => 2000})
89
- assert_equal(189, @segment.points.size)
90
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
91
- assert_equal(1144437991, @segment.latest_point.time.to_i)
92
- assert_equal(1334.447, @segment.lowest_point.elevation)
93
- assert_equal(1480.087, @segment.highest_point.elevation)
94
- assert_in_delta(6.900813095, @segment.distance, 0.001)
95
- assert_equal(4466.0, @segment.duration)
96
- end
89
+ def test_segment_smooth_offset
90
+ @segment.smooth_location_by_average(start: 1000, end: 2000)
91
+ assert_equal(189, @segment.points.size)
92
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
93
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
94
+ assert_equal(1334.447, @segment.lowest_point.elevation)
95
+ assert_equal(1480.087, @segment.highest_point.elevation)
96
+ assert_in_delta(6.900813095, @segment.distance, 0.001)
97
+ assert_equal(4466.0, @segment.duration)
98
+ end
97
99
 
98
- def test_segment_smooth_absolute
99
- @segment.smooth_location_by_average({:start => Time.at(1144434520), :end => Time.at(1144435520)})
100
- assert_equal(189, @segment.points.size)
101
- assert_equal(1144433525, @segment.earliest_point.time.to_i)
102
- assert_equal(1144437991, @segment.latest_point.time.to_i)
103
- assert_equal(1334.447, @segment.lowest_point.elevation)
104
- assert_equal(1480.087, @segment.highest_point.elevation)
105
- assert_in_delta(6.900813095, @segment.distance, 0.001)
106
- assert_equal(4466.0, @segment.duration)
107
- end
100
+ def test_segment_smooth_absolute
101
+ @segment.smooth_location_by_average(start: Time.at(1_144_434_520), end: Time.at(1_144_435_520))
102
+ assert_equal(189, @segment.points.size)
103
+ assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
104
+ assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
105
+ assert_equal(1334.447, @segment.lowest_point.elevation)
106
+ assert_equal(1480.087, @segment.highest_point.elevation)
107
+ assert_in_delta(6.900813095, @segment.distance, 0.001)
108
+ assert_equal(4466.0, @segment.duration)
109
+ end
108
110
 
111
+ def test_segment_mixed_times
112
+ gpx_file_mixed_times = GPX::GPXFile.new(gpx_file: ONE_SEGMENT_MIXED_TIMES)
113
+ segment_mixed_times = gpx_file_mixed_times.tracks.first.segments.first
114
+ assert_equal(588, segment_mixed_times.points.size)
115
+ assert_equal(0, segment_mixed_times.earliest_point.time.to_i)
116
+ assert_equal(0, segment_mixed_times.latest_point.time.to_i)
117
+ assert_in_delta(40.763726054, segment_mixed_times.distance, 0.001)
118
+ assert_equal(0.0, segment_mixed_times.duration)
119
+ end
109
120
  end
@@ -1,75 +1,55 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  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
-
7
+ TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/tracks.gpx')
8
+ OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/arches.gpx')
9
+
10
+ def setup
11
+ @track_file = GPX::GPXFile.new(gpx_file: TRACK_FILE)
12
+ @other_track_file = GPX::GPXFile.new(gpx_file: OTHER_TRACK_FILE)
13
+ FileUtils.mkdir_p(File.join(File.dirname(__FILE__), 'output'))
14
+ end
15
+
16
+ def test_track_read
17
+ assert_equal(3, @track_file.tracks.size)
18
+ assert_equal('First Track', @track_file.tracks[0].name)
19
+ assert_equal('Second Track', @track_file.tracks[1].name)
20
+ assert_equal('Third Track', @track_file.tracks[2].name)
21
+ end
22
+
23
+ def test_track_segment_and_point_counts
24
+ # One segment with 398 points...
25
+ assert_equal(1, @track_file.tracks[0].segments.size)
26
+ assert_equal(389, @track_file.tracks[0].segments.first.points.size)
27
+
28
+ # One segment with 299 points...
29
+ assert_equal(1, @track_file.tracks[1].segments.size)
30
+ assert_equal(299, @track_file.tracks[1].segments.first.points.size)
31
+
32
+ # Many segments of many different sizes
33
+ 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]
34
+ assert_equal(43, @track_file.tracks[2].segments.size)
35
+ @track_file.tracks[2].segments.each_with_index do |seg, i|
36
+ assert_equal(segment_sizes[i].to_i, seg.points.size)
37
+ end
38
+ last_segment = @track_file.tracks[2].segments.last
39
+ assert_equal(1680.041, last_segment.points.last.elevation)
40
+
41
+ second_to_last_segment = @track_file.tracks[2].segments[-2]
42
+ assert_equal('2006-01-02T00:00:51Z', second_to_last_segment.points.last.time.strftime('%Y-%m-%dT%H:%M:%SZ'))
43
+ assert_equal(39.998045, second_to_last_segment.points.last.lat)
44
+ assert_equal(-105.292368, second_to_last_segment.points.last.lon)
45
+ end
46
+
47
+ def test_write
48
+ output_path = 'tests/output/myoutput.gpx'
49
+ @other_track_file.write(output_path)
50
+ new_track_file = GPX::GPXFile.new(gpx_file: output_path)
51
+ orig_segments = @other_track_file.tracks.first.segments
52
+ new_segments = new_track_file.tracks.first.segments
53
+ assert_equal(orig_segments.first.points.map(&:lat_lon), new_segments.first.points.map(&:lat_lon))
54
+ end
75
55
  end
@@ -1,16 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class TrackPointTest < Minitest::Test
5
7
  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
- })
8
+ @point1 = GPX::TrackPoint.new(
9
+ lat: 37.7985474,
10
+ lon: -122.2554386
11
+ )
12
+ @point2 = GPX::TrackPoint.new(
13
+ lat: 37.7985583,
14
+ lon: -122.2554564
15
+ )
16
+ @point3 = GPX::TrackPoint.new(
17
+ lat: 38.7985583,
18
+ lon: -121.2554564
19
+ )
14
20
  end
15
21
 
16
22
  def test_haversine_distance_from
@@ -18,13 +24,18 @@ class TrackPointTest < Minitest::Test
18
24
  assert_in_delta(0.00197862991592239, distance, 1e-18)
19
25
  end
20
26
 
21
- def test_pythagorean_distance_from
22
- distance = @point1.pythagorean_distance_from(@point2)
23
- assert_equal(3.642891416092969e-07, distance)
27
+ def test_longer_haversine_distance_from
28
+ distance = @point2.haversine_distance_from(@point3)
29
+ assert_in_delta(141.3465338444813, distance, 1e-18)
24
30
  end
25
31
 
26
32
  def test_law_of_cosines_distance_from
27
33
  distance = @point1.law_of_cosines_distance_from(@point2)
28
34
  assert_equal(0.001982307218559664, distance)
29
35
  end
36
+
37
+ def test_longer_law_of_cosines_distance_from
38
+ distance = @point2.law_of_cosines_distance_from(@point3)
39
+ assert_equal(141.3465338444991, distance)
40
+ end
30
41
  end
data/tests/track_test.rb CHANGED
@@ -1,72 +1,84 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class TrackTest < Minitest::Test
5
- ONE_TRACK = File.join(File.dirname(__FILE__), "gpx_files/one_track.gpx")
7
+ ONE_TRACK = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
6
8
 
7
- def setup
8
- @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_TRACK)
9
- @track = @gpx_file.tracks.first
10
- end
9
+ def setup
10
+ @gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK)
11
+ @track = @gpx_file.tracks.first
12
+ end
11
13
 
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
14
+ def test_track_read
15
+ assert_equal('ACTIVE LOG', @track.name)
16
+ assert_equal('Comment Log', @track.comment)
17
+ assert_equal('Description Log', @track.description)
18
+ assert_equal(182, @track.points.size)
19
+ assert_equal(8, @track.segments.size)
20
+ assert_in_delta(3.07249668492626, @track.distance, 0.001)
21
+ assert_equal(1267.155, @track.lowest_point.elevation)
22
+ assert_equal(1594.003, @track.highest_point.elevation)
23
+ assert_equal(38.681488, @track.bounds.min_lat)
24
+ assert_equal(-109.606948, @track.bounds.min_lon)
25
+ assert_equal(38.791759, @track.bounds.max_lat)
26
+ assert_equal(-109.447045, @track.bounds.max_lon)
27
+ assert_equal(3036.0, @track.moving_duration)
28
+ end
27
29
 
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
30
+ def test_track_crop
31
+ area = GPX::Bounds.new(
32
+ min_lat: 38.710000,
33
+ min_lon: -109.600000,
34
+ max_lat: 38.791759,
35
+ max_lon: -109.450000
36
+ )
37
+ @track.crop(area)
38
+ assert_equal('ACTIVE LOG', @track.name)
39
+ assert_equal('Comment Log', @track.comment)
40
+ assert_equal('Description Log', @track.description)
41
+ assert_equal(111, @track.points.size)
42
+ assert_equal(4, @track.segments.size)
43
+ assert_in_delta(1.62136024923607, @track.distance, 0.001)
44
+ assert_equal(1557.954, @track.lowest_point.elevation)
45
+ assert_equal(1582.468, @track.highest_point.elevation)
46
+ assert_equal(38.782511, @track.bounds.min_lat)
47
+ assert_equal(-109.599781, @track.bounds.min_lon)
48
+ assert_equal(38.789527, @track.bounds.max_lat)
49
+ assert_equal(-109.594996, @track.bounds.max_lon)
50
+ assert_equal(1773.0, @track.moving_duration)
51
+ end
49
52
 
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)
53
+ def test_track_delete
54
+ area = GPX::Bounds.new(
55
+ min_lat: 38.710000,
56
+ min_lon: -109.600000,
57
+ max_lat: 38.791759,
58
+ max_lon: -109.450000
59
+ )
60
+ @track.delete_area(area)
57
61
 
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
62
+ assert_equal(1229.0, @track.moving_duration)
63
+ # puts @track
64
+ assert_equal('ACTIVE LOG', @track.name)
65
+ assert_equal(71, @track.points.size)
66
+ assert_equal(6, @track.segments.size)
67
+ assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
68
+ assert_equal(1267.155, @track.lowest_point.elevation)
69
+ assert_equal(1594.003, @track.highest_point.elevation)
70
+ assert_equal(38.681488, @track.bounds.min_lat)
71
+ assert_equal(-109.606948, @track.bounds.min_lon)
72
+ assert_equal(38.791759, @track.bounds.max_lat)
73
+ assert_equal(-109.447045, @track.bounds.max_lon)
74
+ end
71
75
 
76
+ def test_append_segment
77
+ trk = GPX::Track.new
78
+ seg = GPX::Segment.new(track: trk)
79
+ pt = GPX::TrackPoint.new(lat: -118, lon: 34)
80
+ seg.append_point(pt)
81
+ trk.append_segment(seg)
82
+ assert_equal(1, trk.points.size)
83
+ end
72
84
  end
@@ -1,48 +1,46 @@
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
+ # frozen_string_literal: true
2
+
3
+ require 'minitest/autorun'
4
+ require 'gpx'
5
+
6
+ class WaypointTest < Minitest::Test
7
+ def test_read_waypoints
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
+ end
46
+ end