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: sh6edgpnt.c,v 1.2 2001-03-19 15:59:07 afr Exp $
45  *
46  */
47 
48 
49 #define SH6EDGPOINT
50 #include "sislP.h"
51 
52 #if defined(SISLNEEDPROTOTYPES)
53 void
sh6edgpoint(SISLEdge * vedge[],SISLIntpt *** wintpt,int * jnum,int * jstat)54 sh6edgpoint (SISLEdge * vedge[], SISLIntpt *** wintpt, int *jnum,int *jstat)
55 #else
56 void
57 sh6edgpoint (vedge, wintpt, jnum, jstat)
58      SISLEdge *vedge[];
59      SISLIntpt ***wintpt;
60      int *jnum;
61      int *jstat;
62 #endif
63  /*
64  *********************************************************************
65  *
66  *********************************************************************
67  *
68  * PURPOSE    : Make an array of pointers pointing to different
69  *              intersection points on edges.
70  *
71  *
72  *
73  * INPUT      : vedge[]  - SISLEdge intersection.
74  *
75  *
76  * OUTPUT     : jnum     - Number of intersection points,
77  *              wintpt   - Array of pointers to intersection points.
78  *              jstat    - status messages
79  *                           = 1     : Coinside found.
80  *                           = 0     : no coinside.
81  *                           < 0     : error
82  *
83  *
84  * METHOD     :
85  *
86  *
87  * REFERENCES :
88  *
89  * CALLS      : sh6getmain - Get main point in chain of help points.
90  *
91  *
92  * WRITTEN BY : Arne Laksaa, SI, 89-06.
93  *
94  *********************************************************************
95  */
96 {
97   int lant[2];
98 
99   if (vedge[0] == SISL_NULL)
100     lant[0] = 0;
101   else
102     lant[0] = vedge[0]->ipoint;
103 
104   if (vedge[1] == SISL_NULL)
105     lant[1] = 0;
106   else
107     lant[1] = vedge[1]->ipoint;
108 
109   if (lant[0] + lant[1] > 0)
110     {
111       int kn1;			/* Number of int. pt. found.   */
112       int kn, ki, kj;		/* Counters.                   */
113       SISLPtedge *qpt;
114       SISLIntpt *qintpt;	/* Intersection point.         */
115       SISLIntpt *qmain;		/* Main point in chain of help points.      */
116 
117       /* Allocate array of pointers to the points. */
118 
119       if (((*wintpt) = newarray (lant[0] + lant[1],
120 				 SISLIntpt *)) == SISL_NULL)
121 	goto err101;
122 
123 
124       /* Update the array. */
125 
126       for (kn1 = 0, kn = 0; kn < 2; kn++)
127 	if (lant[kn] > 0)
128 	  for (kj = 0; kj < vedge[kn]->iedge; kj++)
129 	    for (qpt = vedge[kn]->prpt[kj]; qpt != SISL_NULL; qpt = qpt->pnext)
130 	      {
131 		for (ki = 0; ki < kn1; ki++)
132 		  {
133 		    if (qpt->ppt == (*wintpt)[ki])
134 		      break;
135 		  }
136 		if (ki == kn1)
137 		  (*wintpt)[kn1++] = qpt->ppt;
138 	      }
139 
140       /* Traverse the array and remove help points if the corresponding
141 	 main point also lies in the array.     */
142 
143       for (ki = 0; ki < kn1; ki++)
144 	{
145 	  qintpt = (*wintpt)[ki];
146 	  if (sh6ishelp (qintpt))
147 	    {
148 	      /* A help point is found. Fetch the corresponding main point. */
149 
150 	      qmain = sh6getmain (qintpt);
151 
152 	      /* Check if the main point lies in the array. */
153 
154 	      if (qmain)
155 		{
156 		  for (kj = 0; kj < kn1; kj++)
157 		    if (qmain == (*wintpt)[kj])
158 		      break;
159 		  if (kj < kn1)
160 		    (*wintpt)[ki] = SISL_NULL;
161 		}
162 	    }
163 	}
164 
165       /* Make sure that the array of int.pt. is dense.  */
166 
167       for (ki = 0, kj = kn1; ki < kj; ki++)
168 	if ((*wintpt)[ki] == SISL_NULL)
169 	  (*wintpt)[ki] = (*wintpt)[--kj];
170 
171       *jnum = kn1 = kj;
172     }
173   else
174     *jnum = 0;
175 
176   *jstat = 0;
177   goto out;
178 
179   /* Error in memory allocation.      */
180 
181 err101:*jstat = -101;
182   s6err ("sh6edgpoint", *jstat, 0);
183   goto out;
184 
185 
186 out:;
187 }
188