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: s1880.c,v 1.2 2001-03-19 15:58:55 afr Exp $
45  *
46  */
47 
48 
49 #define S1880
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s1880(int ipar1,int ipar2,int * jpt,SISLIntpt ** vpoint,int * jlist,SISLIntlist ** vlist,int * jpar,double ** gpar1,double ** gpar2,int * jcrv,SISLIntcurve *** wcrv,int * jstat)55 s1880(int ipar1,int ipar2,int *jpt,SISLIntpt **vpoint,int *jlist,SISLIntlist **vlist,
56 	   int *jpar,double **gpar1,double **gpar2,int *jcrv,SISLIntcurve ***wcrv,int *jstat)
57 #else
58 void s1880(ipar1,ipar2,jpt,vpoint,jlist,vlist,jpar,gpar1,gpar2,jcrv,
59            wcrv,jstat)
60      int      ipar1;
61      int      ipar2;
62      int      *jpt;
63      SISLIntpt    **vpoint;
64      int      *jlist;
65      SISLIntlist  **vlist;
66      int      *jpar;
67      double   **gpar1;
68      double   **gpar2;
69      int      *jcrv;
70      SISLIntcurve ***wcrv;
71      int      *jstat;
72 #endif
73 /*
74 *********************************************************************
75 *
76 *********************************************************************
77 *
78 * PURPOSE    : Transform intersection points and curves from internal
79 *              format in the recursive part of intersection routines
80 *              to output format.
81 *
82 *
83 *
84 * INPUT      : ipar1  - Number of parameter directions of first object.
85 *              ipar2  - Number of parameter directions of second object.
86 *              vpoint - Array containing intersection points on the
87 *                       internal format.
88 *              vlist  - Array representing intersection curves on the
89 *                       internal format.
90 *
91 * INPUT/OUTPUT : jpt    - Number of intersection point in the vpoint array.
92 *                jlist  - Number of lists representing intersection curves
93 *                         in the array vlist.
94 *
95 *
96 *
97 *
98 * OUTPUT     : jpar   - Number of single intersection points.
99 *              gpar1  - Parameter values of the single intersection points
100 *                       in the parameter area of the first object.
101 *              gpar2  - Parameter values of the single intersection points
102 *                       in the parameter area of the second object.
103 *              jcrv   - Number of intersection curves.
104 *              wcrv   - Array containing description of intersection curves.
105 *              jstat  - status messages
106 *                                         > 0      : warning
107 *                                         = 0      : ok
108 *                                         < 0      : error
109 *
110 *
111 * METHOD     :
112 *
113 *
114 * REFERENCES :
115 *
116 *-
117 * CALLS      : newIntcurve - Create a new instance of Intcurve.
118 *              freeIntpt   - Free space occupied by intersection point.
119 *
120 * WRITTEN BY : Vibeke Skytt, SI, 88-05.
121 *
122 *********************************************************************
123 */
124 {
125   int kpos = 0;         /* Position of error.                          */
126   int ki,kj,kk;         /* Counters.                                   */
127   int kpoint;           /* Number of points in an intersection list.   */
128   int klst;             /* Kind of intersection list. (See SISLIntlist).   */
129   int ktype;            /* Kind of intersection curve. (See SISLIntcurve). */
130   int kpt;              /* Used to find number of single intersection points.*/
131   double *spar1,*spar2; /* Values of points belonging to an intersection
132 			   curve in the parameter area of the objects
133 			   involved in the intersection.               */
134   double *stpar1,*stpar2,*stpar3; /* Pointers used to travers arrays
135 				     containing parameter values.      */
136   SISLIntcurve **ucrv;      /* Pointer used to traverse *wcrv array.    */
137   SISLIntlist **ulst;       /* Pointer used to traverse vlist array.     */
138   SISLIntpt *qpt;           /* Pointer to an intersection point.         */
139   SISLIntpt **upt;          /* Pointer used to travers vpoint array.     */
140 
141   /* Initiate output arrays.  */
142 
143   *gpar1 = *gpar2 = SISL_NULL;  *wcrv = SISL_NULL;
144 
145   /* Allocate space for intersection curve array.  */
146 
147   *jcrv = *jlist;
148   *wcrv = newarray(*jlist,SISLIntcurve*);
149   if ((*jcrv) > 0 && *wcrv == SISL_NULL) goto err101;
150 
151   /* Transfer curve-information from vlist array to wcrv array. */
152 
153   ucrv = *wcrv;
154   ulst = vlist;
155   kpt = 0;
156   for (ki=0; ki<(*jlist); ki++)
157     {
158       qpt = (*ulst) -> pfirst;
159 
160       /* Allocate space for arrays containing parameter vlaues of points
161 	 in intersection curves.                                          */
162 
163       kpoint = (*ulst) -> inumb;
164       if (kpoint == 0) goto err137;
165       spar1 = newarray(ipar1*kpoint,double);
166       spar2 = newarray(ipar2*kpoint,double);
167       if ((ipar1 > 0 && spar1 == SISL_NULL) ||
168 	  (ipar2 > 0 && spar2 == SISL_NULL)) goto err101;
169 
170       /* Collect parameter values of the points in this intersection list
171 	 and distribute values to the objects in the intersection.         */
172 
173       kj = 0;
174       stpar1 = spar1;
175       stpar2 = spar2;
176       while (qpt != SISL_NULL && qpt -> ipar != -1)
177 	{
178 	  stpar3 = qpt -> epar;
179 	  for (kk=0; kk<ipar1; kk++) *(stpar1++) = *(stpar3++);
180 	  for (kk=0; kk<ipar2; kk++) *(stpar2++) = *(stpar3++);
181 	  qpt -> ipar = -1;
182 	  qpt = qpt -> pcurve;
183 	  kj++;
184 	}
185 
186       /* Find kind of intersection curve.  */
187 
188       klst = (*ulst) -> itype;
189       if (klst == 0) ktype = 4;
190       else if (klst == 1) ktype = 2;
191       else if (klst == 2) ktype = 5;
192       else if (klst == 3) ktype = 6;
193       else if (klst == 4) ktype = 7;
194       else if (klst == 5) ktype = 8;
195       else goto err146;
196 
197       /* Create new intersection curve.  */
198 
199       *ucrv = newIntcurve(kj,ipar1,ipar2,spar1,spar2,ktype);
200       if (*ucrv == SISL_NULL) goto err101;
201 
202       kpt += kj;
203       ucrv++;
204       ulst++;
205     }
206 
207   /* Find number of single intersection points.  */
208 
209   kpt = *jpt - kpt;
210 
211   /* Create arrays to keep parameter values of intersection points.  */
212 
213   *gpar1 = newarray(ipar1*kpt,double);
214   *gpar2 = newarray(ipar2*kpt,double);
215   if ((ipar1*kpt > 0 && *gpar1 == SISL_NULL)
216       || (ipar2*kpt > 0 && *gpar2 == SISL_NULL)) goto err101;
217 
218   /* Copy parameters of single intersection points into output-arrays. */
219 
220   kj = 0;
221   upt = vpoint;
222   stpar1 = *gpar1;
223   stpar2 = *gpar2;
224   for (ki=0; ki<(*jpt); ki++)
225     {
226       qpt = *upt;
227       if (qpt != SISL_NULL)
228 	{
229 	  if (qpt -> ipar != -1)
230 	    {
231 	      kj++;
232 	      stpar3 = qpt -> epar;
233 	      for (kk=0; kk<ipar1; kk++) *(stpar1++) = *(stpar3++);
234 	      for (kk=0; kk<ipar2; kk++) *(stpar2++) = *(stpar3++);
235 	    }
236 
237 	  /* Free space occupied by current intersection point.  */
238 
239 	  freeIntpt(qpt);
240 	}
241 
242       upt++;
243     }
244 
245   *jpar = kj;
246 
247   /* Adjust output arrays to correct length.  */
248 
249   if (kj*ipar1 > 0)
250     {
251       if ((*gpar1 = increasearray(*gpar1,kj*ipar1,double)) == SISL_NULL) goto err101;
252     }
253   else
254     {
255       if (*gpar1 != SISL_NULL) freearray(*gpar1);
256       *gpar1 = SISL_NULL;
257     }
258   if (kj*ipar2 > 0)
259     {
260       if ((*gpar2 = increasearray(*gpar2,kj*ipar2,double)) == SISL_NULL) goto err101;
261     }
262   else
263     {
264       if (*gpar2 != SISL_NULL) freearray(*gpar2);
265       *gpar2 = SISL_NULL;
266     }
267 
268   /* Intersections copied to output format.  */
269 
270   *jpt = 0;
271   *jstat = 0;
272   goto out;
273 
274   /* Error in space allocation.  */
275 
276  err101: *jstat = -101;
277   s6err("s1880",*jstat,kpos);
278   goto out;
279 
280   /* Error in data-strucuture. Expected intersection point not found. */
281 
282  err137: *jstat = -137;
283   s6err("s1880",*jstat,kpos);
284   goto out;
285 
286   /* Unknown kind of intersection type.  */
287 
288  err146: *jstat = -146;
289   s6err("s1880",*jstat,kpos);
290   goto out;
291 
292  out: return;
293 }
294 
295