Size support function

/*****************************************************************************
**
** Function name:
**
**      MyShapeSize
**
** Description:
**
**      This is an R-Tree support function which enables
**      the server to maintain an R-Tree index.  It computes the
**      size of an object's bounding box.
**
** Special Comments:
**
**      Because MyShape and its subtypes are variable length opaque 
**      datatypes, the UDT instance is passed in from the server 
**      wrapped in an mi_lvarchar.
**
** Parameters:
**
**      mi_lvarchar *shape       MyShape UDT whose bbox size is to be computed.
**      mi_double   *bbox_size   Return value, size of UDT's bbox.
**      MI_FPARAM   *fp          UDR function parameter & state info.
**
** Return value:
**
**      mi_integer               MI_OK if success, MI_ERROR if problems.
**
*****************************************************************************/

UDREXPORT mi_integer
MyShapeSize (mi_lvarchar *shape,
             mi_double   *bbox_size,
             MI_FPARAM   *fp)
{
    mi_double   length;
    mi_double   width;
    MyShapeHdr *hdr = (MyShapeHdr *) mi_get_vardata (shape);

    SHAPE_TRACE_ENTER (MyShapeSize);

    length = hdr->xmax - hdr->xmin;
    width  = hdr->ymax - hdr->ymin;

    if (length < 0 && width < 0)
    {
        /*
         * No intersection case.  
         * R-Tree preceded this Size() call with an Inter() call that
         * detected no intersection between two bounding boxes.
         */
        *bbox_size = 0;
    }
    else
    {
        /*
         * Normal case.
         * Take care to always return a different value as a bounding box
         * expands or shrinks.  The following algorithm (area + extent) will
         * correctly account for zero-width or zero-height bounding boxes.
         */

        *bbox_size =  (length * width) + (length + width);
    }
        
    SHAPE_TRACE_EXIT (MyShapeSize);

    return MI_OK;
}