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