]> granicus.if.org Git - postgis/commitdiff
Refactor logic for ST_MakeEnvelope to be reusable in liblwgeom
authorSandro Santilli <strk@kbt.io>
Fri, 2 Dec 2016 08:06:09 +0000 (08:06 +0000)
committerSandro Santilli <strk@kbt.io>
Fri, 2 Dec 2016 08:06:09 +0000 (08:06 +0000)
Patch by Björn Harrtell via
https://git.osgeo.org/gogs/postgis/postgis/pulls/8

git-svn-id: http://svn.osgeo.org/postgis/trunk@15266 b70326c6-7e19-0410-871a-916f4a2858ee

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

index e96839e10cc8a537d339ce16208efbf42d50b7cf..d15afa8b3cb4d073f7977f1382486f206f7683da 100644 (file)
@@ -1356,8 +1356,9 @@ extern LWLINE *lwline_addpoint(LWLINE *line, LWPOINT *point, uint32_t where);
 extern LWLINE *lwline_removepoint(LWLINE *line, uint32_t which);
 extern void lwline_setPoint4d(LWLINE *line, uint32_t which, POINT4D *newpoint);
 extern LWPOLY *lwpoly_from_lwlines(const LWLINE *shell, uint32_t nholes, const LWLINE **holes);
-extern LWPOLY* lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
-extern LWPOLY* lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
+extern LWPOLY *lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2, POINT4D *p3, POINT4D *p4);
+extern LWPOLY *lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2);
+extern LWPOLY *lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior);
 extern LWTRIANGLE *lwtriangle_from_lwline(const LWLINE *shell);
 extern LWMPOINT *lwmpoint_from_lwgeom(const LWGEOM *g); /* Extract the coordinates of an LWGEOM into an LWMPOINT */
 
index 293133060d5e472dac7f1367b7166dd555c80d76..4d2b8a450c22550dc436dbb6d8bf552de0dab7da 100644 (file)
@@ -94,6 +94,28 @@ lwpoly_construct_rectangle(char hasz, char hasm, POINT4D *p1, POINT4D *p2,
        return lwpoly;
 }
 
+LWPOLY *
+lwpoly_construct_envelope(int srid, double x1, double y1, double x2, double y2)
+{
+       POINT4D p1, p2, p3, p4;
+       LWPOLY *poly;
+
+       p1.x = x1;
+       p1.y = y1;
+       p2.x = x1;
+       p2.y = y2;
+       p3.x = x2;
+       p3.y = y2;
+       p4.x = x2;
+       p4.y = y1;
+
+       poly = lwpoly_construct_rectangle(0, 0, &p1, &p2, &p3, &p4);
+       lwgeom_set_srid(lwpoly_as_lwgeom(poly), srid);
+       lwgeom_add_bbox(lwpoly_as_lwgeom(poly));
+
+       return poly;
+}
+
 LWPOLY*
 lwpoly_construct_circle(int srid, double x, double y, double radius, uint32_t segments_per_quarter, char exterior)
 {
index 1b78e5adedc1e08c8fd2d259b33866ca3c05ff7e..ad0899dfdc5b010f5b53299424ff7eb827cb22f8 100644 (file)
@@ -2075,36 +2075,7 @@ Datum ST_MakeEnvelope(PG_FUNCTION_ARGS)
                srid = PG_GETARG_INT32(4);
        }
 
-       pa = (POINTARRAY**)palloc(sizeof(POINTARRAY**));
-       pa[0] = ptarray_construct_empty(0, 0, 5);
-
-       /* 1st point */
-       p.x = x1;
-       p.y = y1;
-       ptarray_append_point(pa[0], &p, LW_TRUE);
-
-       /* 2nd point */
-       p.x = x1;
-       p.y = y2;
-       ptarray_append_point(pa[0], &p, LW_TRUE);
-
-       /* 3rd point */
-       p.x = x2;
-       p.y = y2;
-       ptarray_append_point(pa[0], &p, LW_TRUE);
-
-       /* 4th point */
-       p.x = x2;
-       p.y = y1;
-       ptarray_append_point(pa[0], &p, LW_TRUE);
-
-       /* 5th point */
-       p.x = x1;
-       p.y = y1;
-       ptarray_append_point(pa[0], &p, LW_TRUE);
-
-       poly = lwpoly_construct(srid, NULL, 1, pa);
-       lwgeom_add_bbox(lwpoly_as_lwgeom(poly));
+       poly = lwpoly_construct_envelope(srid, x1, y1, x2, y2);
 
        result = geometry_serialize(lwpoly_as_lwgeom(poly));
        lwpoly_free(poly);