Functional Weave
Code in Rust

geo.distance@2.0.0

vectors.json

2,879 bytes · view raw

[
  { "name": "London to Paris", "args": [51.5074, -0.1278, 48.8566, 2.3522], "expect": 343556.535 },
  { "name": "JFK to Heathrow", "args": [40.6413, -73.7781, 51.47, -0.4543], "expect": 5540018.97 },
  { "name": "Sydney to Melbourne, southern and eastern hemispheres", "args": [-33.8688, 151.2093, -37.8136, 144.9631], "expect": 713428.466 },
  { "name": "Nashville to Los Angeles, the classic haversine example, on the IUGG mean radius", "args": [36.12, -86.67, 33.94, -118.4], "expect": 2886448.43 },
  { "name": "one degree of longitude on the equator is pi R / 180", "args": [0, 0, 0, 1], "expect": 111195.08 },
  { "name": "one degree of latitude is the same length on a sphere", "args": [0, 0, 1, 0], "expect": 111195.08 },
  { "name": "across the antimeridian is one degree, not 359 (naive longitude difference gets this wrong)", "args": [0, 179.5, 0, -179.5], "expect": 111195.08 },
  { "name": "half way round the equator is half the circumference", "args": [0, 0, 0, 180], "expect": 20015114.442 },
  { "name": "pole to pole, antipodal", "args": [90, 0, -90, 0], "expect": 20015114.442 },
  { "name": "over the north pole: 89.9N 0E to 89.9N 180E is 0.2 degrees", "args": [89.9, 0, 89.9, 180], "expect": 22239.016 },
  { "name": "the same pole at two longitudes is the same point", "args": [-90, 0, -90, 123], "expect": 0 },
  { "name": "identical points are zero", "args": [51.5074, -0.1278, 51.5074, -0.1278], "expect": 0 },
  { "name": "about a metre apart keeps millimetre accuracy (the acos formula loses it)", "args": [51.5, -0.1, 51.500009, -0.1], "expect": 1.001 },
  { "name": "about 11 centimetres", "args": [10, 20, 10.000001, 20], "expect": 0.111 },
  { "name": "Tokyo Haneda to near Stellenbosch: the distance is the double 14704080.96649999916..., just below the millimetre tie, so it rounds down (1.x said .967, because 1000 times it rounds up to exactly the tie)", "args": [35.5494, 139.7798, -33.9399, 18.786034], "expect": 14704080.966 },
  { "name": "London to the Tasman Sea off Sydney: 17024346.35449999943... is just below the tie and rounds down (1.x said .355)", "args": [51.5074, -0.1278, -33.8688, 151.714482], "expect": 17024346.354 },
  { "name": "the order of the points does not matter", "args": [48.8566, 2.3522, 51.5074, -0.1278], "expect": 343556.535 },
  { "name": "latitude above 90 is an error", "args": [91, 0, 0, 0], "expectError": "latitude must be between -90 and 90 degrees" },
  { "name": "latitude below -90 is an error", "args": [0, 0, -90.5, 0], "expectError": "latitude must be between -90 and 90 degrees" },
  { "name": "longitude above 180 is an error, not silently wrapped", "args": [0, 181, 0, 0], "expectError": "longitude must be between -180 and 180 degrees" },
  { "name": "a coordinate that is not a number is an error", "args": ["51.5", 0, 0, 0], "expectError": "latitude must be a finite number of degrees" }
]