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: s6idkpt.c,v 1.2 2001-03-19 15:59:01 afr Exp $
45  *
46  */
47 
48 
49 #define S6IDKPT
50 
51 #include "sislP.h"
52 
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s6idkpt(SISLIntdat ** pintdat,SISLIntpt ** pintpt,SISLIntpt ** rtpt,SISLIntpt ** rfpt,int * jstat)55 s6idkpt(SISLIntdat **pintdat,SISLIntpt **pintpt,SISLIntpt **rtpt,SISLIntpt **rfpt,int *jstat)
56 #else
57 void s6idkpt(pintdat,pintpt,rtpt,rfpt,jstat)
58      SISLIntdat **pintdat;
59      SISLIntpt  **pintpt;
60      SISLIntpt  **rtpt;
61      SISLIntpt  **rfpt;
62      int    *jstat;
63 #endif
64 /*
65 *********************************************************************
66 *
67 *********************************************************************
68 *
69 * PURPOSE    : To remove an intersection point pintpt from pintdat.
70 *              Pintpt is than killed. If there is a point pointing on
71 *              pintdat ptpt is set to point to this point otherwise
72 *              ptpt is SISL_NULL. If pintdat is pointing to a point pfpt is
73 *              set to point to this point otherwise pfpt is SISL_NULL.
74 *              If pintdat is empty pintdat is killed and set to SISL_NULL.
75 *              pintpt is set to SISL_NULL.
76 *
77 *
78 *
79 * INPUT/OUTPUT:pintpt   - Pointer to a pointer to new intersection point.
80 *              pintdat  - Pointer to a pointer to intersection data.
81 *
82 *
83 * OUTPUT     : rtpt     - Pointer to a pointer to a point pointing to pintpt.
84 *              rfpt     - Pointer to a pointer to a point pintpt points to.
85 *              jstat    - status messages
86 *                               = 1      : Pintpt is not in pintdat.
87 *                               = 0      : OK!
88 *                               < 0      : error
89 *
90 *
91 * METHOD     :
92 *
93 *
94 * REFERENCES :
95 *
96 *-
97 * CALLS      : s6err      - Gives error message.
98 *              freeIntpt  - free instant of intpt structure.
99 *
100 * WRITTEN BY : Arne Laksaa, 05.89.
101 *
102 *********************************************************************
103 */
104 {
105   int ki;              /* Counters.    */
106   int knum;
107 
108   (*rtpt) = (*rfpt) = SISL_NULL;
109   *jstat = 0;
110 
111   /* We have to be sure that we have an intdat structure. */
112 
113   if ((*pintdat) == SISL_NULL)
114     goto out;
115 
116   if ((*pintpt) == SISL_NULL)
117     {
118       *jstat = 1;
119       goto out;
120     }
121 
122 
123   /* Than we have to be sure that we do not have the intersection point
124      before or an equal point. */
125 
126   for (knum = -1,ki=0; ki<(*pintdat)->ipoint; ki++)
127     {
128       if ((*pintdat)->vpoint[ki] == (*pintpt))
129 	knum = ki;
130 
131       if ((*pintdat)->vpoint[ki] == (*pintpt)->pcurve)
132 	(*rfpt) = (*pintdat)->vpoint[ki];
133 
134       if ((*pintdat)->vpoint[ki]->pcurve == (*pintpt))
135 	(*rtpt) = (*pintdat)->vpoint[ki];
136     }
137 
138 
139   if (knum == -1)
140     *jstat = 1;
141   else
142     {
143       (*pintdat)->vpoint[knum] = (*pintdat)->vpoint[(*pintdat)->ipoint-1];
144       ((*pintdat)->ipoint)--;
145       (*pintdat)->vpoint[(*pintdat)->ipoint] = SISL_NULL;
146 
147       if ((*rtpt) != SISL_NULL)
148 	(*rtpt) ->pcurve = SISL_NULL;
149 
150       if ((*pintdat)->ipoint == 0)
151 	{
152 	  freeIntdat(*pintdat);
153 	  (*pintdat) = SISL_NULL;
154 	}
155     }
156 
157   freeIntpt(*pintpt);
158   (*pintpt) = SISL_NULL;
159 
160  out: ;
161 }
162