Skip to content

Commit

Permalink
Expose Delaunay triangulation to PHP API (libgeos#567)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/geos/trunk@3834 5242fede-7e19-0410-aef8-94bd7d2200fb
  • Loading branch information
Sandro Santilli committed Jul 11, 2013
1 parent c74befc commit 55f79ad
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Changes in 3.4.0
????-??-??

- New things:
- Delaunay Triangulation API (#487, #565, #570)
- Delaunay Triangulation API (#487, #565, #570, #567)
- Interruptibility API (C and C++)
- CAPI: GEOSNode (#496) - PHP: Geometry->node
- GeometryPrecisionReducer class
Expand Down
36 changes: 36 additions & 0 deletions php/geos.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ PHP_METHOD(Geometry, distance);
PHP_METHOD(Geometry, hausdorffDistance);
PHP_METHOD(Geometry, snapTo);
PHP_METHOD(Geometry, node);
PHP_METHOD(Geometry, delaunayTriangulation);

static zend_function_entry Geometry_methods[] = {
PHP_ME(Geometry, __construct, NULL, 0)
Expand Down Expand Up @@ -303,6 +304,7 @@ static zend_function_entry Geometry_methods[] = {
PHP_ME(Geometry, hausdorffDistance, NULL, 0)
PHP_ME(Geometry, snapTo, NULL, 0)
PHP_ME(Geometry, node, NULL, 0)
PHP_ME(Geometry, delaunayTriangulation, NULL, 0)
{NULL, NULL, NULL}
};

Expand Down Expand Up @@ -2582,6 +2584,40 @@ PHP_FUNCTION(GEOSSharedPaths)
setRelay(return_value, geom_out);
}

/**
* GEOSGeometry::delaunayTriangulation([<tolerance>], [<onlyEdges>])
*
* styleArray keys supported:
* 'tolerance'
* Type: double
* snapping tolerance to use for improved robustness
* 'edgesOnly'
* Type: boolean
* if true will return a MULTILINESTRING, otherwise (the default)
* it will return a GEOMETRYCOLLECTION containing triangular POLYGONs.
*/
PHP_METHOD(Geometry, delaunayTriangulation)
{
GEOSGeometry *this;
GEOSGeometry *ret;
double tolerance = 0.0;
zend_bool edgeonly = 0;

this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|db",
&tolerance, &edgeonly) == FAILURE) {
RETURN_NULL();
}

ret = GEOSDelaunayTriangulation(this, tolerance, edgeonly ? 1 : 0);
if ( ! ret ) RETURN_NULL(); /* should get an exception first */

/* return_value is a zval */
object_init_ex(return_value, Geometry_ce_ptr);
setRelay(return_value, ret);
}

/**
* bool GEOSRelateMatch(string matrix, string pattern)
*/
Expand Down
20 changes: 20 additions & 0 deletions php/test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2017,6 +2017,26 @@ public function testGeometry_hausdorffDistance()

}

public function testGeometry_delaunayTriangulation()
{
$reader = new GEOSWKTReader();
$writer = new GEOSWKTWriter();
$writer->setRoundingPrecision(0);

$g = $reader->read('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))');

$b = $g->delaunayTriangulation();
$this->assertEquals(
'GEOMETRYCOLLECTION (POLYGON ((0 1, 0 0, 1 0, 0 1)), POLYGON ((0 1, 1 0, 1 1, 0 1)))'
, $writer->write($b));

$b = $g->delaunayTriangulation(0,true);
$this->assertEquals(
'MULTILINESTRING ((0 1, 1 1), (0 0, 0 1), (0 0, 1 0), (1 0, 1 1), (0 1, 1 0))'
, $writer->write($b));

}

public function testGeometry_snapTo()
{
$reader = new GEOSWKTReader();
Expand Down

0 comments on commit 55f79ad

Please sign in to comment.