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: s1992.c,v 1.2 2001-03-19 15:58:59 afr Exp $
45  *
46  */
47 
48 
49 #define S1992
50 
51 #include "sislP.h"
52 
53 /*
54 * Forward declarations.
55 * ---------------------
56 */
57 
58 #if defined(SISLNEEDPROTOTYPES)
59 static void
60 s1992_s9mbox3(double [],int,double [],double []);
61 static void
62 s1992_s9mbox2(double [],int,double [],double []);
63 static void
64 s1992_s9mbox(double [],int,int idim,double[],double []);
65 #else
66 static void s1992_s9mbox3();
67 static void s1992_s9mbox2();
68 static void s1992_s9mbox();
69 #endif
70 
71 #if defined(SISLNEEDPROTOTYPES)
72 void
s1992(SISLObject * po,int * jstat)73 s1992(SISLObject *po,int *jstat)
74 #else
75 void s1992(po,jstat)
76      SISLObject *po;
77      int    *jstat;
78 #endif
79 /*
80 *********************************************************************
81 *
82 *********************************************************************
83 *
84 * PURPOSE    : Make a SISLbox on the control-polygons given by
85 *              ecoef to the object. If dimension is 2 then one
86 *	       SISLbox rotated 45 degree is also made. If dimension
87 *	       is 3 then one SISLbox roteted 45 degree around each
88 *	       main axes, in all 4 boxes is made.
89 *
90 *
91 *
92 * INPUT      : po     - SISLObject to treat.
93 *
94 * OUTPUT     : jstat  - status messages
95 *                                         > 0      : warning
96 *                                         = 0      : ok
97 *                                         < 0      : error
98 *
99 *
100 *
101 * METHOD     :
102 *
103 *
104 * REFERENCES :
105 *
106 *-
107 * CALLS      :
108 *
109 * WRITTEN BY : Arne Laksaa, SI, 89-02.
110 *
111 *********************************************************************
112 */
113 {
114   int kpos = 0;                        /* Position of error.   */
115 
116   if (po -> iobj == SISLPOINT)
117     {
118       if (po->p1->pbox == SISL_NULL)
119 	{
120 	  if ((po->p1->pbox = newbox(po->p1->idim))==SISL_NULL)
121 	    goto err101;
122 
123 	  if (po->p1->idim == 3)
124 	    s1992_s9mbox3(po->p1->ecoef,1,po->p1->pbox->emax,
125 		    po->p1->pbox->emin);
126 	  else
127 	    if (po->p1->idim == 2)
128 	      s1992_s9mbox2(po->p1->ecoef,1,po->p1->pbox->emax,
129 		      po->p1->pbox->emin);
130 	    else
131 	      s1992_s9mbox(po->p1->ecoef,1,po->p1->idim,
132 		     po->p1->pbox->emax,po->p1->pbox->emin);
133 	}
134     }
135   else
136     if (po -> iobj == SISLCURVE)
137       {
138 	if (po->c1->pbox == SISL_NULL)
139 	  {
140 	    if ((po->c1->pbox = newbox(po->c1->idim))==SISL_NULL)
141 	      goto err101;
142 
143 	    if (po->c1->idim == 3)
144 	      s1992_s9mbox3(po->c1->ecoef,po->c1->in,po->c1->pbox->emax,
145 		      po->c1->pbox->emin);
146 	    else
147 	      if (po->c1->idim == 2)
148 		s1992_s9mbox2(po->c1->ecoef,po->c1->in,po->c1->pbox->emax,
149 			po->c1->pbox->emin);
150 	      else
151 		s1992_s9mbox(po->c1->ecoef,po->c1->in,po->c1->idim,
152 		       po->c1->pbox->emax,po->c1->pbox->emin);
153 	  }
154       }
155     else
156       if (po -> iobj == SISLSURFACE)
157 	{
158 	  if (po->s1->pbox == SISL_NULL)
159 	    {
160 	      if ((po->s1->pbox = newbox(po->s1->idim))==SISL_NULL)
161 		goto err101;
162 
163 	      if (po->s1->idim == 3)
164 		s1992_s9mbox3(po->s1->ecoef,po->s1->in1 * po->s1->in2,
165 			po->s1->pbox->emax,po->s1->pbox->emin);
166 	      else
167 		if (po->s1->idim == 2)
168 		  s1992_s9mbox2(po->s1->ecoef,po->s1->in1 * po->s1->in2,
169 			  po->s1->pbox->emax,po->s1->pbox->emin);
170 		else
171 		  s1992_s9mbox(po->s1->ecoef,po->s1->in1 * po->s1->in2,
172 			 po->s1->idim,po->s1->pbox->emax,po->s1->pbox->emin);
173 	    }
174 	}
175 
176   *jstat = 0;
177   goto out;
178 
179 
180   /* Error in space allocation.  */
181 
182  err101: *jstat = -101;
183   s6err("s1992",*jstat,kpos);
184   goto out;
185 
186  out: ;
187 }
188 
189 #if defined(SISLNEEDPROTOTYPES)
190 void
s1992cu(SISLCurve * pc,int * jstat)191 s1992cu(SISLCurve *pc,int *jstat)
192 #else
193 void s1992cu(pc,jstat)
194      SISLCurve *pc;
195      int   *jstat;
196 #endif
197 /*
198 *********************************************************************
199 *
200 *********************************************************************
201 *
202 * PURPOSE    : Make a SISLbox on the control-polygons given by
203 *              ecoef to the object. If dimension is 2 then one
204 *	       SISLbox rotated 45 degree is also made. If dimension
205 *	       is 3 then one SISLbox roteted 45 degree around each
206 *	       main axes, in all 4 boxes is made.
207 *
208 *
209 *
210 * INPUT      : pc     - SISLObject to treat.
211 *
212 * OUTPUT     : jstat  - status messages
213 *                                         > 0      : warning
214 *                                         = 0      : ok
215 *                                         < 0      : error
216 *
217 *
218 *
219 * METHOD     :
220 *
221 *
222 * REFERENCES :
223 *
224 *-
225 * CALLS      :
226 *
227 * WRITTEN BY : Arne Laksaa, SI, 89-02.
228 *
229 *********************************************************************
230 */
231 {
232   int kpos = 0;                        /* Position of error.   */
233 
234   if (pc->pbox == SISL_NULL)
235     {
236       if ((pc->pbox = newbox(pc->idim))==SISL_NULL)
237 	goto err101;
238 
239       if (pc->idim == 3)
240 	s1992_s9mbox3(pc->ecoef,pc->in,pc->pbox->emax,pc->pbox->emin);
241       else if (pc->idim == 2)
242 	s1992_s9mbox2(pc->ecoef,pc->in,pc->pbox->emax,pc->pbox->emin);
243       else
244 	s1992_s9mbox(pc->ecoef,pc->in,pc->idim,
245 	       pc->pbox->emax,pc->pbox->emin);
246     }
247 
248   *jstat = 0;
249   goto out;
250 
251 
252   /* Error in space allocation.  */
253 
254  err101: *jstat = -101;
255   s6err("s1992cu",*jstat,kpos);
256   goto out;
257 
258  out: ;
259 }
260 
261 #if defined(SISLNEEDPROTOTYPES)
262 void
s1992su(SISLSurf * ps,int * jstat)263 s1992su(SISLSurf *ps,int *jstat)
264 #else
265 void s1992su(ps,jstat)
266      SISLSurf *ps;
267      int  *jstat;
268 #endif
269 /*
270 *********************************************************************
271 *
272 *********************************************************************
273 *
274 * PURPOSE    : Make a SISLbox on the control-polygons given by
275 *              ecoef to the object. If dimension is 2 then one
276 *	       SISLbox rotated 45 degree is also made. If dimension
277 *	       is 3 then one SISLbox roteted 45 degree around each
278 *	       main axes, in all 4 boxes is made.
279 *
280 *
281 *
282 * INPUT      : ps     - SISLObject to treat.
283 *
284 * OUTPUT     : jstat  - status messages
285 *                                         > 0      : warning
286 *                                         = 0      : ok
287 *                                         < 0      : error
288 *
289 *
290 *
291 * METHOD     :
292 *
293 *
294 * REFERENCES :
295 *
296 *-
297 * CALLS      :
298 *
299 * WRITTEN BY : Arne Laksaa, SI, 89-02.
300 *
301 *********************************************************************
302 */
303 {
304   int kpos = 0;                        /* Position of error.   */
305 
306   if (ps->pbox == SISL_NULL)
307     {
308       if ((ps->pbox = newbox(ps->idim))==SISL_NULL) goto err101;
309 
310       if (ps->idim == 3) s1992_s9mbox3(ps->ecoef,ps->in1 * ps->in2,
311 				 ps->pbox->emax,ps->pbox->emin);
312 
313       else if (ps->idim == 2) s1992_s9mbox2(ps->ecoef,ps->in1 * ps->in2,
314 				      ps->pbox->emax,ps->pbox->emin);
315       else
316 	s1992_s9mbox(ps->ecoef,ps->in1 * ps->in2,
317 	       ps->idim,ps->pbox->emax,ps->pbox->emin);
318     }
319 
320   *jstat = 0;
321   goto out;
322 
323 
324   /* Error in space allocation.  */
325 
326  err101: *jstat = -101;
327   s6err("s1992su",*jstat,kpos);
328   goto out;
329 
330  out: ;
331 }
332 
333 #if defined(SISLNEEDPROTOTYPES)
334 static void
s1992_s9mbox3(double ecoef[],int icoef,double gmax[],double gmin[])335   s1992_s9mbox3(double ecoef[],int icoef,double gmax[],double gmin[])
336 #else
337 static void s1992_s9mbox3(ecoef,icoef,gmax,gmin)
338      double ecoef[];
339      int    icoef;
340      double gmax[];
341      double gmin[];
342 #endif
343 /*
344 *********************************************************************
345 *
346 *********************************************************************
347 *
348 * PURPOSE    : Make 4 boxes on the control-polygons given by
349 *              ecoef to the object.
350 *
351 *
352 * INPUT      : ecoef  - Control-polygon.
353 *              icoef - Number of vertices in control-polygon.
354 *
355 *
356 *
357 * OUTPUT     : gmax   - Array to contain maximum values of the box.
358 *	       gmin   - Array to contain minimum values of the box.
359 *
360 *
361 * METHOD     : Make 4 boxes. One ordinary and tree boxes rotated
362 *	       45 degree around the main axes.
363 *
364 *
365 * REFERENCES :
366 *
367 *-
368 * CALLS      :
369 *
370 * WRITTEN BY : Arne Laksaa, SI, 89-02.
371 *
372 *********************************************************************
373 */
374 {
375   int ki,ki1,ki2,ki3;    /* Counters.                                 */
376   double t1,t2,t3,t4;    /* To store elements of the rotation matrix. */
377   double *tmin,*tmax;    /* Pointers used to traverse gmin and gmax.  */
378 
379   /* Fetch value of first vertex.  */
380 
381   t1= ROTM * ecoef[0];
382   t2= ROTM * ecoef[1];
383   t3= ROTM * ecoef[2];
384 
385   tmin = gmin;
386   tmax = gmax;
387   *tmin = *tmax = ecoef[0];
388   tmin++; tmax++;
389   *tmin = *tmax = ecoef[1];
390   tmin++; tmax++;
391   *tmin = *tmax = ecoef[2];
392   tmin++; tmax++;
393   *tmin = *tmax = ecoef[0];
394   tmin++; tmax++;
395   *tmin = *tmax = t2-t3;
396   tmin++; tmax++;
397   *tmin = *tmax = t2+t3;
398   tmin++; tmax++;
399   *tmin = *tmax = t1-t3;
400   tmin++; tmax++;
401   *tmin = *tmax = ecoef[1];
402   tmin++; tmax++;
403   *tmin = *tmax = t1+t3;
404   tmin++; tmax++;
405   *tmin = *tmax = t1-t2;
406   tmin++; tmax++;
407   *tmin = *tmax = t1+t2;
408   tmin++; tmax++;
409   *tmin = *tmax = ecoef[2];
410 
411   /* For each vertice check and corrigate the box.  */
412 
413   for (ki=1,ki1=3,ki2=4,ki3=5; ki<icoef; ki++,ki1+=3,ki2+=3,ki3+=3)
414     {
415 
416 
417       t1= ROTM * ecoef[ki1];
418       t2= ROTM * ecoef[ki2];
419       t3= ROTM * ecoef[ki3];
420       tmin = gmin;
421       tmax = gmax;
422       if(ecoef[ki1] < *tmin) *tmin = ecoef[ki1];
423       if(ecoef[ki1] > *tmax) *tmax = ecoef[ki1];
424       tmin++; tmax++;
425       if(ecoef[ki2] < *tmin) *tmin = ecoef[ki2];
426       if(ecoef[ki2] > *tmax) *tmax = ecoef[ki2];
427       tmin++; tmax++;
428       if(ecoef[ki3] < *tmin) *tmin = ecoef[ki3];
429       if(ecoef[ki3] > *tmax) *tmax = ecoef[ki3];
430       tmin++; tmax++;
431       if(ecoef[ki1] < *tmin) *tmin = ecoef[ki1];
432       if(ecoef[ki1] > *tmax) *tmax = ecoef[ki1];
433       tmin++; tmax++;
434       t4= t2 - t3;
435       if(t4 < *tmin) *tmin = t4;
436       if(t4 > *tmax) *tmax = t4;
437       tmin++; tmax++;
438       t4= t2 + t3;
439       if(t4 < *tmin) *tmin = t4;
440       if(t4 > *tmax) *tmax = t4;
441       tmin++; tmax++;
442       t4= t1 - t3;
443       if(t4 < *tmin) *tmin = t4;
444       if(t4 > *tmax) *tmax = t4;
445       tmin++; tmax++;
446       if(ecoef[ki2] < *tmin) *tmin = ecoef[ki2];
447       if(ecoef[ki2] > *tmax) *tmax = ecoef[ki2];
448       tmin++; tmax++;
449       t4= t1 + t3;
450       if(t4 < *tmin) *tmin = t4;
451       if(t4 > *tmax) *tmax = t4;
452       tmin++; tmax++;
453       t4= t1 - t2;
454       if(t4 < *tmin) *tmin = t4;
455       if(t4 > *tmax) *tmax = t4;
456       tmin++; tmax++;
457       t4= t1 + t2;
458       if(t4 < *tmin) *tmin = t4;
459       if(t4 > *tmax) *tmax = t4;
460       tmin++; tmax++;
461       if(ecoef[ki3] < *tmin) *tmin = ecoef[ki3];
462       if(ecoef[ki3] > *tmax) *tmax = ecoef[ki3];
463     }
464 }
465 
466 #if defined(SISLNEEDPROTOTYPES)
467 static void
s1992_s9mbox2(double ecoef[],int icoef,double gmax[],double gmin[])468   s1992_s9mbox2(double ecoef[],int icoef,double gmax[],double gmin[])
469 #else
470 static void s1992_s9mbox2(ecoef,icoef,gmax,gmin)
471      double ecoef[];
472      int    icoef;
473      double gmax[];
474      double gmin[];
475 #endif
476 /*
477 *********************************************************************
478 *
479 *********************************************************************
480 *
481 * PURPOSE    : Make 2 boxes on the control-polygons given by
482 *              ecoef to the object.
483 *
484 *
485 * INPUT      : ecoef  - Control-polygon.
486 *              icoef - Number of vertices in control-polygon.
487 *
488 *
489 *
490 * OUTPUT     : gmax   - Array to contain maximum values of the box.
491 *	       gmin   - Array to contain minimum values of the box.
492 *
493 *
494 * METHOD     : Make two boxes. One ordinary and one rotated 45 degree.
495 *
496 *
497 * REFERENCES :
498 *
499 *-
500 * CALLS      :
501 *
502 * WRITTEN BY : Arne Laksaa, SI, 89-02.
503 *
504 *********************************************************************
505 */
506 {
507   int ki,ki1,ki2;        /* Counters.                                 */
508   double t1,t2,t3;       /* To store elements of the rotation matrix. */
509   double *tmin,*tmax;    /* Pointers used to traverse gmin and gmax.  */
510 
511 
512 
513   /* Fetch value of first vertex.  */
514 
515   t1= ROTM * ecoef[0];
516   t2= ROTM * ecoef[1];
517 
518   tmin = gmin;
519   tmax = gmax;
520   *tmin = *tmax = ecoef[0];
521   tmin++; tmax++;
522   *tmin = *tmax = ecoef[1];
523   tmin++; tmax++;
524   *tmin = *tmax = t1-t2;
525   tmin++; tmax++;
526   *tmin = *tmax = t1+t2;
527 
528   /* For each vertice check and corrigate the box.  */
529 
530   for (ki=1,ki1=2,ki2=3; ki<icoef; ki++,ki1+=2,ki2+=2)
531     {
532 
533 
534       t1= ROTM * ecoef[ki1];
535       t2= ROTM * ecoef[ki2];
536       tmin = gmin;
537       tmax = gmax;
538       if(ecoef[ki1] < *tmin) *tmin = ecoef[ki1];
539       if(ecoef[ki1] > *tmax) *tmax = ecoef[ki1];
540       tmin++; tmax++;
541       if(ecoef[ki2] < *tmin) *tmin = ecoef[ki2];
542       if(ecoef[ki2] > *tmax) *tmax = ecoef[ki2];
543       tmin++; tmax++;
544       t3= t1 - t2;
545       if(t3 < *tmin) *tmin = t3;
546       if(t3 > *tmax) *tmax = t3;
547       tmin++; tmax++;
548       t3= t1 + t2;
549       if(t3 < *tmin) *tmin = t3;
550       if(t3 > *tmax) *tmax = t3;
551     }
552 }
553 
554 #if defined(SISLNEEDPROTOTYPES)
555 static void
s1992_s9mbox(double ecoef[],int icoef,int idim,double gmax[],double gmin[])556   s1992_s9mbox(double ecoef[],int icoef,int idim,double gmax[],double gmin[])
557 #else
558 static void s1992_s9mbox(ecoef,icoef,idim,gmax,gmin)
559      double ecoef[];
560      int    icoef;
561      int    idim;
562      double gmax[];
563      double gmin[];
564 #endif
565 /*
566 *********************************************************************
567 *
568 *********************************************************************
569 *
570 * PURPOSE    : Make a SISLbox on the control-polygons given by
571 *              ecoef to the object.
572 *
573 *
574 * INPUT      : ecoef  - Control-polygon.
575 *              icoef - Number of vertices in control-polygon.
576 *
577 *
578 *
579 * OUTPUT     : gmax   - Array to contain maximum values of the box.
580 *	       gmin   - Array to contain minimum values of the box.
581 *
582 *
583 * METHOD     :
584 *
585 *
586 * REFERENCES :
587 *
588 *-
589 * CALLS      :
590 *
591 * WRITTEN BY : Arne Laksaa, SI, 89-02.
592 *
593 *********************************************************************
594 */
595 {
596   int ki,ki1,kj;         /* Counters.  */
597   double noice = (double)100.0 * REL_COMP_RES;   /* Noice killer */
598 
599 
600 
601   /* Fetch value of first vertex.  */
602 
603   for (ki = 0; ki < idim; ki++) gmin[ki] = gmax[ki] = ecoef[ki];
604 
605   /* For each vertice check and corrigate the box.  */
606 
607   for (kj=1; kj<icoef; kj++)
608     for (ki1 = 0; ki1 < idim; ki1++,ki++)
609       {
610 	if(ecoef[ki] < gmin[ki1]) gmin[ki1] = ecoef[ki];
611 	if(ecoef[ki] > gmax[ki1]) gmax[ki1] = ecoef[ki];
612       }
613 
614   /* ALA and UJK 30.10.90, remove noice near by zero */
615   if (idim == 1)
616     {
617       if (fabs(gmax[0]) < noice) gmax[0] = DZERO;
618       if (fabs(gmin[0]) < noice) gmin[0] = DZERO;
619     }
620 
621 }
622 
623 
624 
625 
626