Tracks and routes as containers of points: listed (collapsed) under them in the tree, added via a point's popup, a new note or the route planner's navigation pins, and written as course points into the FIT course
CI / check (push) Successful in 18s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-18 12:39:04 +01:00
1 parent 6aa7b34f92
commit 4265421457
10 files changed
+354 -20

No files matched your search

+17
View File
@@ -158,4 +158,21 @@ class FitTest < Minitest::Test
assert_equal 0, Maptool::FitCourse.send(:crc, bytes)
assert_equal 0xBB3D, Maptool::FitCourse.send(:crc, "123456789")
end
def test_a_fit_course_carries_its_points_as_course_points
coordinates = [[17.1, 48.1], [17.11, 48.11], [17.12, 48.1]]
points = [{ coordinate: [17.12, 48.1001], name: "Summit cross with a long name", hint: "summit" }, { coordinate: [17.1101, 48.11], name: "Spring", hint: "Spring water" }]
bytes = Maptool::FitCourse.encode(coordinates, name: "Loop", points: points)
path = File.join(Dir.mktmpdir, "course.fit")
File.binwrite(path, bytes)
assert_equal 3, Maptool::Fit.to_geojson(path)["features"][0]["geometry"]["coordinates"][0].size # still parses
assert_equal 0, Maptool::FitCourse.send(:crc, bytes)
# course_point data: message_index, timestamp, lat, lon, distance, type, name — in order along the line
spring = bytes.index("Spring")
summit = bytes.index("Summit cross wi\0")
assert spring < summit
assert_equal 3, bytes.getbyte(spring - 1) # water
assert_equal 1, bytes.getbyte(summit - 1) # summit
end
end
+16
View File
@@ -177,6 +177,22 @@ class LibraryTest < Minitest::Test
assert_raises(Maptool::Library::NotFound) { library.export_gpx("nope") }
end
def test_points_added_to_a_track_live_in_it
library = open_library
key = library.import(folder: "trips", filename: "ride.gpx", io: File.open(fixture_path("sample.gpx"))).find { |k| k.start_with?("item:") }
before = library.tree["children"][0]["children"].find { |n| n["path"] == key }["points"].to_a.size
id = library.add_point(key, { "type" => "Feature", "geometry" => { "type" => "Point", "coordinates" => [17.1, 48.1] }, "properties" => { "name" => "Spring", "id" => "x" } })
node = library.tree["children"][0]["children"].find { |n| n["path"] == key }
assert_equal before + 1, node["points"].size
assert_includes node["points"], { "id" => id, "name" => "Spring", "coordinates" => [17.1, 48.1] }
assert_includes JSON.parse(library.geojson(key))["features"].map { |f| f["properties"]["name"] }, "Spring"
assert_raises(Maptool::Library::InvalidValue) { library.add_point(key, { "geometry" => { "type" => "LineString", "coordinates" => [] } }) }
library.delete_feature(key, id)
assert_equal before, library.tree["children"][0]["children"].find { |n| n["path"] == key }["points"].to_a.size
end
def test_reparse_rereads_old_profiles_once_and_keeps_the_name
library = open_library
key = library.import(folder: "", filename: "ride.gpx", io: File.open(fixture_path("sample.gpx"))).find { |k| k.start_with?("item:") }