1 /*
2  * This file is a part of the C port of the Poly2Tri library
3  * Porting to C done by (c) Barak Itkin <lightningismyname@gmail.com>
4  * http://code.google.com/p/poly2tri-c/
5  *
6  * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
7  * http://code.google.com/p/poly2tri/
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without modification,
12  * are permitted provided that the following conditions are met:
13  *
14  * * Redistributions of source code must retain the above copyright notice,
15  *   this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above copyright notice,
17  *   this list of conditions and the following disclaimer in the documentation
18  *   and/or other materials provided with the distribution.
19  * * Neither the name of Poly2Tri nor the names of its contributors may be
20  *   used to endorse or promote products derived from this software without specific
21  *   prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef __P2TC_P2T_SWEEP_CONTEXT_H__
37 #define __P2TC_P2T_SWEEP_CONTEXT_H__
38 
39 #include "../common/poly2tri-private.h"
40 #include "../common/shapes.h"
41 #include "advancing_front.h"
42 
43 /* Inital triangle factor, seed triangle will extend 30% of
44  * PointSet width to both left and right. */
45 #define kAlpha 0.3
46 
47 struct P2tSweepContextBasin_
48 {
49   P2tNode* left_node;
50   P2tNode* bottom_node;
51   P2tNode* right_node;
52   double width;
53   gboolean left_highest;
54 };
55 
56 void p2t_sweepcontext_basin_init (P2tSweepContextBasin* THIS);
57 void p2t_sweepcontext_basin_clear (P2tSweepContextBasin* THIS);
58 
59 struct P2tSweepContextEdgeEvent_
60 {
61   P2tEdge* constrained_edge;
62   gboolean right;
63 };
64 
65 void p2t_sweepcontext_edgeevent_init (P2tSweepContextEdgeEvent* THIS);
66 
67 struct SweepContext_
68 {
69   P2tEdgePtrArray edge_list;
70 
71   P2tSweepContextBasin basin;
72   P2tSweepContextEdgeEvent edge_event;
73 
74   P2tTrianglePtrArray triangles_;
75   P2tTrianglePtrList map_;
76   P2tPointPtrArray points_;
77 
78   /** Advancing front */
79   P2tAdvancingFront* front_;
80   /** head point used with advancing front */
81   P2tPoint* head_;
82   /** tail point used with advancing front */
83   P2tPoint* tail_;
84 
85   P2tNode *af_head_, *af_middle_, *af_tail_;
86 };
87 
88 /** Constructor */
89 void p2t_sweepcontext_init (P2tSweepContext* THIS, P2tPointPtrArray polyline);
90 P2tSweepContext* p2t_sweepcontext_new (P2tPointPtrArray polyline);
91 
92 /** Destructor */
93 void p2t_sweepcontext_destroy (P2tSweepContext* THIS);
94 void p2t_sweepcontext_delete (P2tSweepContext* THIS);
95 
96 void p2t_sweepcontext_set_head (P2tSweepContext *THIS, P2tPoint* p1);
97 
98 P2tPoint* p2t_sweepcontext_head (P2tSweepContext *THIS);
99 
100 void p2t_sweepcontext_set_tail (P2tSweepContext *THIS, P2tPoint* p1);
101 
102 P2tPoint* p2t_sweepcontext_tail (P2tSweepContext *THIS);
103 
104 int p2t_sweepcontext_point_count (P2tSweepContext *THIS);
105 
106 P2tNode* p2t_sweepcontext_locate_node (P2tSweepContext *THIS, P2tPoint* point);
107 
108 void p2t_sweepcontext_remove_node (P2tSweepContext *THIS, P2tNode* node);
109 
110 void p2t_sweepcontext_create_advancingfront (P2tSweepContext *THIS, P2tNodePtrArray nodes);
111 
112 /** Try to map a node to all sides of this triangle that don't have a neighbor */
113 void p2t_sweepcontext_map_triangle_to_nodes (P2tSweepContext *THIS, P2tTriangle* t);
114 
115 void p2t_sweepcontext_add_to_map (P2tSweepContext *THIS, P2tTriangle* triangle);
116 
117 P2tPoint* p2t_sweepcontext_get_point (P2tSweepContext *THIS, const int index);
118 
119 P2tPoint* SweepContext_GetPoints (P2tSweepContext *THIS);
120 
121 void p2t_sweepcontext_remove_from_map (P2tSweepContext *THIS, P2tTriangle* triangle);
122 
123 void p2t_sweepcontext_add_hole (P2tSweepContext *THIS, P2tPointPtrArray polyline);
124 
125 void p2t_sweepcontext_add_point (P2tSweepContext *THIS, P2tPoint* point);
126 
127 P2tAdvancingFront* p2t_sweepcontext_front (P2tSweepContext *THIS);
128 
129 void p2t_sweepcontext_mesh_clean (P2tSweepContext *THIS, P2tTriangle* triangle);
130 
131 P2tTrianglePtrArray p2t_sweepcontext_get_triangles (P2tSweepContext *THIS);
132 P2tTrianglePtrList p2t_sweepcontext_get_map (P2tSweepContext *THIS);
133 
134 void p2t_sweepcontext_init_triangulation (P2tSweepContext *THIS);
135 void p2t_sweepcontext_init_edges (P2tSweepContext *THIS, P2tPointPtrArray polyline);
136 
137 #endif
138