require_relative "test_helper" require "maptool/corridor" class CorridorTest < Minitest::Test C = Maptool::Corridor # 30 km east along 48° N, as a vertex every ~0.75 km LINE = (0..40).map { |i| [17.0 + i * 0.01, 48.0] } def test_circles_cover_the_corridor_with_no_gap circles = C.circles(LINE, 2.0) assert_in_delta 2.5, circles.first[1], 1e-9 # every point 2 km off the line, all along it, inside a circle (0..300).each do |i| lon = 17.0 + i * 0.4 / 300 edge = [lon, 48.0 + 2.0 / C::KM_PER_DEG] assert circles.any? { |center, r| C.km(center, edge) <= r + 1e-6 }, "gap at #{lon}" end assert_operator circles.size, :<=, (C.km(LINE.first, LINE.last) / 3.0).ceil + 2 end def test_distance_to_the_line_and_thinning assert_in_delta 1.0, C.distance_km([17.2, 48.0 + 1.0 / C::KM_PER_DEG], LINE), 1e-3 assert_in_delta C.km([16.99, 48.0], LINE.first), C.distance_km([16.99, 48.0], LINE), 1e-9 # past an end: to the end thin = C.thin(LINE, 2.0) assert_equal [LINE.first, LINE.last], [thin.first, thin.last] assert thin.each_cons(2).to_a[0..-2].all? { |a, b| C.km(a, b) >= 2.0 } end end