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: sh6idnpt.c,v 1.2 2001-03-19 15:59:08 afr Exp $
45  *
46  */
47 
48 
49 #define SH6IDNPT
50 
51 
52 #include "sislP.h"
53 
54 #if defined(SISLNEEDPROTOTYPES)
55 void
sh6idnpt(SISLIntdat ** pintdat,SISLIntpt ** pintpt,int itest,int * jstat)56       sh6idnpt(SISLIntdat **pintdat,SISLIntpt **pintpt,int itest,int *jstat)
57 #else
58 void sh6idnpt(pintdat,pintpt,itest,jstat)
59      SISLIntdat **pintdat;
60      SISLIntpt  **pintpt;
61      int    itest;
62      int    *jstat;
63 #endif
64 
65 
66 /*
67 *********************************************************************
68 *
69 *********************************************************************
70 *
71 * PURPOSE    : To insert a new intersection point into pintdat.
72 *              If pintdat is SISL_NULL a new pintdat is also made.
73 *              If pintpt is close to an other intersection point
74 *              the object pintpt is pointing to is freed, and
75 *              pintpt is set to point to the already inserted point.
76 *
77 *
78 *
79 * INPUT      : pintpt   - Pointer to a pointer to new intersection point.
80 *              pintdat  - Pointer to a pointer to intersection data.
81 *              itest    - Indikate testing equalety.
82 *                               = 1      : Testing.
83 *                               = 0      : No testing.
84 *
85 *
86 * OUTPUT     : jstat  - status messages
87 *                               = 2      : Already existing.
88 *                               = 1      : Already inserted.
89 *                               = 0      : Intersection point inserted.
90 *                               < 0      : error
91 *
92 *
93 * METHOD     :
94 *
95 *
96 * REFERENCES :
97 *
98 *-
99 * CALLS      : s6err      - Gives error message.
100 *              newIntdat  - Create new intdat structure.
101 *              freeIntpt  - free instant of intpt structure.
102 *
103 * WRITTEN BY : Michael Floater, June 91.
104 *
105 *********************************************************************
106 */
107 {
108   register int ki,kj;              /* Counters.    */
109 
110   /* We have to be sure that we have an intdat structure. */
111 
112   if ((*pintdat) == SISL_NULL)
113     {
114       if (((*pintdat) = newIntdat()) == SISL_NULL) goto err101;
115     }
116 
117 
118   /* Then we have to be sure that we do not have the intersection point
119      before or an equal point. */
120 
121   for (ki=0; ki<(*pintdat)->ipoint; ki++)
122     if ((*pintdat)->vpoint[ki] == (*pintpt))
123       {
124 	*jstat = 1;
125 	goto out;
126       }
127     else if (itest)
128       {
129 	for (kj=0; kj<(*pintpt)->ipar; kj++)
130 	  if (DNEQUAL((*pintpt)->epar[kj],(*pintdat)->vpoint[ki]->epar[kj]))
131 	    break;
132 
133 	if (kj == (*pintpt)->ipar)
134 	  {
135 	    freeIntpt(*pintpt);
136 	    (*pintpt) = (*pintdat)->vpoint[ki];
137 	    *jstat = 2;
138 	    goto out;
139 	  }
140       }
141 
142 
143   /* Then we have to be sure that the array vpoint is great enough. */
144 
145   if (ki == (*pintdat)->ipmax)
146     {
147       (*pintdat)->ipmax += 20;
148 
149       if (((*pintdat)->vpoint = increasearray((*pintdat)->vpoint,
150 					      (*pintdat)->ipmax,SISLIntpt *)) == SISL_NULL)
151 	goto err101;
152     }
153 
154 
155   /* Now we can insert the new point. */
156 
157   (*pintdat)->vpoint[ki] = (*pintpt);
158   (*pintdat)->ipoint++;
159   *jstat = 0;
160   goto out;
161 
162 
163 /* Error in space allocation.  */
164 
165 err101: *jstat = -101;
166         s6err("sh6idnpt",*jstat,0);
167         goto out;
168 
169  out: ;
170 }
171