Skip to content

Commit 801eaec

Browse files
committed
Move radius conversion out of the helper function, so we can use it for other things too.
1 parent 214fa8d commit 801eaec

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

geospatial.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ PHP_MINFO_FUNCTION(geospatial)
9797
}
9898
/* }}} */
9999

100-
double php_geo_haversine(double from_lat, double from_long, double to_lat, double to_long, double radius)
100+
double php_geo_haversine(double from_lat, double from_long, double to_lat, double to_long)
101101
{
102102
double delta_lat, delta_long;
103103
double latH, longH, result;
@@ -111,7 +111,7 @@ double php_geo_haversine(double from_lat, double from_long, double to_lat, doubl
111111
longH *= longH;
112112

113113
result = cos(from_lat) * cos(to_lat);
114-
result = radius * 2.0 * asin(sqrt(latH + result * longH));
114+
result = 2.0 * asin(sqrt(latH + result * longH));
115115

116116
return result;
117117
}
@@ -127,7 +127,7 @@ PHP_FUNCTION(haversine)
127127
return;
128128
}
129129

130-
RETURN_DOUBLE(php_geo_haversine(from_lat * GEO_DEG_TO_RAD, from_long * GEO_DEG_TO_RAD, to_lat * GEO_DEG_TO_RAD, to_long * GEO_DEG_TO_RAD, radius) / GEO_DEG_TO_RAD);
130+
RETURN_DOUBLE(php_geo_haversine(from_lat * GEO_DEG_TO_RAD, from_long * GEO_DEG_TO_RAD, to_lat * GEO_DEG_TO_RAD, to_long * GEO_DEG_TO_RAD) * radius);
131131
}
132132
/* }}} */
133133

tests/haversine.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ $lat2 = $lat1;
1111
$lon2 = -104.80;
1212
var_dump(haversine($lat1, $lon1, $lat2, $lon2));
1313
?>
14-
--EXPECT--
15-
float(7.38469839293155)
14+
--EXPECTF--
15+
float(7.384698392931%d)

0 commit comments

Comments
 (0)