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

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Aug 4 01:29:17 PDT 2015


Author: strk
Date: 2015-08-04 01:29:17 -0700 (Tue, 04 Aug 2015)
New Revision: 4067

Modified:
   trunk/NEWS
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Expose clipByRect to PHP bindings (#734)

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2015-07-31 14:26:25 UTC (rev 4066)
+++ trunk/NEWS	2015-08-04 08:29:17 UTC (rev 4067)
@@ -6,7 +6,7 @@
   - PHP: Geometry->normalize method
   - GEOS_USE_ONLY_R_API macro support (#695)
   - PHP: WKBReader->read() & WKBWriter::write() methods (Benjamin Morel)
-  - RectangleIntersection, GEOSClipByRect (Mika Heiskanen, Sandro Santilli)
+  - GEOSClipByRect (#699, Mika Heiskanen, Sandro Santilli)
   - CAPI: thread-safe message handling API (#663, Pepijn Van Eeckhoudt)
 - Improvements:
   - Speed-up intersection and difference between geometries

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2015-07-31 14:26:25 UTC (rev 4066)
+++ trunk/php/geos.c	2015-08-04 08:29:17 UTC (rev 4067)
@@ -248,6 +248,7 @@
 PHP_METHOD(Geometry, node);
 PHP_METHOD(Geometry, delaunayTriangulation);
 PHP_METHOD(Geometry, voronoiDiagram);
+PHP_METHOD(Geometry, clipByRect);
 
 static zend_function_entry Geometry_methods[] = {
     PHP_ME(Geometry, __construct, NULL, 0)
@@ -313,6 +314,7 @@
     PHP_ME(Geometry, node, NULL, 0)
     PHP_ME(Geometry, delaunayTriangulation, NULL, 0)
     PHP_ME(Geometry, voronoiDiagram, NULL, 0)
+    PHP_ME(Geometry, clipByRect, NULL, 0)
     {NULL, NULL, NULL}
 };
 
@@ -769,6 +771,30 @@
     setRelay(return_value, ret);
 }
 
+/**
+ * GEOSGeometry GEOSGeometry::clipByRect(xmin,ymin,xmax,ymax)
+ */
+PHP_METHOD(Geometry, clipByRect)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *ret;
+    double xmin,ymin,xmax,ymax;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dddd",
+            &xmin, &ymin, &xmax, &ymax) == FAILURE) {
+        RETURN_NULL();
+    }
+
+    ret = GEOSClipByRect(this, xmin, ymin, xmax, ymax);
+    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);
+}
+
 PHP_METHOD(Geometry, convexHull)
 {
     GEOSGeometry *this;

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2015-07-31 14:26:25 UTC (rev 4066)
+++ trunk/php/test/test.php	2015-08-04 08:29:17 UTC (rev 4067)
@@ -753,6 +753,38 @@
             , $writer->write($gi));
     }
 
+    public function testGeometry_clipByRect()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        /* POINT */
+        $g = $reader->read('POINT(0 0)');
+        $gi = $g->clipByRect(-1,-1,1,1);
+        $this->assertEquals( 'POINT (0 0)'
+            , $writer->write($gi));
+        $gi = $g->clipByRect(1,1,2,2);
+        $this->assertEquals( 'GEOMETRYCOLLECTION EMPTY'
+            , $writer->write($gi));
+
+        /* LINE */
+        $g = $reader->read('LINESTRING(0 0, 10 0)');
+        $gi = $g->clipByRect(1,-1,2,1);
+        $this->assertEquals( 'LINESTRING (1 0, 2 0)'
+            , $writer->write($gi));
+
+        /* POLY */
+        $g = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
+        $gi = $g->clipByRect(1,1,5,5);
+        $this->assertEquals( 'POLYGON ((1 1, 1 5, 5 5, 5 1, 1 1))'
+            , $writer->write($gi));
+        $gi = $g->clipByRect(-1,-1,5,5);
+        $this->assertEquals( 'POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))'
+            , $writer->write($gi));
+
+    }
+
     public function testGeometry_convexHull()
     {
         $reader = new GEOSWKTReader();



More information about the geos-commits mailing list