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: sh_set_at.c,v 1.2 2001-03-19 16:06:04 afr Exp $
45  *
46  */
47 
48 
49 #define SH_SET_AT
50 
51 #include "sislP.h"
52 
53 
54 
55 
56 #if defined(SISLNEEDPROTOTYPES)
57 void
sh_set_at(SISLObject * po1,SISLObject * po2,SISLIntdat * pintdat,int * jstat)58 sh_set_at (SISLObject * po1, SISLObject * po2,
59 	SISLIntdat * pintdat, int *jstat)
60 #else
61 void
62 sh_set_at (po1, po2, pintdat,  jstat)
63      SISLObject *po1;
64      SISLObject *po2;
65      SISLIntdat *pintdat;
66      int *jstat;
67 #endif
68 /*
69 *********************************************************************
70 *
71 *********************************************************************
72 *
73 * PURPOSE    : Set SI_AT topology part.
74 *
75 *
76 * INPUT      : po1      - Pointer to the first object in the intersection.
77 *              po2      - Pointer to the second object in the intersection.
78 *              pintdat  - Intersection data of object-object intersection.
79 *
80 * OUTPUT       : jstat    - status messages
81 *                                > 0   : Warning.
82 *                                = 0   : Ok.
83 *                                < 0   : Error.
84 *
85 *
86 * METHOD     :
87 *
88 * CALLS      : sh1781_AT          - Find pre-topology of 1D curve-point.
89 *              sh1780_AT          - Find pre-topology of curve-curve.
90 *              sh1779_AT          - Find pre-topology of 3D curve-surface.
91 *
92 * REFERENCES :
93 *
94 * WRITTEN BY : Ulf J. Krystad, SI, 09.91
95 *********************************************************************
96 */
97 {
98   int kstat = 0;		/* Status variable.                        */
99   int ki;			/* Counter.                                */
100   int kdim;			/* Dimension of geometry space.            */
101   SISLIntpt *qpt = SISL_NULL;	/* Pointer to intersection point.          */
102   /* --------------------------------------------------------------------- */
103 
104   /* Init */
105   *jstat = 0;
106 
107   /* Test if an intersection data structure exist.  */
108   if (pintdat == SISL_NULL)
109     goto out;
110 
111 
112   /* Fetch dimension of geometry space. */
113   if (po1->iobj == SISLPOINT)
114 
115     kdim = po1->p1->idim;
116   else if (po1->iobj == SISLCURVE)
117     kdim = po1->c1->idim;
118   else
119     kdim = po1->s1->idim;
120 
121   /* Treat only cases:
122      crv vs pt 1D
123      crv vs crv
124      crv vs sf
125      (?sf vs pt 2D)
126      */
127 
128   if (!(((po1->iobj == SISLCURVE && po2->iobj >= SISLCURVE) ||
129 	 (po2->iobj == SISLCURVE && po1->iobj >= SISLCURVE)) ||
130 	(kdim == 1 && (po1->iobj + po2->iobj) == (SISLPOINT + SISLCURVE)) ||
131 	(kdim == 2 && (po1->iobj + po2->iobj) == (SISLPOINT + SISLSURFACE))))
132     goto out;
133 
134 
135   for (ki = 0; ki < (pintdat)->ipoint; ki++)
136   {
137      qpt = (pintdat)->vpoint[ki];
138 
139       /* Browse on the dimension of geometry space and the type of
140          the input objects.     */
141 
142       if (kdim == 1 && ((po1->iobj == SISLCURVE && po2->iobj == SISLPOINT)
143 		     || (po2->iobj == SISLCURVE && po1->iobj == SISLPOINT)))
144 	{
145 	  /* Compute pre-topology in one-dimensional curve-level value
146              intersection.            */
147 
148 	  sh1781_at (po1, po2,qpt, &kstat);
149 	  if (kstat < 0)
150 	    goto error;
151 	}
152       else if (po1->iobj == SISLCURVE && po2->iobj == SISLCURVE)
153 	{
154 	  /* curve-curve intersection.  */
155 	  sh1780_at (po1, po2, qpt, &kstat);
156 	  if (kstat < 0)
157 	    goto error;
158 	}
159       else if (kdim == 3 &&
160 	       ((po1->iobj == SISLCURVE && po2->iobj == SISLSURFACE) ||
161 		(po1->iobj == SISLSURFACE && po2->iobj == SISLCURVE)))
162 	{
163 	  /* Surface-curve intersection in 3-dimensional geometry space. */
164 
165 	  sh1779_at (po1, po2, qpt, &kstat);
166 	  if (kstat < 0)
167 	    goto error;
168 	}
169     }
170 
171   /* Task performed.  */
172 
173   *jstat = 0;
174   goto out;
175 
176   /* Error in lower level routine.  */
177 
178 error:*jstat = kstat;
179   goto out;
180 
181 out:
182    return;
183 }
184