[geos-commits] r3024 - in trunk/php: . test
svn_geos at osgeo.org
svn_geos at osgeo.org
Sat Jun 19 09:17:49 EDT 2010
Author: strk
Date: 2010-06-19 13:17:49 +0000 (Sat, 19 Jun 2010)
New Revision: 3024
Modified:
trunk/php/geos.c
trunk/php/test/test.php
Log:
Add second optional argument to Geometry->project and Geometry->interpolate to request normalization
Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c 2010-06-19 13:08:31 UTC (rev 3023)
+++ trunk/php/geos.c 2010-06-19 13:17:49 UTC (rev 3024)
@@ -210,17 +210,22 @@
GEOSGeometry *this;
GEOSGeometry *other;
zval *zobj;
+ zend_bool normalized = 0;
double ret;
this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
- == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|b", &zobj,
+ &normalized) == FAILURE) {
RETURN_NULL();
}
other = getRelay(zobj, Geometry_ce_ptr);
- ret = GEOSProject(this, other);
+ if ( normalized ) {
+ ret = GEOSProjectNormalized(this, other);
+ } else {
+ ret = GEOSProject(this, other);
+ }
if ( ret < 0 ) RETURN_NULL(); /* should get an exception first */
RETURN_DOUBLE(ret);
@@ -230,17 +235,21 @@
{
GEOSGeometry *this;
double dist;
- zval *zobj;
GEOSGeometry *ret;
+ zend_bool normalized = 0;
this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dist)
- == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|b",
+ &dist, &normalized) == FAILURE) {
RETURN_NULL();
}
- ret = GEOSInterpolate(this, dist);
+ if ( normalized ) {
+ ret = GEOSInterpolateNormalized(this, dist);
+ } else {
+ ret = GEOSInterpolate(this, dist);
+ }
if ( ! ret ) RETURN_NULL(); /* should get an exception first */
/* return_value is a zval */
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-06-19 13:08:31 UTC (rev 3023)
+++ trunk/php/test/test.php 2010-06-19 13:17:49 UTC (rev 3024)
@@ -221,24 +221,34 @@
$g2 = $reader->read('POINT(0 0)');
$prj = $g->project($g2);
$this->assertEquals(0, $prj);
+ $prj = $g->project($g2, TRUE);
+ $this->assertEquals(0, $prj);
$g2 = $reader->read('POINT(10 0)');
$prj = $g->project($g2);
$this->assertEquals(10, $prj);
+ $prj = $g->project($g2, TRUE);
+ $this->assertEquals(1, $prj);
$g2 = $reader->read('POINT(5 0)');
$prj = $g->project($g2);
$this->assertEquals(5, $prj);
+ $prj = $g->project($g2, TRUE);
+ $this->assertEquals(0.5, $prj);
- $g = $reader->read('MULTILINESTRING((0 0, 10 0),(20 10, 20 30))');
+ $g = $reader->read('MULTILINESTRING((0 0, 10 0),(20 10, 20 20))');
$g2 = $reader->read('POINT(20 0)');
$prj = $g->project($g2);
$this->assertEquals(10, $prj);
+ $prj = $g->project($g2, TRUE);
+ $this->assertEquals(0.5, $prj);
$g2 = $reader->read('POINT(20 5)');
$prj = $g->project($g2);
$this->assertEquals(10, $prj);
+ $prj = $g->project($g2, TRUE);
+ $this->assertEquals(0.5, $prj);
}
@@ -263,15 +273,24 @@
$prj = $g->interpolate(0);
$this->assertNotNull($prj);
$this->assertEquals('POINT (0 0)', $writer->write($prj));
+ $prj = $g->interpolate(0, TRUE);
+ $this->assertNotNull($prj);
+ $this->assertEquals('POINT (0 0)', $writer->write($prj));
$prj = $g->interpolate(5);
$this->assertNotNull($prj);
$this->assertEquals('POINT (5 0)', $writer->write($prj));
+ $prj = $g->interpolate(0.5, TRUE);
+ $this->assertNotNull($prj);
+ $this->assertEquals('POINT (5 0)', $writer->write($prj));
/* return closest on longer distance */
$prj = $g->interpolate(20);
$this->assertNotNull($prj);
$this->assertEquals('POINT (10 0)', $writer->write($prj));
+ $prj = $g->interpolate(2, TRUE);
+ $this->assertNotNull($prj);
+ $this->assertEquals('POINT (10 0)', $writer->write($prj));
}
}
More information about the geos-commits
mailing list