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: s6idint.c,v 1.2 2001-03-19 15:59:01 afr Exp $
45 *
46 */
47
48
49 #define S6IDINT
50
51 #include "sislP.h"
52
53 #if defined(SISLNEEDPROTOTYPES)
54 void
s6idint(SISLObject * po1,SISLObject * po2,SISLIntdat * pintdat,SISLIntpt ** rpt,int iob)55 s6idint(SISLObject *po1,SISLObject *po2,SISLIntdat *pintdat,SISLIntpt **rpt,int iob)
56 #else
57 void s6idint(po1,po2,pintdat,rpt,iob)
58 SISLObject *po1;
59 SISLObject *po2;
60 SISLIntdat *pintdat;
61 SISLIntpt **rpt;
62 int iob;
63 #endif
64 /*
65 *********************************************************************
66 *
67 *********************************************************************
68 *
69 * PURPOSE : To find an internal intersection point in object iob
70 * from pintdat.
71 *
72 *
73 *
74 * INPUT : pintdat - Pointer to intersection data.
75 * po1 - Pointer to first object
76 * po2 - Pointer to second object
77 * iob - Number of object to find internal
78 * intersection poin in.
79 *
80 *
81 * OUTPUT : rpt - Pointer to an internal intersection point.
82 *
83 *
84 * METHOD :
85 *
86 *
87 * REFERENCES :
88 *
89 *-
90 * CALLS :
91 *
92 * WRITTEN BY : Arne Laksaa, 05.89.
93 *
94 *********************************************************************
95 */
96 {
97 register int ki,kj;
98 int kpar1,kpar2;
99 double sstart1[2],send1[2];
100 double sstart2[2],send2[2];
101
102
103 /* Initiate to emty list. */
104
105 *rpt = SISL_NULL;
106
107
108 /* We have to be sure that we have an intdat structure. */
109
110 if (pintdat == SISL_NULL)
111 goto out;
112
113
114 if (po1 == SISL_NULL || po1->iobj == SISLPOINT)
115 kpar1 = 0;
116 else if (po1->iobj == SISLCURVE)
117 {
118 kpar1 = 1;
119 sstart1[0] = po1->c1->et[po1->c1->ik-1];
120 send1[0] = po1->c1->et[po1->c1->in];
121 }
122 else if (po1->iobj == SISLSURFACE)
123 {
124 kpar1 = 2;
125 sstart1[0] = po1->s1->et1[po1->s1->ik1-1];
126 send1[0] = po1->s1->et1[po1->s1->in1];
127 sstart1[1] = po1->s1->et2[po1->s1->ik2-1];
128 send1[1] = po1->s1->et2[po1->s1->in2];
129 }
130
131
132 if (po2 == SISL_NULL || po2->iobj == SISLPOINT)
133 kpar2 = 0;
134 else if (po2->iobj == SISLCURVE)
135 {
136 kpar2 = 1;
137 sstart2[0] = po2->c1->et[po2->c1->ik-1];
138 send2[0] = po2->c1->et[po2->c1->in];
139 }
140 else if (po2->iobj == SISLSURFACE)
141 {
142 kpar2 = 2;
143 sstart2[0] = po2->s1->et1[po2->s1->ik1-1];
144 send2[0] = po2->s1->et1[po2->s1->in1];
145 sstart2[1] = po2->s1->et2[po2->s1->ik2-1];
146 send2[1] = po2->s1->et2[po2->s1->in2];
147 }
148
149
150 if (iob == 1 && kpar1 == 0)
151 goto out;
152
153 if (iob == 2 && kpar2 == 0)
154 goto out;
155
156
157 /* We have to go trough all intersection points to search for internal
158 intersection points. */
159
160 for (ki=pintdat->ipoint-1; ki>=0; ki--)
161 {
162 for (kj=0; kj<kpar1; kj++)
163 if (sstart1[kj] > pintdat->vpoint[ki]->epar[kj] ||
164 send1[kj] < pintdat->vpoint[ki]->epar[kj])
165 goto end;
166 for (kj=0; kj<kpar2; kj++)
167 if (sstart2[kj] > pintdat->vpoint[ki]->epar[kpar1+kj] ||
168 send2[kj] < pintdat->vpoint[ki]->epar[kpar1+kj])
169 goto end;
170
171 if (iob == 1)
172 {
173 for (kj=0; kj<kpar1; kj++)
174 if (DEQUAL(sstart1[kj],pintdat->vpoint[ki]->epar[kj]) ||
175 DEQUAL(send1[kj],pintdat->vpoint[ki]->epar[kj]))
176 goto end;
177 }
178 else
179 {
180 for (kj=0; kj<kpar2; kj++)
181 if (DEQUAL(sstart2[kj],pintdat->vpoint[ki]->epar[kpar1+kj]) ||
182 DEQUAL(send2[kj],pintdat->vpoint[ki]->epar[kpar1+kj]))
183 goto end;
184 }
185
186
187 (*rpt) = pintdat->vpoint[ki];
188 goto out;
189 end:;
190 }
191 out:;
192 }
193