Advertisement
Guest User

Untitled

a guest
Nov 19th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.45 KB | None | 0 0
  1. /*
  2. ===========================================================================
  3.  
  4. Project:   Generic Polygon Clipper
  5.  
  6.            A new algorithm for calculating the difference, intersection,
  7.            exclusive-or or union of arbitrary polygon sets.
  8.  
  9. File:      gpc.h
  10. Author:    Alan Murta (email: gpc@cs.man.ac.uk)
  11. Version:   2.32
  12. Date:      17th December 2004
  13.  
  14. Copyright: (C) Advanced Interfaces Group,
  15.            University of Manchester.
  16.  
  17.            This software is free for non-commercial use. It may be copied,
  18.            modified, and redistributed provided that this copyright notice
  19.            is preserved on all copies. The intellectual property rights of
  20.            the algorithms used reside with the University of Manchester
  21.            Advanced Interfaces Group.
  22.  
  23.            You may not use this software, in whole or in part, in support
  24.            of any commercial product without the express consent of the
  25.            author.
  26.  
  27.            There is no warranty or other guarantee of fitness of this
  28.            software for any purpose. It is provided solely "as is".
  29.  
  30. ===========================================================================
  31. */
  32.  
  33. #ifndef __gpc_h
  34. #define __gpc_h
  35.  
  36. #include <stdio.h>
  37.  
  38.  
  39. /*
  40. ===========================================================================
  41.                                Constants
  42. ===========================================================================
  43. */
  44.  
  45. /* Increase GPC_EPSILON to encourage merging of near coincident edges    */
  46.  
  47. #define GPC_EPSILON (DBL_EPSILON)
  48.  
  49. #define GPC_VERSION "2.32"
  50.  
  51.  
  52. /*
  53. ===========================================================================
  54.                            Public Data Types
  55. ===========================================================================
  56. */
  57.  
  58. typedef enum                        /* Set operation type                */
  59. {
  60.   GPC_DIFF,                         /* Difference                        */
  61.   GPC_INT,                          /* Intersection                      */
  62.   GPC_XOR,                          /* Exclusive or                      */
  63.   GPC_UNION                         /* Union                             */
  64. } gpc_op;
  65.  
  66. typedef struct                      /* Polygon vertex structure          */
  67. {
  68.   double              x;            /* Vertex x component                */
  69.   double              y;            /* vertex y component                */
  70. } gpc_vertex;
  71.  
  72. typedef struct                      /* Vertex list structure             */
  73. {
  74.   int                 num_vertices; /* Number of vertices in list        */
  75.   gpc_vertex         *vertex;       /* Vertex array pointer              */
  76. } gpc_vertex_list;
  77.  
  78. typedef struct                      /* Polygon set structure             */
  79. {
  80.   int                 num_contours; /* Number of contours in polygon     */
  81.   int                *hole;         /* Hole / external contour flags     */
  82.   gpc_vertex_list    *contour;      /* Contour array pointer             */
  83. } gpc_polygon;
  84.  
  85. typedef struct                      /* Tristrip set structure            */
  86. {
  87.   int                 num_strips;   /* Number of tristrips               */
  88.   gpc_vertex_list    *strip;        /* Tristrip array pointer            */
  89. } gpc_tristrip;
  90.  
  91. /*
  92. ===========================================================================
  93.                            TCL compatibility
  94. ===========================================================================
  95. */
  96.  
  97. /*
  98. ===========================================================================
  99.                        Public Function Prototypes
  100. ===========================================================================
  101. */
  102.  
  103. void gpc_read_polygon        (FILE            *infile_ptr,
  104.                               int              read_hole_flags,
  105.                               gpc_polygon     *polygon);
  106.  
  107. void gpc_write_polygon       (FILE            *outfile_ptr,
  108.                               int              write_hole_flags,
  109.                               gpc_polygon     *polygon);
  110.  
  111. void gpc_add_contour         (gpc_polygon     *polygon,
  112.                               gpc_vertex_list *contour,
  113.                               int              hole);
  114.  
  115. void gpc_polygon_clip        (gpc_op           set_operation,
  116.                               gpc_polygon     *subject_polygon,
  117.                               gpc_polygon     *clip_polygon,
  118.                               gpc_polygon     *result_polygon);
  119.  
  120. void gpc_tristrip_clip       (gpc_op           set_operation,
  121.                               gpc_polygon     *subject_polygon,
  122.                               gpc_polygon     *clip_polygon,
  123.                               gpc_tristrip    *result_tristrip);
  124.  
  125. void gpc_polygon_to_tristrip (gpc_polygon     *polygon,
  126.                               gpc_tristrip    *tristrip);
  127.  
  128. void gpc_free_polygon        (gpc_polygon     *polygon);
  129.  
  130. void gpc_free_tristrip       (gpc_tristrip    *tristrip);
  131.  
  132. /*
  133. ===========================================================================
  134.                            TCL compatibility functions
  135. ===========================================================================
  136. */
  137.  
  138. //vertex
  139. gpc_vertex_list   gpc_vertex_list_make        (int n);
  140. int               gpc_vertex_num_get          (gpc_vertex_list *list);
  141. void              gpc_vertex_set              (gpc_vertex_list *list, int n, double x, double y);
  142. #ifdef SWIG
  143. %apply double *OUTPUT {double *x, double *y };
  144. #endif
  145. void              gpc_vertex_get              (gpc_vertex_list *list, int n, double *x, double *y);
  146. #ifdef SWIG
  147. %clear double *x;
  148. %clear double *y;
  149. #endif
  150.  
  151. //polygon
  152. gpc_polygon     * gpc_polygon_empty_make      ();
  153. int               gpc_polygon_num_get         (gpc_polygon *polygon);
  154. gpc_vertex_list   gpc_polygon_vertex_list_get (gpc_polygon *polygon, int n);
  155.  
  156. //functions taken from https://github.com/jraedler/Polygon3
  157. void              gpc_polygon_rotate          (gpc_polygon *p, double alpha, double xc, double yc);
  158. void              gpc_polygon_scale           (gpc_polygon *p, double xs, double ys, double xc, double yc);
  159. void              gpc_polygon_shift           (gpc_polygon *p, double x, double y);
  160.  
  161. //misc
  162. int               gpc_write_polygon_tcl       (const char *filename, gpc_polygon *polygon);
  163. #endif
  164.  
  165. /*
  166. ===========================================================================
  167.                            End of file: gpc.h
  168. ===========================================================================
  169. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement