return LW_TRUE;
}
+int gbox_overlaps_2d(const GBOX *g1, const GBOX *g2)
+{
+
+ /* Make sure our boxes are consistent */
+ if ( FLAGS_GET_GEODETIC(g1->flags) != FLAGS_GET_GEODETIC(g2->flags) )
+ lwerror("gbox_overlaps: cannot compare geodetic and non-geodetic boxes");
+
+ /* Check X/Y first */
+ if ( g1->xmax < g2->xmin || g1->ymax < g2->ymin ||
+ g1->xmin > g2->xmax || g1->ymin > g2->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.
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( box2.xmax < box1.xmin ) PG_RETURN_BOOL(FALSE);
- if ( box2.xmin > box1.xmax ) PG_RETURN_BOOL(FALSE);
- if ( box2.ymax < box1.ymin ) PG_RETURN_BOOL(FALSE);
- if ( box2.ymin > box2.ymax ) PG_RETURN_BOOL(FALSE);
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
+ {
+ PG_RETURN_BOOL(FALSE);
+ }
}
initGEOS(lwnotice, lwgeom_geos_error);
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
- ( box2.ymax < box1.ymin ) || ( box2.ymin > box2.ymax ) )
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
{
PG_RETURN_BOOL(FALSE);
}
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
- ( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ) )
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
{
PG_RETURN_BOOL(FALSE);
}
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
- ( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ) )
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
{
PG_RETURN_BOOL(FALSE);
}
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
- ( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ) )
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
{
PG_RETURN_BOOL(TRUE);
}
PG_RETURN_BOOL(TRUE);
/*
- * short-circuit: Loose test, if they don't intersect they
- * sure can't be equal.
+ * short-circuit: Loose test, if geom2 bounding box does not overlap
+ * geom1 bounding box we can prematurely return FALSE.
*/
if ( gserialized_get_gbox_p(geom1, &box1) &&
gserialized_get_gbox_p(geom2, &box2) )
{
- if ( ( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
- ( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ) )
+ if ( gbox_overlaps_2d(&box1, &box2) == LW_FALSE )
{
PG_RETURN_BOOL(FALSE);
}