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

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Jun 20 17:00:29 EDT 2010


Author: strk
Date: 2010-06-20 21:00:29 +0000 (Sun, 20 Jun 2010)
New Revision: 3037

Modified:
   trunk/php/geos.c
   trunk/php/test/test.php
Log:
Relational operators + equalsExact


Modified: trunk/php/geos.c
===================================================================
--- trunk/php/geos.c	2010-06-20 19:05:57 UTC (rev 3036)
+++ trunk/php/geos.c	2010-06-20 21:00:29 UTC (rev 3037)
@@ -185,6 +185,15 @@
 PHP_METHOD(Geometry, relate); 
 PHP_METHOD(Geometry, simplify); /* also does topology-preserving */
 PHP_METHOD(Geometry, extractUniquePoints); 
+PHP_METHOD(Geometry, disjoint);
+PHP_METHOD(Geometry, touches);
+PHP_METHOD(Geometry, intersects);
+PHP_METHOD(Geometry, crosses);
+PHP_METHOD(Geometry, within);
+PHP_METHOD(Geometry, contains);
+PHP_METHOD(Geometry, overlaps);
+PHP_METHOD(Geometry, equals);
+PHP_METHOD(Geometry, equalsExact);
 
 PHP_METHOD(Geometry, numGeometries);
 
@@ -206,6 +215,15 @@
     PHP_ME(Geometry, relate, NULL, 0)
     PHP_ME(Geometry, simplify, NULL, 0)
     PHP_ME(Geometry, extractUniquePoints, NULL, 0)
+    PHP_ME(Geometry, disjoint, NULL, 0)
+    PHP_ME(Geometry, touches, NULL, 0)
+    PHP_ME(Geometry, intersects, NULL, 0)
+    PHP_ME(Geometry, crosses, NULL, 0)
+    PHP_ME(Geometry, within, NULL, 0)
+    PHP_ME(Geometry, contains, NULL, 0)
+    PHP_ME(Geometry, overlaps, NULL, 0)
+    PHP_ME(Geometry, equals, NULL, 0)
+    PHP_ME(Geometry, equalsExact, NULL, 0)
 
     PHP_ME(Geometry, numGeometries, NULL, 0)
     {NULL, NULL, NULL}
@@ -1068,8 +1086,252 @@
     setRelay(return_value, ret);
 }
 
+/**
+ * bool GEOSGeometry::disjoint(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, disjoint)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
 
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
 
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSDisjoint(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::touches(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, touches)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSTouches(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::intersects(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, intersects)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSIntersects(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::crosses(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, crosses)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSCrosses(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::within(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, within)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSWithin(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::contains(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, contains)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSContains(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::overlaps(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, overlaps)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zobj)
+            == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSOverlaps(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::equals(GEOSGeometry)
+ */
+PHP_METHOD(Geometry, equals)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",
+        &zobj) == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSEquals(this, other);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+/**
+ * bool GEOSGeometry::equalsExact(GEOSGeometry)
+ * bool GEOSGeometry::equalsExact(GEOSGeometry, double tolerance)
+ */
+PHP_METHOD(Geometry, equalsExact)
+{
+    GEOSGeometry *this;
+    GEOSGeometry *other;
+    int ret;
+    double tolerance = 0;
+    zend_bool retBool;
+    zval *zobj;
+
+    this = (GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);
+
+    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|d",
+        &zobj, &tolerance) == FAILURE) {
+        RETURN_NULL();
+    }
+    other = getRelay(zobj, Geometry_ce_ptr);
+
+    ret = GEOSEqualsExact(this, other, tolerance);
+    if ( ret == 2 ) RETURN_NULL(); /* should get an exception first */
+
+    /* return_value is a zval */
+    retBool = ret;
+    RETURN_BOOL(retBool);
+}
+
+
 /* ------ Initialization / Deinitialization / Meta ------------------ */
 
 /* per-module initialization */

Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php	2010-06-20 19:05:57 UTC (rev 3036)
+++ trunk/php/test/test.php	2010-06-20 21:00:29 UTC (rev 3037)
@@ -1024,4 +1024,116 @@
 'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)'
             , $writer->write($gs));
     }
+
+    public function testGeometry_relationalOps()
+    {
+        $reader = new GEOSWKTReader();
+        $writer = new GEOSWKTWriter();
+        $writer->setRoundingPrecision(0);
+
+        $g1 = $reader->read('POINT(0 0)');
+        $g2 = $reader->read('POINT(0 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); /* no bounds, can't touch */
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertTrue( $g1->within($g2) );
+        $this->assertTrue( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertTrue( $g1->equals($g2) );
+        $this->assertTrue( $g1->equalsExact($g2) );
+
+        $g1 = $reader->read('POINT(0 0)');
+        $g2 = $reader->read('LINESTRING(0 0, 10 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertTrue( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertFalse( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 10) );
+
+        $g1 = $reader->read('POINT(5 0)');
+        $g2 = $reader->read('LINESTRING(0 0, 10 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertTrue( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 10) );
+
+        $g1 = $reader->read('LINESTRING(5 -5, 5 5)');
+        $g2 = $reader->read('LINESTRING(0 0, 10 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertTrue( $g1->crosses($g2) );
+        $this->assertFalse( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 1) );
+
+        $g1 = $reader->read('LINESTRING(5 0, 15 0)');
+        $g2 = $reader->read('LINESTRING(0 0, 10 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertFalse( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertTrue( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 1) );
+
+        $g1 = $reader->read('LINESTRING(0 0, 5 0, 10 0)');
+        $g2 = $reader->read('LINESTRING(0 0, 10 0)');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertTrue( $g1->within($g2) );
+        $this->assertTrue( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertTrue( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 1) );
+
+        $g1 = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
+        $g2 = $reader->read('POLYGON((5 -5, 5 5, 15 5, 15 -5, 5 -5))');
+
+        $this->assertFalse( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertTrue( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertFalse( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertTrue( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 1) );
+
+        $g1 = $reader->read('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
+        $g2 = $reader->read('POINT(15 15)');
+
+        $this->assertTrue( $g1->disjoint($g2) );
+        $this->assertFalse( $g1->touches($g2) ); 
+        $this->assertFalse( $g1->intersects($g2) );
+        $this->assertFalse( $g1->crosses($g2) );
+        $this->assertFalse( $g1->within($g2) );
+        $this->assertFalse( $g1->contains($g2) );
+        $this->assertFalse( $g1->overlaps($g2) );
+        $this->assertFalse( $g1->equals($g2) );
+        $this->assertFalse( $g1->equalsExact($g2, 1) );
+
+    }
 }



More information about the geos-commits mailing list