/*****************************************************************************
**
** Function name:
**
** MyShapeWithin
**
** Description:
**
** Entrypoint for the SQL routine "Within (MyShape,MyShape)
** returns integer". This is an Rtree strategy function.
**
** Special Comments:
**
** Because MyShape and its subtypes are variable length opaque
** datatypes, the UDT instances are passed in from the server
** wrapped in mi_lvarchars.
**
** Parameters:
**
** mi_lvarchar *in1, *in2 UDT instances to be spatially compared.
** MI_FPARAM *fp UDR function parameter & state info.
**
** Return value:
**
** mi_boolean True if
**
*****************************************************************************/
UDREXPORT mi_boolean
MyShapeWithin (mi_lvarchar *shape1,
mi_lvarchar *shape2,
MI_FPARAM *fp)
{
mi_boolean bbox_overlap;
mi_boolean retval;
MyShape *s1 = (MyShape *) mi_get_vardata (shape1);
MyShape *s2 = (MyShape *) mi_get_vardata (shape2);
SHAPE_TRACE_ENTER (MyShapeWithin);
CheckVersion (s1->hdr.version);
CheckVersion (s2->hdr.version);
/*
* If shape2 is a non-region shape (e.g. point) it is not
* possible for shape1 to be within shape2 so return NULL.
*/
switch (s2->hdr.tag)
{
case MyHeaderTag:
case MyBoxTag:
case MyCircleTag:
break;
case MyPointTag:
default:
mi_fp_setreturnisnull((fp), 0, MI_TRUE);
return MI_FALSE;
}
bbox_overlap = (s1->hdr.xmin <= s2->hdr.xmax &&
s2->hdr.xmin <= s1->hdr.xmax &&
s1->hdr.ymin <= s2->hdr.ymax &&
s2->hdr.ymin <= s1->hdr.ymax);
/*
* If bounding boxes do not overlap then it is not possible for
* shape1 to be within shape2.
*/
if (!bbox_overlap)
{
retval = MI_FALSE;
goto WithinDone;
}
/*
* If bounding boxes overlap, and one or both objects are internal
* index nodes, we cannot rule out the possibility that objects
* in the subtree below this node satisfy the spatial test,
* so return true.
*/
if (s1->hdr.tag == MyHeaderTag || s2->hdr.tag == MyHeaderTag)
{
retval = MI_TRUE;
goto WithinDone;
}
/*
* Both objects are actual shapes so perform an exact geometric test.
*/
retval = Dispatch (insideTable, MI_FALSE, s1, s2);
WithinDone:
SHAPE_TRACE_EXIT (MyShapeWithin);
return retval;
}