]> granicus.if.org Git - postgis/commitdiff
Move some ptarray functions out of postgis and back into liblwgeom from silly old...
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 28 Sep 2012 20:30:26 +0000 (20:30 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 28 Sep 2012 20:30:26 +0000 (20:30 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10338 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwgeom.c
postgis/lwgeom_functions_basic.c

index b1c7a01ac55c66498f4ad487c8f9c4b8845ca5ff..767aade1a3f5b7654b86f7785dce13bf532919b3 100644 (file)
@@ -1077,7 +1077,7 @@ extern double ptarray_length(const POINTARRAY *pts);
 extern int pt_in_ring_2d(const POINT2D *p, const POINTARRAY *ring);
 extern int pt_in_poly_2d(const POINT2D *p, const LWPOLY *poly);
 extern int azimuth_pt_pt(const POINT2D *p1, const POINT2D *p2, double *ret);
-extern int lwgeom_pt_inside_circle(POINT2D *p, double cx, double cy, double rad);
+extern int lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad);
 extern void lwgeom_reverse(LWGEOM *lwgeom);
 extern void lwline_reverse(LWLINE *line);
 extern void lwpoly_reverse(LWPOLY *poly);
index 60e055d055cc7d5334eecbbc7fc5775c009fd41b..e03cb5330a78c72a0a3c4e9ee3f60508428201a3 100644 (file)
@@ -528,6 +528,26 @@ lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
 
 }
 
+int
+lwpoint_inside_circle(const LWPOINT *p, double cx, double cy, double rad)
+{
+       POINT2D center;
+       POINT2D pt;
+
+       if ( ! p || ! p->point )
+               return LW_FALSE;
+               
+       getPoint2d_p(p->point, 0, &pt);
+
+       center.x = cx;
+       center.y = cy;
+
+       if ( distance2d_pt_pt(&pt, &center) < rad ) 
+               return LW_TRUE;
+
+       return LW_FALSE;
+}
+
 void
 lwgeom_drop_bbox(LWGEOM *lwgeom)
 {
index c6106fd9f4ec51e2722f41542e027779e99ba794..df7f4f876618a89ada261d56bb1c00435b490dcf 100644 (file)
@@ -1027,22 +1027,24 @@ Datum LWGEOM_inside_circle_point(PG_FUNCTION_ARGS)
        double cx = PG_GETARG_FLOAT8(1);
        double cy = PG_GETARG_FLOAT8(2);
        double rr = PG_GETARG_FLOAT8(3);
-       LWPOINT *point;
-       POINT2D pt;
+       LWPOINT *lwpoint;
+       LWGEOM *lwgeom;
+       int inside;
 
        geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       point = lwgeom_as_lwpoint(lwgeom_from_gserialized(geom));
-       if ( point == NULL )
+       lwgeom = lwgeom_from_gserialized(geom);
+       lwpoint = lwgeom_as_lwpoint(lwgeom);
+       if ( lwpoint == NULL || lwgeom_is_empty(lwgeom) )
        {
                PG_FREE_IF_COPY(geom, 0);
                PG_RETURN_NULL(); /* not a point */
        }
 
-       getPoint2d_p(point->point, 0, &pt);
+       inside = lwpoint_inside_circle(lwpoint, cx, cy, rr);
+       lwpoint_free(lwpoint);
 
        PG_FREE_IF_COPY(geom, 0);
-
-       PG_RETURN_BOOL(lwgeom_pt_inside_circle(&pt, cx, cy, rr));
+       PG_RETURN_BOOL(inside);
 }
 
 /**