Overlap strategy function

/*****************************************************************************
**
** Function name:
**
**      MyShapeOverlap
**
** Description:
**
**      Entrypoint for the SQL routine "Overlap (MyShape,MyShape)
**      returns boolean".  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 the two shapes overlap.
**
*****************************************************************************/

UDREXPORT mi_boolean
MyShapeOverlap (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 (MyShapeOverlap);

    CheckVersion (s1->hdr.version);
    CheckVersion (s2->hdr.version);

    /*
     * First check if bounding boxes overlap.
     */
    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
     * the actual shapes to overlap.
     */
    if (!bbox_overlap)
    {
        retval = MI_FALSE;
        goto OverlapDone;
    }

    /*
     * If bounding boxes overlap and one or both of the objects are
     * R-Tree internal nodes there are no actual geometries to test.
     */
    if (s1->hdr.tag == MyHeaderTag || s2->hdr.tag == MyHeaderTag)
    {
        retval = MI_TRUE;
        goto OverlapDone;
    }

    /*
     * Both objects are 'real' objects or objects on R-Tree leaf nodes.
     */
    
    retval = Dispatch (intersectTable, MI_TRUE, s1, s2);

OverlapDone:

    SHAPE_TRACE_EXIT (MyShapeOverlap);

    return retval;
}