Skip to content

Commit

Permalink
Merge pull request #20 from niborg/fix_track_append
Browse files Browse the repository at this point in the history
Fix duplication of points on appending segment to track
  • Loading branch information
andrewhao committed Jan 27, 2017
2 parents cb3199b + cf7256e commit d9ab0d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/gpx/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def initialize(opts = {})
def append_segment(seg)
update_meta_data(seg)
@segments << seg
@points.concat(seg.points) unless seg.nil?
end

# Returns true if the given time occurs within any of the segments of this track.
Expand Down Expand Up @@ -125,7 +124,7 @@ def recalculate_distance
@distance += seg.distance
end
end

protected

def update_meta_data(seg)
Expand Down
9 changes: 9 additions & 0 deletions tests/track_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,13 @@ def test_track_delete
assert_equal(-109.447045, @track.bounds.max_lon)
end

def test_append_segment
trk = GPX::Track.new
seg = GPX::Segment.new(track: trk)
pt = GPX::TrackPoint.new(lat: -118, lon: 34)
seg.append_point(pt)
trk.append_segment(seg)
assert_equal(1, trk.points.size)
end

end

0 comments on commit d9ab0d2

Please sign in to comment.