Skip to content

Commit 768f82d

Browse files
committed
Merge pull request #1 from derickr/adding-arginfo
Fixed arginfo and tests; added a prototype.
2 parents c218672 + b172396 commit 768f82d

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

geospatial.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
#include "ext/standard/info.h"
2828
#include "php_geospatial.h"
2929

30-
ZEND_BEGIN_ARG_INFO(haversine_args,ZEND_SEND_BY_VAL)
31-
ZEND_ARG_INFO(0,fromLatitude)
32-
ZEND_ARG_INFO(0,fromLongitude)
33-
ZEND_ARG_INFO(0,toLatitude)
34-
ZEND_ARG_INFO(0,toLongitude)
35-
ZEND_ARG_INFO(0,radius)
30+
ZEND_BEGIN_ARG_INFO_EX(haversine_args, 0, 0, 4)
31+
ZEND_ARG_INFO(0, fromLatitude)
32+
ZEND_ARG_INFO(0, fromLongitude)
33+
ZEND_ARG_INFO(0, toLatitude)
34+
ZEND_ARG_INFO(0, toLongitude)
35+
ZEND_ARG_INFO(0, radius)
3636
ZEND_END_ARG_INFO()
3737

3838
/* {{{ geospatial_functions[]
@@ -97,7 +97,8 @@ PHP_MINFO_FUNCTION(geospatial)
9797
}
9898
/* }}} */
9999

100-
100+
/* {{{ proto haversine(double fromLat, double fromLong, double toLat, double toLong [, double radius ])
101+
* Calculates the greater circle distance between the two lattitude/longitude pairs */
101102
PHP_FUNCTION(haversine)
102103
{
103104
double fromLat, fromLong, toLat, toLong, deltaLat, deltaLong;
@@ -118,6 +119,7 @@ PHP_FUNCTION(haversine)
118119
result = radius * 2.0 * asin(sqrt(latH + result * longH));
119120
RETURN_DOUBLE(result);
120121
}
122+
/* }}} */
121123

122124
/*
123125
* Local variables:

tests/geospatial_haversine_london_edinburgh.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Check the haversine function returns the correct distance between London and Edinburgh.
33
--SKIPIF--
44
<?php if (!extension_loaded("geospatial")) print "skip"; ?>
5+
--INI--
6+
precision=14
57
--FILE--
68
<?php
79
echo haversine(51.5171, 0.1062, 55.9500, 3.2200);

tests/geospatial_haversine_polar_distance.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Check the haversine function returns the correct distance between the North and South poles, using a custom radius.
33
--SKIPIF--
44
<?php if (!extension_loaded("geospatial")) print "skip"; ?>
5+
--INI--
6+
precision=14
57
--FILE--
68
<?php
79
echo haversine(90, 0, -90, 0, 6356.7523);

tests/haversine.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
2-
haversine() function - bastic test for haversine forumla
2+
haversine() function - basic test for haversine forumla
3+
--INI--
4+
precision=15
35
--FILE--
46
<?php
57
$lat1 = 39.06546;
@@ -10,4 +12,4 @@ $lon2 = -104.80;
1012
var_dump(haversine($lat1, $lon1, $lat2, $lon2));
1113
?>
1214
--EXPECT--
13-
float(7.3785163137969)
15+
float(7.38469839293155)

0 commit comments

Comments
 (0)