home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 3 / RISC_DISC_3.iso / resources / etexts / gems / gemsv / ch7_4 / polygon.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  1.7 KB  |  61 lines

  1. // -*- C++ -*-
  2. // polygon.h by George Vanecek Jr, June 1994
  3.  
  4. #ifndef _POLYGON_H_
  5. #define _POLYGON_H_
  6.  
  7. #ifndef _LIST_H_
  8. #include "list.h"
  9. #endif
  10.  
  11. #ifndef _PLANE_H_
  12. #include "plane.h"
  13. #endif
  14.  
  15. #ifndef _DEDGE_H_
  16. #include "dedge.h"
  17. #endif
  18.  
  19. class Polygon {
  20. public:
  21.   Polygon( const Counter nPoints, const Point [] );
  22.   Counter    nPoints( ) const { return nDEdges; }
  23.   const Plane& plane( ) const { return supportPlane; }
  24.   DEdge*       first( ) const { return anchor; }
  25.  
  26. private:
  27.   Polygon( DEdge* const, const Plane& );
  28.   Where   classifyPoints( const Plane&, Counter&, DEdge*[] );
  29.   void    addBridge     ( DEdge* const, DEdge* const );
  30.   void    complexCut    ( const Plane&, const Counter, DEdge* const [],
  31.               List<Polygon>&, List<Polygon>& );
  32.   static void sortDEdges( const Counter, DEdge* const [], const Vector& );
  33.   void    maximize      ( DEdge* const );
  34.   void    split         ( const Plane&, DEdge* const );
  35.  
  36.   const Plane supportPlane;
  37.   Counter     nDEdges;        // Number of DEdges in loop...
  38.   DEdge*      anchor;        // Edge Loop
  39.  
  40. friend void split( Polygon*&, const Plane& cut,
  41.            List<Polygon>& above,
  42.            List<Polygon>& on,
  43.            List<Polygon>& below );
  44. };
  45.  
  46. // Juxtapose two strings to form a single identifier:
  47. #define name2(a,b) a##b
  48.  
  49. // Iterate over all Directed Edges within a Polygon member function:
  50. #define forEachDEdge(d) \
  51.        for( DEdgePtr d = first(), name2(last,d) = NULL;\
  52.         d != first() || name2(last,d) == NULL;\
  53.         name2(last,d) = d, d = d->next() )
  54.  
  55. // Iterate over all Directed Edges of a Polygon *g:
  56. #define forEachDEdgeOfPoly(d,g) \
  57.        for( DEdgePtr d = g->first(), name2(last,d) = NULL;\
  58.         d != g->first() || name2(last,d) == NULL;\
  59.         name2(last,d) = d, d = d->next() )
  60. #endif
  61.