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: sh6connect.c,v 1.1 1994-04-21 12:10:42 boh Exp $
45  *
46  */
47 
48 
49 #define SH6CONNECT
50 
51 #include "sislP.h"
52 
53 
54 #if defined(SISLNEEDPROTOTYPES)
55 void
sh6connect(SISLIntpt * pt1,SISLIntpt * pt2,int * jstat)56 sh6connect (SISLIntpt * pt1, SISLIntpt * pt2, int *jstat)
57 #else
58 void
59 sh6connect (pt1, pt2, jstat)
60      SISLIntpt *pt1;
61      SISLIntpt *pt2;
62      int *jstat;
63 #endif
64 /*
65 *********************************************************************
66 *
67 *********************************************************************
68 *
69 * PURPOSE    : Connect the two points.
70 *              If they are already connected give message.
71 *
72 *
73 * INPUT      : pt1      - Pointer to first Intpt.
74 *              pt2      - Pointer to second Intpt.
75 *              jstat    - Error flag.
76 *                        jstat =  0  => Successful
77 *                        jstat =  1  => Points already connected.
78 *                        jstat = -1  => Illegal to connect.
79 *                        jstat = -2  => Error in data structure.
80 *                        jstat = -3  => Error in subfunction.
81 *                        jstat = -4  => Selfconnecting not legal.
82 *
83 *
84 *
85 * REFERENCES :
86 *
87 * WRITTEN BY : Michael Floater, SI, Oslo, Norway. May 91.
88 * CORRECTED BY : Ulf J. Krystad, SI, Oslo, Norway. July 91.
89 *********************************************************************
90 */
91 {
92   int kstat;			/* error flag. */
93   int index1, index2;		/* dummy indices.           */
94   int num;			/* Number of main point pinters.  */
95 
96   *jstat = 0;
97 
98   if (pt1 == pt2)
99     goto err4;
100 
101   /* Check if pt1 and pt2 are already connected. */
102 
103   sh6getlist (pt1, pt2, &index1, &index2, &kstat);
104   if (kstat < 0)
105     goto err3;
106   if (kstat < 1)		/* Already connected. */
107     {
108       *jstat = 1;
109       goto out;
110     }
111 
112   /* Check that we can connect pt1. There are restrictions if it
113      it a help point.  */
114 
115   if (sh6ishelp (pt1))		/* pt1 is a help point */
116     {
117       /* UJK, this is NO invariant */
118       /*if (pt1->no_of_curves > 2)
119          goto err2;
120          if (pt1->no_of_curves == 2)
121          goto err1; */
122 
123       if (sh6ismain (pt2))	/* pt2 is a main point. */
124 	{
125 	  num = sh6nmbmain (pt1, &kstat);
126 
127 	  /* UJK, If invar does not hold, MAKE it hold */
128 	  /* if (num > 1)
129 	    goto err2;
130 	  if (num == 1)
131 	    goto err1; */
132 	  if (num >= 1)
133 	    sh6tomain (pt1, &kstat);
134 	  if (kstat < 0)
135 	    goto err2;
136 
137 	  /* pt1 cannot be connected to two main points. */
138 	}
139     }
140 
141   /* Check that we can connect pt2. There are restrictions if it
142      it a help point.  */
143 
144   if (sh6ishelp (pt2))		/* pt2 is a help point */
145     {
146       /* UJK, this is NO invariant */
147       /*if (pt2->no_of_curves > 2)
148          goto err2;
149          if (pt2->no_of_curves == 2)
150          goto err1; */
151 
152       if (sh6ismain (pt1))	/* pt1 is a main point. */
153 	{
154 	  num = sh6nmbmain (pt2, &kstat);
155 
156 	  /* UJK, If invar does not hold, MAKE it hold */
157 	  /*if (num > 1)
158 	    goto err2;
159 	  if (num == 1)
160 	    goto err1; */
161 	  if (num >= 1)
162 	    sh6tomain (pt2, &kstat);
163 	  if (kstat < 0)
164 	    goto err2;
165 
166 	  /* pt2 cannot be connected to two main points. */
167 	}
168     }
169 
170   /* Now make the connection. */
171 
172 
173   /* Point pt1 to pt2. */
174 
175   /* Check if we need to reallocate the pnext and curve_dir arrays. */
176 
177   if (pt1->no_of_curves > pt1->no_of_curves_alloc)
178     goto err2;
179   if (pt1->no_of_curves == pt1->no_of_curves_alloc)
180     {
181       pt1->no_of_curves_alloc += 4;
182       pt1->pnext = increasearray (pt1->pnext,
183 				  pt1->no_of_curves_alloc, SISLIntpt *);
184       pt1->curve_dir = increasearray (pt1->curve_dir,
185 				      pt1->no_of_curves_alloc, int);
186       /* UJK, Must have size of pretop arrays increased */
187       pt1->left_obj_1 = increasearray (pt1->left_obj_1,
188 				       pt1->no_of_curves_alloc, int);
189       pt1->left_obj_2 = increasearray (pt1->left_obj_2,
190 				       pt1->no_of_curves_alloc, int);
191       pt1->right_obj_1 = increasearray (pt1->right_obj_1,
192 					pt1->no_of_curves_alloc, int);
193       pt1->right_obj_2 = increasearray (pt1->right_obj_2,
194 					pt1->no_of_curves_alloc, int);
195     }
196 
197   /* Set new pointer to new position in array. */
198   /* Set new curve direction to 0 for now. */
199 
200   pt1->pnext[pt1->no_of_curves] = pt2;
201   pt1->curve_dir[pt1->no_of_curves] = 0;
202 
203   /* Increment no_of_curves. */
204 
205   pt1->no_of_curves++;
206 
207 
208   /* Point pt2 to pt1. */
209 
210   /* Check if we need to reallocate the pnext and curve_dir arrays. */
211 
212   if (pt2->no_of_curves > pt2->no_of_curves_alloc)
213     goto err2;
214   if (pt2->no_of_curves == pt2->no_of_curves_alloc)
215     {
216       pt2->no_of_curves_alloc += 4;
217       /* UJK, pt1->pnext chaged to pt2->pnext */
218       pt2->pnext = increasearray (pt2->pnext,
219 				  pt2->no_of_curves_alloc, SISLIntpt *);
220       pt2->curve_dir = increasearray (pt2->curve_dir,
221 				      pt2->no_of_curves_alloc, int);
222       /* UJK, Must have size of pretop arrays increased */
223       pt2->left_obj_1 = increasearray (pt2->left_obj_1,
224 				       pt2->no_of_curves_alloc, int);
225       pt2->left_obj_2 = increasearray (pt2->left_obj_2,
226 				       pt2->no_of_curves_alloc, int);
227       pt2->right_obj_1 = increasearray (pt2->right_obj_1,
228 					pt2->no_of_curves_alloc, int);
229       pt2->right_obj_2 = increasearray (pt2->right_obj_2,
230 					pt2->no_of_curves_alloc, int);
231     }
232 
233   /* Set new pointer to new position in array. */
234   /* Set new curve direction to 0 for now. */
235 
236   pt2->pnext[pt2->no_of_curves] = pt1;
237   pt2->curve_dir[pt2->no_of_curves] = 0;
238 
239   /* Increment no_of_curves. */
240 
241   pt2->no_of_curves++;
242 
243 
244 
245   goto out;
246 
247   /* Illegal to connect. */
248   /*err1:
249 
250   *jstat = -1;
251   s6err ("sh6connect", *jstat, 0);
252   goto out; */
253 
254   /* Error in data structure. */
255 err2:
256 
257   *jstat = -2;
258   s6err ("sh6connect", *jstat, 0);
259   goto out;
260 
261   /* Error in subfunction. */
262 err3:
263 
264   *jstat = -3;
265   s6err ("sh6connect", *jstat, 0);
266   goto out;
267 
268 err4:
269   /* Selfconnecting not legal */
270   *jstat = -4;
271   s6err ("sh6connect", *jstat, 0);
272   goto out;
273 
274 
275 out:
276   return;
277 }
278