{"ScriptPreparationCode":"var EARTH_RADIUS_M = 6371e3;\r\nvar EARTH_DIAMETER_M = EARTH_RADIUS_M * 2;\r\nvar DEG_TO_RAD = Math.PI / 180;\r\nvar p1 = { lat: 43.63625, lon: -79.40454 };\r\nvar p2 = { lat: 43.69851, lon: -79.39699 };\r\n\r\nfunction haversineClassic(lat1, lon1, lat2, lon2) {\r\n var \u03C61 = lat1 * DEG_TO_RAD;\r\n var \u03C62 = lat2 * DEG_TO_RAD;\r\n var \u0394\u03C6 = (lat2-lat1) * DEG_TO_RAD;\r\n var \u0394\u03BB = (lon2-lon1) * DEG_TO_RAD;\r\n\r\n var a = Math.sin(\u0394\u03C6/2) * Math.sin(\u0394\u03C6/2) \u002B\r\n Math.cos(\u03C61) * Math.cos(\u03C62) *\r\n Math.sin(\u0394\u03BB/2) * Math.sin(\u0394\u03BB/2);\r\n var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));\r\n\r\n var d = EARTH_RADIUS_M * c;\r\n \r\n return d;\r\n}\r\n\r\nfunction haversineOptimized(lat1, lon1, lat2, lon2) {\r\n var p = 0.017453292519943295; // Math.PI / 180\r\n var c = Math.cos;\r\n var a = 0.5 - c((lat2 - lat1) * p)/2 \u002B \r\n c(lat1 * p) * c(lat2 * p) * \r\n (1 - c((lon2 - lon1) * p))/2;\r\n\r\n return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km \r\n}\r\n\r\nfunction haversineMineATan(lat1, lon1, lat2, lon2) {\r\n var fDP = Math.sin( (lat2 - lat1) * DEG_TO_RAD / 2 );\r\n var fDL = Math.sin( (lon2 - lon1) * DEG_TO_RAD / 2 );\r\n var fP1 = Math.cos( lat1 * DEG_TO_RAD );\r\n var fP2 = Math.cos( lat2 * DEG_TO_RAD );\r\n var a = fDP * fDP \u002B fP1 * fP2 * fDL * fDL;\r\n return EARTH_DIAMETER_M * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));\r\n}\r\nfunction haversineMineASin(lat1, lon1, lat2, lon2) {\r\n var fDP = Math.sin( (lat2 - lat1) * DEG_TO_RAD / 2 );\r\n var fDL = Math.sin( (lon2 - lon1) * DEG_TO_RAD / 2 );\r\n var fP1 = Math.cos( lat1 * DEG_TO_RAD );\r\n var fP2 = Math.cos( lat2 * DEG_TO_RAD );\r\n var a = fDP * fDP \u002B fP1 * fP2 * fDL * fDL;\r\n return EARTH_DIAMETER_M * Math.asin(Math.sqrt(a));\r\n}\r\n\r\nfunction spherical(lat1, lon1, lat2, lon2) {\r\n var \u03C61 = lat1 * DEG_TO_RAD, \u03C62 = lat2 * DEG_TO_RAD, \u0394\u03BB = (lon2-lon1) * DEG_TO_RAD;\r\n return Math.acos( Math.sin(\u03C61) * Math.sin(\u03C62) \u002B Math.cos(\u03C61) * Math.cos(\u03C62) * Math.cos(\u0394\u03BB) ) * EARTH_RADIUS_M;\r\n}\r\n\r\nfunction equirectangular(lat1, lon1, lat2, lon2) {\r\n var x = (lon2-lon1)*DEG_TO_RAD * Math.cos( (lat1\u002Blat2)*DEG_TO_RAD/2 );\r\n var y = (lat2-lat1)*DEG_TO_RAD;\r\n return EARTH_RADIUS_M * Math.sqrt( x*x \u002B y*y )\r\n}\r\n","TestCases":[{"Name":"Haversine Classic","Code":"haversineClassic(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false},{"Name":"Haversine Optimized","Code":"haversineOptimized(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false},{"Name":"Haversine Mine ATan","Code":"haversineMineATan(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false},{"Name":"Haversine Mine ASin","Code":"haversineMineASin(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false},{"Name":"Spherical Law of Cosines","Code":"spherical(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false},{"Name":"Equirectangular (a little less accurate)","Code":"equirectangular(p1.lat, p1.lon, p2.lat, p2.lon);","IsDeferred":false}]}