Skip to content

Commit b9afaf2

Browse files
committed
Added a test which checks the distance between London and Edinburgh is correctly calculated.
1 parent ce84a8d commit b9afaf2

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Check the haversine function usage.
3+
--SKIPIF--
4+
<?php if (!extension_loaded("geospatial")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
echo haversine(51.5171, 0.1062, 55.9500, 3.2200);
8+
/*
9+
Test the haversine distance between London and Edinburgh.
10+
11+
London: 51.5171° N, 0.1062° W (0.899143016 / 0.00185353967)
12+
Edinburgh: 55.9500° N, 3.2200° W (0.976511716 / 0.0561996019)
13+
14+
Delta-lat: 4.4329° (0.0773687004)
15+
Delta-long: 3.1138° (0.0543460622)
16+
17+
double a = pow(sin(0.0773687004 * 0.5),2) + cos(0.899143016) * cos(0.976511716) * pow(sin(0.0543460622 * 0.5),2);
18+
double a = pow(sin(0.03868435),2) + cos(0.899143016) * cos(0.976511716) * pow(sin(0.027173031),2);
19+
double a = pow(0.03867470233,2) + 0.62228103855 * 0.55991616262 * pow(0.02716968714,2);
20+
double a = 0.0014957326 + 0.62228103855 * 0.55991616262 * 0.00073819189
21+
double a = 0.0014957326 + 0.00025720466
22+
double a = 0.00175293726
23+
double c = 2.0 * atan2(sqrt(a), sqrt(1-a));
24+
double c = 2.0 * atan2(sqrt(0.00175293726), sqrt(0.99824706274));
25+
double c = 2.0 * 0.04188033525
26+
double c = 0.08376067
27+
return R * c;
28+
return
29+
30+
Accept defined (equatorial) Earth Radius in km (which is based on WGS-84):
31+
- 6378137m (at the equator).
32+
33+
Sanity check - expected distance: approx 534km.
34+
*/
35+
?>
36+
--EXPECT--
37+
534.237028
38+
39+

0 commit comments

Comments
 (0)