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: sh6isinsid.c,v 1.2 2001-03-19 16:06:03 afr Exp $
45 *
46 */
47
48
49 #define SH6ISINSIDE
50
51 #include "sislP.h"
52
53
54 #if defined(SISLNEEDPROTOTYPES)
55 void
sh6isinside(SISLObject * po1,SISLObject * po2,SISLIntpt * intpt,int * jstat)56 sh6isinside (SISLObject * po1, SISLObject * po2, SISLIntpt *intpt, int *jstat)
57 #else
58 void
59 sh6isinside (po1, po2, intpt, jstat)
60 SISLObject *po1;
61 SISLObject *po2;
62 SISLIntpt *intpt;
63 int *jstat;
64 #endif
65
66 /*
67 *********************************************************************
68 *
69 *********************************************************************
70 *
71 * PURPOSE : Test if an intersection point is inside the parametric space
72 * of the objects.
73 *
74 *
75 * INPUT : po1 - Pointer to the first object in the intersection.
76 * po2 - Pointer to the second object in the intersection.
77 * intpt - Intersection point.
78 *
79 *
80 * OUTPUT : jstat - status messages
81 * < 0 : Error.
82 * 0 : outside (UJK:at least one?) all objects
83 * 1 : in the inner of all objects
84 * 2 : on at least one edge/end of the objects
85 * 3 : on one corner of one objects
86 * 4 : on one corner of each objects
87 * 5 : on one edge/end of both objects
88 * (not corner)
89 *
90 *
91 * METHOD :
92 *
93 * CALLS :
94 *
95 * REFERENCES :
96 *
97 * WRITTEN BY : Arne Laksaa, SI, Oslo, sep. -91.
98 * CORRECTED BY: UJK
99 * REVISED BY : ALA and VSK, 09.92. Introduced output status *jstat = 5.
100 *********************************************************************
101 */
102 {
103 double minpar[4];
104 double maxpar[4];
105 int nrpar;
106 int i;
107 int is_inside = 1;
108 int on_edge = 0;
109
110
111 if (intpt != SISL_NULL)
112 {
113 /* Making the parametric boarders */
114
115 if (po1->iobj == SISLSURFACE)
116 {
117 nrpar = 2;
118
119 minpar[0] = po1->s1->et1[po1->s1->ik1-1];
120 minpar[1] = po1->s1->et2[po1->s1->ik2-1];
121 maxpar[0] = po1->s1->et1[po1->s1->in1];
122 maxpar[1] = po1->s1->et2[po1->s1->in2];
123 }
124 else if (po1->iobj == SISLCURVE)
125 {
126 nrpar = 1;
127
128 minpar[0] = po1->c1->et[po1->c1->ik-1];
129 maxpar[0] = po1->c1->et[po1->c1->in];
130 }
131 else /* SISLPOINT */
132 nrpar = 0;
133
134 if (po2->iobj == SISLSURFACE)
135 {
136 minpar[nrpar] = po2->s1->et1[po2->s1->ik1-1];
137 minpar[nrpar+1] = po2->s1->et2[po2->s1->ik2-1];
138 maxpar[nrpar] = po2->s1->et1[po2->s1->in1];
139 maxpar[nrpar+1] = po2->s1->et2[po2->s1->in2];
140 nrpar += 2;
141 }
142 else if (po2->iobj == SISLCURVE)
143 {
144 minpar[nrpar] = po2->c1->et[po2->c1->ik-1];
145 maxpar[nrpar] = po2->c1->et[po2->c1->in];
146 nrpar++;
147 }
148 /*else SISLPOINT */
149
150 if (nrpar != intpt->ipar) goto err106;
151
152 /* Testing. */
153
154 for (i = 0; (i < nrpar) && is_inside; i++)
155 {
156 if ((intpt->epar[i] <= maxpar[i] + REL_PAR_RES ||
157 DEQUAL(intpt->epar[i], maxpar[i])) &&
158 (intpt->epar[i] >= minpar[i] - REL_PAR_RES ||
159 DEQUAL(intpt->epar[i], minpar[i])))
160 {
161 /* Int point is inside. */
162
163 if (intpt->epar[i] >= maxpar[i] - REL_PAR_RES)
164 on_edge += (1 << (2*i)); /* On edge/end */
165 if (intpt->epar[i] <= minpar[i] + REL_PAR_RES)
166 on_edge += (1 << (2*i+1)); /* On edge/end */
167
168 }
169 else is_inside = 0;
170 }
171
172 if (is_inside)
173 {
174 (*jstat) = 1;
175 if(on_edge)
176 {
177 (*jstat) += 1;
178 if(on_edge > 1)
179 {
180 if (po1->iobj == SISLSURFACE)
181 {
182 if ((on_edge & 1 || on_edge & 2) &&
183 (on_edge & 4 || on_edge & 8))
184 (*jstat) += 1;
185 }
186
187 if (po2->iobj == SISLSURFACE )
188 {
189 int ui = 2*(nrpar - 2);
190 if ((on_edge & (1 << (ui)) || on_edge & (1 << (ui+1))) &&
191 (on_edge & (1 << (ui+2)) || on_edge & (1 << (ui+3))))
192 (*jstat) += 1;
193 }
194 }
195 }
196
197 /* Test if the intersection point lies at an edge in both
198 objects and is not registered as a corner point. */
199
200 if (*jstat == 2 && (on_edge & 15) && (on_edge & 240))
201 *jstat = 5;
202 }
203 else
204 (*jstat) = 0;
205 }
206 else goto err108;
207
208
209 /* Done. */
210
211 goto out;
212
213 /* Error in input. Conflicting dimensions. */
214
215 err106:*jstat = -106;
216 goto out;
217
218 /* Error in input. No points */
219
220 err108:*jstat = -108;
221 goto out;
222
223 out:
224 return;
225 }
226