mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-24 17:12:35 +00:00
Centralize gbox calculations in liblwgeom
git-svn-id: http://svn.osgeo.org/postgis/trunk@13313 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
cb73df91ec
commit
179a06c7a1
|
@ -296,6 +296,17 @@ gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
|
|||
return LW_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
gbox_contains_2d(const GBOX *g1, const GBOX *g2)
|
||||
{
|
||||
if ( ( g2->xmin < g1->xmin ) || ( g2->xmax > g1->xmax ) ||
|
||||
( g2->ymin < g1->ymin ) || ( g2->ymax > g1->ymax ) )
|
||||
{
|
||||
return LW_FALSE;
|
||||
}
|
||||
return LW_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning, this function is only good for x/y/z boxes, used
|
||||
* in unit testing of geodetic box generation.
|
||||
|
|
|
@ -1748,6 +1748,11 @@ extern int gbox_overlaps(const GBOX *g1, const GBOX *g2);
|
|||
*/
|
||||
extern int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2);
|
||||
|
||||
/**
|
||||
* Return #LW_TRUE if the first #GBOX contains the second on the 2d plane, #LW_FALSE otherwise.
|
||||
*/
|
||||
extern int gbox_contains_2d(const GBOX *g1, const GBOX *g2);
|
||||
|
||||
/**
|
||||
* Copy the values of original #GBOX into duplicate.
|
||||
*/
|
||||
|
|
|
@ -1679,8 +1679,7 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
|
|||
bbox2 = (GBOX *)PG_GETARG_POINTER(1);
|
||||
|
||||
/* If bbox1 outside of bbox2, return empty */
|
||||
if ( bbox1->xmin > bbox2->xmax || bbox1->xmax < bbox2->xmin ||
|
||||
bbox1->ymin > bbox2->ymax || bbox1->ymax < bbox2->ymin )
|
||||
if ( ! gbox_overlaps_2d(bbox1, bbox2) )
|
||||
{
|
||||
lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0);
|
||||
lwgeom_free(lwgeom1);
|
||||
|
@ -1691,8 +1690,7 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
|
|||
}
|
||||
|
||||
/* if bbox1 is covered by bbox2, return lwgeom1 */
|
||||
if ( bbox1->xmax <= bbox2->xmax && bbox1->xmin >= bbox2->xmin &&
|
||||
bbox1->ymax <= bbox2->ymax && bbox1->ymin >= bbox2->ymin )
|
||||
if ( gbox_contains_2d(box2, box1) )
|
||||
{
|
||||
lwgeom_free(lwgeom1);
|
||||
PG_RETURN_POINTER(geom1);
|
||||
|
@ -2023,7 +2021,7 @@ Datum overlaps(PG_FUNCTION_ARGS)
|
|||
if ( gserialized_get_gbox_p(geom1, &box1) &&
|
||||
gserialized_get_gbox_p(geom2, &box2) )
|
||||
{
|
||||
if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
|
||||
if ( ! gbox_overlaps_2d(&box1, &box2) )
|
||||
{
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
@ -2098,8 +2096,7 @@ Datum contains(PG_FUNCTION_ARGS)
|
|||
if ( gserialized_get_gbox_p(geom1, &box1) &&
|
||||
gserialized_get_gbox_p(geom2, &box2) )
|
||||
{
|
||||
if ( ( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
|
||||
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ) )
|
||||
if ( ! gbox_contains_2d(&box1, &box2) )
|
||||
{
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
@ -2234,8 +2231,7 @@ Datum containsproperly(PG_FUNCTION_ARGS)
|
|||
if ( gserialized_get_gbox_p(geom1, &box1) &&
|
||||
gserialized_get_gbox_p(geom2, &box2) )
|
||||
{
|
||||
if (( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
|
||||
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
|
||||
if ( ! gbox_contains_2d(&box1, &box2) )
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
||||
|
@ -2324,8 +2320,7 @@ Datum covers(PG_FUNCTION_ARGS)
|
|||
if ( gserialized_get_gbox_p(geom1, &box1) &&
|
||||
gserialized_get_gbox_p(geom2, &box2) )
|
||||
{
|
||||
if (( box2.xmin < box1.xmin ) || ( box2.xmax > box1.xmax ) ||
|
||||
( box2.ymin < box1.ymin ) || ( box2.ymax > box1.ymax ))
|
||||
if ( ! gbox_contains_2d(&box1, &box2) )
|
||||
{
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
@ -2479,8 +2474,7 @@ Datum coveredby(PG_FUNCTION_ARGS)
|
|||
if ( gserialized_get_gbox_p(geom1, &box1) &&
|
||||
gserialized_get_gbox_p(geom2, &box2) )
|
||||
{
|
||||
if ( ( box1.xmin < box2.xmin ) || ( box1.xmax > box2.xmax ) ||
|
||||
( box1.ymin < box2.ymin ) || ( box1.ymax > box2.ymax ) )
|
||||
if ( ! gbox_contains_2d(&box2, &box1) )
|
||||
{
|
||||
PG_RETURN_BOOL(FALSE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue