1 /*
2 * Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3 * Applied Mathematics, Norway.
4 *
5 * Contact information: E-mail: tor.dokken@sintef.no
6 * SINTEF ICT, Department of Applied Mathematics,
7 * P.O. Box 124 Blindern,
8 * 0314 Oslo, Norway.
9 *
10 * This file is part of SISL.
11 *
12 * SISL is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Affero General Public License as
14 * published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * SISL is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Affero General Public License for more details.
21 *
22 * You should have received a copy of the GNU Affero General Public
23 * License along with SISL. If not, see
24 * <http://www.gnu.org/licenses/>.
25 *
26 * In accordance with Section 7(b) of the GNU Affero General Public
27 * License, a covered work must retain the producer line in every data
28 * file that is created or manipulated using SISL.
29 *
30 * Other Usage
31 * You can be released from the requirements of the license by purchasing
32 * a commercial license. Buying such a license is mandatory as soon as you
33 * develop commercial activities involving the SISL library without
34 * disclosing the source code of your own applications.
35 *
36 * This file may be used in accordance with the terms contained in a
37 * written agreement between you and SINTEF ICT.
38 */
39
40 #include "sisl-copyright.h"
41
42 /*
43 *
44 * $Id: sh6idkpt.c,v 1.2 2001-03-19 15:59:08 afr Exp $
45 *
46 */
47
48
49 #define S6IDKPT
50
51
52 #include "sislP.h"
53
54 #if defined(SISLNEEDPROTOTYPES)
55 void
sh6idkpt(SISLIntdat ** pintdat,SISLIntpt ** pintpt,int join,int * jstat)56 sh6idkpt (SISLIntdat ** pintdat, SISLIntpt ** pintpt, int join, int *jstat)
57 #else
58 void
59 sh6idkpt (pintdat, pintpt, join, jstat)
60 SISLIntdat **pintdat;
61 SISLIntpt **pintpt;
62 int join;
63 int *jstat;
64 #endif
65
66
67 /*
68 *********************************************************************
69 *
70 *********************************************************************
71 *
72 * PURPOSE : To remove an intersection point pintpt from pintdat.
73 * pintpt is removed from all lists which it lies in if any.
74 * If pintpt has exactly two neighbours, they are joined
75 * together if the option join is selected.
76 * After disconnection is done, pintpt is killed. If pintdat
77 * is empty pintdat is killed and set to SISL_NULL.
78 *
79 *
80 *
81 * INPUT/OUTPUT:pintpt - Pointer to a pointer to new intersection point.
82 * pintdat - Pointer to a pointer to intersection data.
83 * join - Flag for whether the lists are repaired.
84 * --ALA-- and kill all help-points connected
85 * to this point if this point is a main point.
86 *
87 *
88 * OUTPUT : jstat - status messages
89 * = 2 : Pintpt is not in pintdat.
90 * = 1 : Pintpt is SISL_NULL
91 * = 0 : OK!
92 * < 0 : error
93 *
94 *
95 * METHOD :
96 *
97 *
98 * REFERENCES :
99 *
100 *-
101 * CALLS : sh6err - Gives error message.
102 * freeIntpt - free instant of intpt structure.
103 *
104 * WRITTEN BY : Ulf J. Krystad, 06.91.
105 *
106 *********************************************************************
107 */
108 {
109 int ki; /* Counters. */
110 int knum;
111 int kstat = 0;
112 SISLIntpt *pnhbr_1 = SISL_NULL; /* First neighbour */
113 SISLIntpt *pnhbr_2 = SISL_NULL; /* Second neighbour */
114 SISLIntpt *help_pt = SISL_NULL; /* help point */
115 int crv_dir_1 = 0;
116 int crv_dir_2 = 0;
117 int index1 = 0;
118 int index2 = 0;
119 int dummy;
120 /* ------------------------------------------------*/
121
122 *jstat = 0;
123
124 if ((*pintpt) == SISL_NULL)
125 {
126 *jstat = 1;
127 goto out;
128 }
129
130 if (join)
131 {
132 /* ALA-- We first remove all help point if this point is a main point. */
133 if (sh6ismain(*pintpt))
134 for (ki = 0; ki < (*pintpt)->no_of_curves; ki++)
135 {
136 if (sh6ishelp(help_pt = sh6getnext(*pintpt, ki)))
137 {
138 sh6idkpt (pintdat, &help_pt, 1, &kstat);
139 if (kstat < 0)
140 goto error;
141 }
142 }
143
144 /* Remember the two neighbours */
145 sh6getnhbrs (*pintpt, &pnhbr_1, &pnhbr_2, &kstat);
146 if (kstat < 0)
147 goto error;
148
149
150 if (pnhbr_1 && pnhbr_2)
151 {
152 /* Two neighbours, remember crv_dir */
153 sh6getlist (*pintpt, pnhbr_1, &dummy, &index1, &kstat);
154 if (kstat < 0)
155 goto error; /* Error. */
156 if (kstat == 1)
157 goto err1; /* pt1 and pt2 are not linked. */
158
159 sh6getlist (*pintpt, pnhbr_2, &dummy, &index2, &kstat);
160 if (kstat < 0)
161 goto error; /* Error. */
162 if (kstat == 1)
163 goto err1; /* pt1 and pt2 are not linked. */
164
165 crv_dir_1 = pnhbr_1->curve_dir[index1];
166 crv_dir_2 = pnhbr_2->curve_dir[index2];
167 }
168 }
169
170
171 for (; (*pintpt)->no_of_curves;)
172 {
173 /* Disconnect all */
174 sh6disconnect (*pintpt, (*pintpt)->pnext[0], &kstat);
175 if (kstat < 0)
176 goto error;
177 }
178
179 /* Connect the two neighbours */
180 if (pnhbr_1 && pnhbr_2)
181 {
182 sh6connect (pnhbr_1, pnhbr_2, &kstat);
183 if (kstat < 0)
184 goto error;
185
186 /* UJK, MESZ 930617: Don't bother with curve_dir when
187 the points already were connected. */
188 if (kstat != 1)
189 {
190 sh6getlist (pnhbr_1, pnhbr_2, &index1, &index2, &kstat);
191 if (kstat < 0)
192 goto error; /* Error. */
193 if (kstat == 1)
194 goto err1; /* pt1 and pt2 are not linked. */
195
196 pnhbr_1->curve_dir[index1] = crv_dir_1;
197 pnhbr_2->curve_dir[index2] = crv_dir_2;
198 }
199 }
200
201 if ((*pintdat) == SISL_NULL)
202 {
203 freeIntpt (*pintpt);
204 (*pintpt) = SISL_NULL;
205
206 *jstat = 1;
207 goto out;
208 }
209
210
211 /* Find pintpt in pintdat. */
212
213 for (knum = -1, ki = 0; ki < (*pintdat)->ipoint; ki++)
214 {
215 if ((*pintdat)->vpoint[ki] == (*pintpt))
216 {
217 knum = ki;
218 break;
219 }
220 }
221
222
223 if (knum == -1)
224 *jstat = 1;
225 else
226 {
227 (*pintdat)->vpoint[knum] = (*pintdat)->vpoint[(*pintdat)->ipoint - 1];
228 ((*pintdat)->ipoint)--;
229 (*pintdat)->vpoint[(*pintdat)->ipoint] = SISL_NULL;
230
231
232
233 if ((*pintdat)->ipoint == 0)
234 {
235 freeIntdat (*pintdat);
236 (*pintdat) = SISL_NULL;
237 }
238 }
239
240 freeIntpt (*pintpt);
241 (*pintpt) = SISL_NULL;
242 goto out;
243
244
245 err1:
246 *jstat = -1;
247 goto out;
248
249 error:
250 *jstat = kstat;
251 goto out;
252
253 out:;
254 }
255