/[zanavi_public1]/navit/navit/maptool/refine/mesh-action.c
ZANavi

Contents of /navit/navit/maptool/refine/mesh-action.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 2 months ago) by zoff99
File MIME type: text/plain
File size: 6299 byte(s)
new map version, lots of fixes and experimental new features
1 /*
2 * This file is a part of Poly2Tri-C
3 * (c) Barak Itkin <lightningismyname@gmail.com>
4 * http://code.google.com/p/poly2tri-c/
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without modification,
9 * are permitted provided that the following conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 * * Neither the name of Poly2Tri nor the names of its contributors may be
17 * used to endorse or promote products derived from this software without specific
18 * prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <glib.h>
34 #include "point.h"
35 #include "edge.h"
36 #include "mesh.h"
37 #include "vedge.h"
38 #include "vtriangle.h"
39 #include "mesh-action.h"
40
41 static P2trMeshAction*
42 p2tr_mesh_action_point (P2trPoint *point,
43 gboolean added)
44 {
45 P2trMeshAction *self = g_slice_new (P2trMeshAction);
46 self->type = P2TR_MESH_ACTION_POINT;
47 self->added = added;
48 self->refcount = 1;
49 self->action.action_point.point = p2tr_point_ref (point);
50 return self;
51 }
52
53 static void
54 p2tr_mesh_action_point_free (P2trMeshAction *self)
55 {
56 g_assert (self->type == P2TR_MESH_ACTION_POINT);
57 p2tr_point_unref (self->action.action_point.point);
58 g_slice_free (P2trMeshAction, self);
59 }
60
61 static void
62 p2tr_mesh_action_point_undo (P2trMeshAction *self,
63 P2trMesh *mesh)
64 {
65 g_assert (self->type == P2TR_MESH_ACTION_POINT);
66 if (self->added)
67 p2tr_point_remove (self->action.action_point.point);
68 else
69 p2tr_mesh_add_point (mesh, self->action.action_point.point);
70 }
71
72 P2trMeshAction*
73 p2tr_mesh_action_new_point (P2trPoint *point)
74 {
75 return p2tr_mesh_action_point (point, TRUE);
76 }
77
78 P2trMeshAction*
79 p2tr_mesh_action_del_point (P2trPoint *point)
80 {
81 return p2tr_mesh_action_point (point, FALSE);
82 }
83
84 static P2trMeshAction*
85 p2tr_mesh_action_edge (P2trEdge *edge,
86 gboolean added)
87 {
88 P2trMeshAction *self = g_slice_new (P2trMeshAction);
89 self->type = P2TR_MESH_ACTION_EDGE;
90 self->added = added;
91 self->refcount = 1;
92 self->action.action_edge.vedge = p2tr_vedge_new2 (edge);
93 self->action.action_edge.constrained = edge->constrained;
94 return self;
95 }
96
97 static void
98 p2tr_mesh_action_edge_free (P2trMeshAction *self)
99 {
100 g_assert (self->type == P2TR_MESH_ACTION_EDGE);
101 p2tr_vedge_unref (self->action.action_edge.vedge);
102 g_slice_free (P2trMeshAction, self);
103 }
104
105 static void
106 p2tr_mesh_action_edge_undo (P2trMeshAction *self,
107 P2trMesh *mesh)
108 {
109 g_assert (self->type == P2TR_MESH_ACTION_EDGE);
110
111 if (self->added)
112 p2tr_vedge_remove (self->action.action_edge.vedge);
113 else
114 p2tr_vedge_create (self->action.action_edge.vedge);
115 }
116
117 P2trMeshAction*
118 p2tr_mesh_action_new_edge (P2trEdge *edge)
119 {
120 return p2tr_mesh_action_edge (edge, TRUE);
121 }
122
123 P2trMeshAction*
124 p2tr_mesh_action_del_edge (P2trEdge *edge)
125 {
126 return p2tr_mesh_action_edge (edge, FALSE);
127 }
128
129 static P2trMeshAction*
130 p2tr_mesh_action_triangle (P2trTriangle *tri,
131 gboolean added)
132 {
133 P2trMeshAction *self = g_slice_new (P2trMeshAction);
134 self->type = P2TR_MESH_ACTION_TRIANGLE;
135 self->added = added;
136 self->refcount = 1;
137 self->action.action_tri.vtri = p2tr_vtriangle_new (tri);
138 return self;
139 }
140
141 static void
142 p2tr_mesh_action_triangle_free (P2trMeshAction *self)
143 {
144 g_assert (self->type == P2TR_MESH_ACTION_TRIANGLE);
145 p2tr_vtriangle_unref (self->action.action_tri.vtri);
146 g_slice_free (P2trMeshAction, self);
147 }
148
149 static void
150 p2tr_mesh_action_triangle_undo (P2trMeshAction *self,
151 P2trMesh *mesh)
152 {
153 g_assert (self->type == P2TR_MESH_ACTION_TRIANGLE);
154
155 if (self->added)
156 p2tr_vtriangle_remove (self->action.action_tri.vtri);
157 else
158 p2tr_vtriangle_create (self->action.action_tri.vtri);
159 }
160
161 P2trMeshAction*
162 p2tr_mesh_action_new_triangle (P2trTriangle *tri)
163 {
164 return p2tr_mesh_action_triangle (tri, TRUE);
165 }
166
167 P2trMeshAction*
168 p2tr_mesh_action_del_triangle (P2trTriangle *tri)
169 {
170 return p2tr_mesh_action_triangle (tri, FALSE);
171 }
172
173 P2trMeshAction*
174 p2tr_mesh_action_ref (P2trMeshAction *self)
175 {
176 ++self->refcount;
177 return self;
178 }
179
180 void
181 p2tr_mesh_action_free (P2trMeshAction *self)
182 {
183 switch (self->type)
184 {
185 case P2TR_MESH_ACTION_POINT:
186 p2tr_mesh_action_point_free (self);
187 break;
188 case P2TR_MESH_ACTION_EDGE:
189 p2tr_mesh_action_edge_free (self);
190 break;
191 case P2TR_MESH_ACTION_TRIANGLE:
192 p2tr_mesh_action_triangle_free (self);
193 break;
194 default:
195 g_assert_not_reached ();
196 break;
197 }
198 }
199
200 void
201 p2tr_mesh_action_unref (P2trMeshAction *self)
202 {
203 g_assert (self->refcount > 0);
204 if (--self->refcount == 0)
205 p2tr_mesh_action_free (self);
206 }
207
208 void
209 p2tr_mesh_action_undo (P2trMeshAction *self,
210 P2trMesh *mesh)
211 {
212 switch (self->type)
213 {
214 case P2TR_MESH_ACTION_POINT:
215 p2tr_mesh_action_point_undo (self, mesh);
216 break;
217 case P2TR_MESH_ACTION_EDGE:
218 p2tr_mesh_action_edge_undo (self, mesh);
219 break;
220 case P2TR_MESH_ACTION_TRIANGLE:
221 p2tr_mesh_action_triangle_undo (self, mesh);
222 break;
223 default:
224 g_assert_not_reached ();
225 break;
226 }
227 }
228

   
Visit the ZANavi Wiki