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 */
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)
{
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);