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

svn_geos at osgeo.org svn_geos at osgeo.org
Wed May 11 05:48:05 EDT 2011


Author: strk
Date: 2011-05-11 02:48:05 -0700 (Wed, 11 May 2011)
New Revision: 3345

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Add Geometry.offsetCurve to PHP binding

Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2011-05-11 09:47:57 UTC (rev 3344)
+++ trunk/php/geos.c	2011-05-11 09:48:05 UTC (rev 3345)
@@ -178,6 +178,7 @@
 PHP_METHOD(Geometry, project);
 PHP_METHOD(Geometry, interpolate);
 PHP_METHOD(Geometry, buffer);
+PHP_METHOD(Geometry, offsetCurve);
 PHP_METHOD(Geometry, envelope);
 PHP_METHOD(Geometry, intersection);
 PHP_METHOD(Geometry, convexHull);
@@ -238,6 +239,7 @@
     PHP_ME(Geometry, project, NULL, 0)
     PHP_ME(Geometry, interpolate, NULL, 0)
     PHP_ME(Geometry, buffer, NULL, 0)
+    PHP_ME(Geometry, offsetCurve, NULL, 0)
     PHP_ME(Geometry, envelope, NULL, 0)
     PHP_ME(Geometry, intersection, NULL, 0)
     PHP_ME(Geometry, convexHull, NULL, 0)
@@ -634,6 +636,80 @@
     setRelay(return_value, ret);
 }
 
+/**
+ * GEOSGeometry::offsetCurve(dist, [<styleArray>])
+ *
+ * styleArray keys supported:
+ *  'quad_segs'
+ *       Type: int 
+ *       Number of segments used to approximate
+ *       a quarter circle (defaults to 8).
+ *  'join'
+ *       Type: long
+ *       Join style (defaults to GEOSBUF_JOIN_ROUND)
+ *  'mitre_limit'
+ *       Type: double
+ *       mitre ratio limit (only affects joins with GEOSBUF_JOIN_MITRE style)
+ *       'miter_limit' is also accepted as a synonym for 'mitre_limit'.
+ */
+PHP_METHOD(Geometry, offsetCurve)
+{
+    GEOSGeometry *this;
+    double dist;
+    GEOSGeometry *ret;
+    static const double default_mitreLimit = 5.0;
+    static const int default_joinStyle = GEOSBUF_JOIN_ROUND;
+    static const int default_quadSegs = 8;
+    long int quadSegs = default_quadSegs;
+    long int joinStyle = default_joinStyle;
+    double mitreLimit = default_mitreLimit;
+    zval *style_val = NULL;
+    zval **data;
+    HashTable *style;
+    char *key;
+    ulong index;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|a",
+            &dist, &style_val) == FAILURE) {
+        RETURN_NULL();
+    }
+
+    if ( style_val )
+    {
+        style = HASH_OF(style_val);
+        while(zend_hash_get_current_key(style, &key, &index, 0)
+              == HASH_KEY_IS_STRING)
+        {
+            if(!strcmp(key, "quad_segs"))
+            {
+                zend_hash_get_current_data(style, (void**)&data);
+                quadSegs = getZvalAsLong(*data);
+            }
+            else if(!strcmp(key, "join"))
+            {
+                zend_hash_get_current_data(style, (void**)&data);
+                joinStyle = getZvalAsLong(*data);
+            }
+            else if(!strcmp(key, "mitre_limit"))
+            {
+                zend_hash_get_current_data(style, (void**)&data);
+                mitreLimit = getZvalAsDouble(*data);
+            }
+
+            zend_hash_move_forward(style);
+        }
+    }
+
+    ret = GEOSOffsetCurve(this, dist, quadSegs, joinStyle, mitreLimit);
+    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, envelope)
 {
     GEOSGeometry *this;

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2011-05-11 09:47:57 UTC (rev 3344)
+++ trunk/php/test/test.php	2011-05-11 09:48:05 UTC (rev 3345)
@@ -519,6 +519,83 @@
 
     }
 
+    public function testGeometry_offsetCurve()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+
+        /* Join styles */
+
+        $g = $reader->read('LINESTRING(0 0, 100 0, 100 100)');
+
+	/* left, round join */
+        $b = $g->offsetCurve(10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_ROUND
+        ));
+        $this->assertEquals(
+'LINESTRING (0 10, 90 10, 90 100)'
+            , $writer->write($b));
+
+	/* right, round join */
+        $b = $g->offsetCurve(-10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_ROUND
+        ));
+        $this->assertEquals(
+'LINESTRING (110 100, 110 0, 107 -7, 100 -10, 0 -10)'
+            , $writer->write($b));
+
+	/* left, bevel join */
+        $b = $g->offsetCurve(10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_BEVEL
+        ));
+        $this->assertEquals(
+'LINESTRING (0 10, 90 10, 90 100)'
+            , $writer->write($b));
+
+	/* right, bevel join */
+        $b = $g->offsetCurve(-10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_BEVEL
+        ));
+        $this->assertEquals(
+'LINESTRING (110 100, 110 0, 100 -10, 0 -10)'
+            , $writer->write($b));
+
+	/* left, mitre join */
+        $b = $g->offsetCurve(10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_MITRE
+        ));
+        $this->assertEquals(
+'LINESTRING (0 10, 90 10, 90 100)'
+            , $writer->write($b));
+
+	/* right, mitre join */
+        $b = $g->offsetCurve(-10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_MITRE
+        ));
+        $this->assertEquals(
+'LINESTRING (110 100, 110 -10, 0 -10)'
+            , $writer->write($b));
+
+	/* right, mitre join limited */
+        $b = $g->offsetCurve(-10, array(
+            'quad_segs' => 2,
+            'join' => GEOSBUF_JOIN_MITRE,
+            'mitre_limit' => 1.0
+        ));
+        $this->assertEquals(
+'LINESTRING (110 100, 109 -5, 105 -9, 0 -10)'
+            , $writer->write($b));
+
+    }
+
     public function testGeometry_envelope()
     {
         $reader = new GEOSWKTReader();



More information about the geos-commits mailing list