home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
-
- (C) 1994 George Taylor
- ----------------------
-
-
- Title: quadtree
-
- Purpose: 2D Space subdivision for quick collision detection
-
- Author: George Taylor
-
- Notes: These procedures must be called from
- a Shared C Library environment (eg call from C/Pascal).
-
- malloc(),free() are used for space allocation.
-
- ***************************************************************************/
-
-
- /* need GeomI2 type */
- #include "<Adhesive$ObjectPath>139.100.geometry"
-
-
- /* abstract quadtree */
- typedef void *Quadtree;
-
-
- /* a point in a quadtree */
- typedef struct Quadtree_Point {
- GeomI2 point; /* the position of the point */
- void *private; /* private pointer associated with a point */
- /* After you have added a point, you can use the elements below to
- get to a point in one of the four quadrants around the point.
- These pointers are NULL if there are no such points.
- */
- struct Quadtree_Point *tr,*tl,*bl,*br;
- } Quadtree_Point;
-
-
-
- /* Procedure: quadtree_New
- *
- * Description: Makes a new emptry Quadtree.
- *
- * Parameters: none
- *
- * Returns: Quadtree - abstract tree of NULL if not enough space
- *
- * Other Info:
- */
- Quadtree quadtree_New(void);
-
-
-
- /* Procedure: quadtree_Build
- *
- * Description: Given an array of GeomI2 points, insert them into a Quadtree.
- *
- * Parameters: Quadtree q
- * Quadtree_Point *points - an array of points
- * A copy of this array is NOT made, it must remain in existence until
- * after quadtree_Empty() or quadtree_Dispose() is called.
- * unsigned int num - number of points in array
- *
- * Returns: int - non-zero if not enough space
- *
- * Other Info: For best performance you should add your points in as few
- * arrays of points as possible. The points in the array should
- * ideally be in a random order.
- * This call takes O(nlogn) time to add n points asssuming
- * good random order.
- * Never add the same array more than once to a Quadtree without
- * calling quadtree_Empty() first.
- */
- int quadtree_Build(Quadtree q, Quadtree_Point *points, unsigned int num);
-
-
-
- /* Procedure: quadtree_Empty
- *
- * Description: Removes all points from a Quadtree.
- *
- * Parameters: Quadtree q
- *
- * Returns: void
- *
- * Other Info: This call takes time proportional to the number of
- * arrays of points.
- */
- void quadtree_Empty(Quadtree q);
-
-
-
- /* Procedure: quadtree_Dispose
- *
- * Description: Disposes of a quadtree (opposite of quadtree_New())
- *
- * Parameters: Quadtree q
- *
- * Returns: void
- *
- * Other Info: This call takes time proportional to the number of
- * arrays of points.
- */
- void quadtree_Dispose(Quadtree q);
-
-
-
- /* type of procedure called when point inside bounding box */
- /* Procedure type: Quadtree_Proc
- *
- * Parameters: Quadtree_Point *point - point which is inside bounding box
- * void *private - private ptr passed to quadtree_Search()
- *
- * Returns: void
- *
- * Other Info: The private ptr with each point is useful for dealing with
- * a collision.
- */
- typedef void (*Quadtree_Proc)(Quadtree_Point *point, void *private);
-
-
-
- /* Procedure: quadtree_Search
- *
- * Description: Given a bounding box and a function to call, test to see
- * if any of the points in the Quadtree intersect with your
- * object.
- *
- * Parameters: Quadtree q - tree to search
- * GeomI2 *min - minimum corner of bounding box
- * GeomI2 *max - maximum corner of bounding box
- * (undefined results if not ordered)
- * Quadtree_Proc furthertest -
- * This procedure is called for every point inside
- * the bounding box.
- * void *private - private ptr passed to furthertest procedure.
- *
- * Returns: void
- *
- * Other Info: The bounding box should not be changed by the function
- * furthertest.
- * This call takes O(lgn) time where n is the number of points.
- */
- void quadtree_Search(Quadtree q, GeomI2 *min, GeomI2 *max,
- Quadtree_Proc furthertest, void *private);
-
-