[geos-commits] r3834 - in trunk: . php php/test

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Jul 11 01:21:54 PDT 2013


Author: strk
Date: 2013-07-11 01:21:54 -0700 (Thu, 11 Jul 2013)
New Revision: 3834

Modified:
   trunk/NEWS
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Expose Delaunay triangulation to PHP API (#567)

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2013-07-11 07:36:28 UTC (rev 3833)
+++ trunk/NEWS	2013-07-11 08:21:54 UTC (rev 3834)
@@ -2,7 +2,7 @@
 ????-??-??
 
 - 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

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2013-07-11 07:36:28 UTC (rev 3833)
+++ trunk/php/geos.c	2013-07-11 08:21:54 UTC (rev 3834)
@@ -241,6 +241,7 @@
 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)
@@ -303,6 +304,7 @@
     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}
 };
 
@@ -2583,6 +2585,40 @@
 }
 
 /**
+ * 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)
  */
 PHP_FUNCTION(GEOSRelateMatch)

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2013-07-11 07:36:28 UTC (rev 3833)
+++ trunk/php/test/test.php	2013-07-11 08:21:54 UTC (rev 3834)
@@ -2017,6 +2017,26 @@
 
     }
 
+    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();



More information about the geos-commits mailing list