The shape.h header file

#ifndef SHAPES_BLADE_H
#define SHAPES_BLADE_H

/*****************************************************************************
**
**  Project:
**
**       Shapes.3.0 DataBlade
**
**  File:
**
**       shape.h
**
**  Description:
**
**       This is the header file for the Shapes DataBlade.
**       It contains constants, structure definitions, and function
**       prototypes.
**
*****************************************************************************/

#include <mi.h>

/*
 * Convenience typedefs. Saves typing!
 */
typedef mi_double_precision mi_double;
typedef mi_unsigned_char1   mi_uchar;

/*
 * Datablade version. This string is returned by the ShapeRelease UDR.
 */
#define BLADE_VERSION Shapes DataBlade version 3.0

/*
 * Data structure version. Also serves as a magic number.
 */
#define SHAPE_VERSION 0x53687033      /* 'Shp3' in ascii hex */

/*
 * Subtype tag definitions.
 */
#define MyPointTag    1
#define MyCircleTag   2
#define MyBoxTag      3
#define MyHeaderTag   4
#define LastTag       4

/*
 * Size of spatial key generated by SFCvalue routine.
 */
#define SPATIAL_KEY_BITS 32

/*
 * Mathematical constants
 */
#define MyEpsilon     0.000001
#define Pi            3.14159265358979323846

/*
 * Tracing-related macros
 */
#define TRACE_CLASS Shapes
#define TRACE_LEVEL 20

#define SHAPE_TRACE_ENTER(fn) DPRINTF(TRACE_CLASS, TRACE_LEVEL, (Enter  #fn))
#define SHAPE_TRACE_EXIT(fn)  DPRINTF(TRACE_CLASS, TRACE_LEVEL, (Exit   #fn))
#define SHAPE_TRACE(args)     DPRINTF(TRACE_CLASS, TRACE_LEVEL, args)

/*
 *  UDREXPORT is normally used to export a function from the DataBlade when
 *  linking on NT. UNIX source files should maintain this define in source
 *  for use when porting back to NT.
 */
#ifndef UDREXPORT
#define UDREXPORT
#endif

/*
 * Data structures.
 */

/*
 * The data structures for the supertype (MyShape) and its subtypes
 * (MyPoint, MyBox, MyCircle) all share a common header, called
 * MyShapeHdr. This contains a version number, a tag which indicates
 * what the subtype is, and a bounding box. This structure is also
 * what gets stored in R-Tree internal-node pages, with the tag field
 * set to MyHeaderTag.
 */

typedef struct
{
    mi_integer    version;
    mi_integer    tag;           /* type of this object */
    mi_double     xmin, ymin;    /* bounding box */
    mi_double     xmax, ymax;    
}
MyShapeHdr;

/*
 * Data structures for each subtype's actual geometry data.
 */
typedef struct
{
    mi_double  x;
    mi_double  y;
}
MyPointData;

typedef struct
{
    MyPointData  ll;           /* coordinates of lower left corner */
    MyPointData  ur;           /* coordinates of upper right corner */
}
MyBoxData;

typedef struct
{
    MyPointData  c;            /* center */
    mi_double    r;            /* radius */
}
MyCircleData;


/*
 * MyShape is the structure which contains both the header information
 * and the geometry data; it is the full definition of a shape object.
 */
typedef struct
{
    MyShapeHdr hdr;
    mi_char    data[8];      /* start of subtype geometry data */
}
MyShape;


/*
 * Typedefs for the function dispatch tables.
 */
typedef mi_boolean (*operatorFunction)   (MyShape*, MyShape*);
typedef operatorFunction* functionTable;


/*
 * Function prototypes for the functions in the function dispatch tables.
 */

mi_boolean CircleIBox    (MyShape *obj1, MyShape *obj2);
mi_boolean CircleICircle (MyShape *obj1, MyShape *obj2);
mi_boolean CircleXBox    (MyShape *obj1, MyShape *obj2);
mi_boolean CircleXCircle (MyShape *obj1, MyShape *obj2);
mi_boolean BoxICircle    (MyShape *obj1, MyShape *obj2);
mi_boolean BoxIBox       (MyShape *obj1, MyShape *obj2);
mi_boolean BoxXBox       (MyShape *obj1, MyShape *obj2);
mi_boolean PointXBox     (MyShape *obj1, MyShape *obj2);
mi_boolean PointXCircle  (MyShape *obj1, MyShape *obj2);
mi_boolean PointXPoint   (MyShape *obj1, MyShape *obj2);

mi_boolean Dispatch      (functionTable  tab,
                          mi_boolean     commutative,
                          MyShape       *obj1,
                          MyShape       *obj2);

/*
 * Function dispatch tables.
 * These are essentially NxN matrices (where N is the number of subtypes),
 * with only the upper diagonal of each matrix filled in.
 */

static operatorFunction intersectTable[] =
{
                    /* PointT   = 1                */
    PointXPoint,    /*                PointT   = 1 */
    PointXCircle,   /*                CircleT  = 2 */
    PointXBox,      /*                BoxT     = 3 */
                    /* CircleT  = 2                */
    NULL,
    CircleXCircle,  /*                CircleT  = 2 */
    CircleXBox,     /*                BoxT     = 3 */
                    /* BoxT     = 3                */
    NULL,
    NULL,           
    BoxXBox         /*                BoxT     = 3 */

};

static operatorFunction insideTable[] =
{
                    /* PointT   = 1                */
    NULL,           /*                PointT   = 1 */
    PointXCircle,   /*                CircleT  = 2 */
    PointXBox,      /*                BoxT     = 3 */
                    /* CircleT  = 2                */
    NULL,           /*                PointT   = 1 */
    CircleICircle,  /*                CircleT  = 2 */
    CircleIBox,     /*                BoxT     = 3 */
                    /* BoxT     = 3                */
    NULL,           /*                PointT   = 1 */
    BoxICircle,     /*                CircleT  = 2 */
    BoxIBox         /*                BoxT     = 3 */
};


/*
 * Miscellaneous internal subroutines
 */
mi_lvarchar *MyShapeInCommon    (mi_integer   tag,
                                 mi_lvarchar *text,
                                 MI_FPARAM   *fp);

mi_lvarchar *MyShapeRecvCommon  (mi_integer   tag,
                                 mi_sendrecv *recv_data,
                                 MI_FPARAM   *fp);

void         CheckVersion       (mi_integer   v);


#endif