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: sh6getothr.c,v 1.2 2001-03-19 15:59:07 afr Exp $
45  *
46  */
47 
48 
49 #define SH6GETOTHER
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
sh6getother(SISLIntpt * pt,SISLIntpt * pt1,SISLIntpt ** pt2,int * jstat)55       sh6getother(SISLIntpt *pt,SISLIntpt *pt1,SISLIntpt **pt2,int *jstat)
56 #else
57 void sh6getother(pt,pt1,pt2,jstat)
58    SISLIntpt *pt;
59    SISLIntpt *pt1;
60    SISLIntpt **pt2;
61    int       *jstat;
62 #endif
63 /*
64 *********************************************************************
65 *
66 *********************************************************************
67 *
68 * PURPOSE    : Given one neighbour pt1 of the point pt, find
69 *              the other neighbour if it is unique.
70 *              If pt is help point, look for both type of neighbours.
71 *              If main point, look only for main points.
72 *              pt and pt1 must be linked.
73 *
74 * INPUT      : pt       - SISLIntpt point.
75 *              pt1      - One neighbour.
76 *
77 * OUTPUT     :  pt2     - Second neighbour if unique.
78 *              jstat    - Error flag.
79 *                         jstat =  0  => successful, unique neighbour
80 *                         jstat =  1  => pt is end point, pt2 SISL_NULL
81 *                         jstat =  2  => pt is junction point, pt2 SISL_NULL
82 *                         jstat = -1  => pt1 and pt2 are not connected
83 *                         jstat = -2  => error in data structure.
84 *                         jstat <  0  => error in lower level routine
85 *
86 *
87 * METHOD     :
88 *
89 *
90 * REFERENCES :
91 *
92 * WRITTEN BY : Michael Floater, SI, Oslo, Norway. June 91.
93 * CHANGED BY : Ulf J. Krystad, SI, Oslo, Norway. July 91.
94 *********************************************************************
95 */
96 {
97   int kstat;              /* Local status variable.    */
98   int index,index1;      /* Indices for pt and pt1.   */
99   int num;              /* count number of pointers    */
100   int i;              /* Loop variable. */
101 
102    *pt2 = SISL_NULL;
103    *jstat = 0;
104 
105   sh6getlist(pt,pt1,&index1,&index,&kstat);
106   if(kstat < 0) goto error;
107   if(kstat == 1) goto err1;
108 
109   if(sh6ismain(pt))  /* pt is main point. */
110   {
111       if(!sh6ismain(pt1)) goto err1;
112       num=0;
113       /* UJK, don't pass singular point ! */
114       if (pt->iinter == SI_SING)
115       {
116 	  *pt2 = SISL_NULL;
117           *jstat = 2;
118           goto out;
119       }
120 
121       for(i=0; i < pt->no_of_curves; i++)
122       {
123 	  if(i != index1 && sh6ismain(pt->pnext[i]))
124 	  {
125 	      *pt2 = pt->pnext[i];
126 	      num++;
127 	  }
128       }
129 
130       if(num == 0) *jstat = 1; /* pt is an end point. */
131       else if(num > 1) /* pt is a junction point. */
132       {
133 	  *pt2 = SISL_NULL;
134           *jstat = 2;
135       }
136   }
137   else  /* pt is help point. */
138   {
139       num=0;
140 
141       for(i=0; i < pt->no_of_curves; i++)
142       {
143 	  if(i != index1)
144 	  {
145 	      *pt2 = pt->pnext[i];
146 	      num++;
147 	  }
148       }
149 
150       if(num > 1) goto err2; /* Error in data structure. */
151       if(num == 0) *jstat = 1; /* pt is an end point. */
152   }
153 
154   goto out;
155 
156 
157 /* Error. pt1 and pt2 are not linked.  */
158 
159 err1: *jstat = -1;
160       s6err("sh6getother",*jstat,0);
161       goto out;
162 
163 /* Error in sub function.  */
164 
165 /* Error in data structure. */
166 
167 err2: *jstat = -2;
168       s6err("sh6getother",*jstat,0);
169       goto out;
170 
171 /* Error in sub function.  */
172 
173 error:  *jstat = kstat;
174         s6err("sh6getother",*jstat,0);
175         goto out;
176 
177    out:
178       return;
179 }
180