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: sh6idfcros.c,v 1.1 1994-04-21 12:10:42 boh Exp $ 45 * 46 */ 47 48 49 #define SH6IDFCROSS 50 51 #include "sislP.h" 52 53 54 #if defined(SISLNEEDPROTOTYPES) 55 void sh6idfcross(SISLIntdat * pintdat,SISLIntpt * vcross[],int * jncross,int ipar1,int ipar2,int * jstat)56 sh6idfcross(SISLIntdat *pintdat, SISLIntpt *vcross[], int *jncross, 57 int ipar1, int ipar2, int *jstat) 58 #else 59 void sh6idfcross(pintdat, vcross, jncross, ipar1, ipar2, jstat) 60 SISLIntdat *pintdat; 61 SISLIntpt *vcross[]; 62 int *jncross; 63 int ipar1; 64 int ipar2; 65 int *jstat; 66 #endif 67 /* 68 ********************************************************************* 69 * 70 ********************************************************************* 71 * 72 * PURPOSE : Given intersection data. Check if there exist 4 73 * intersection points where where the parameters 74 * corresponding to each object in the intersection 75 * are pairwise equal. 76 * 77 * 78 * INPUT : pintdat - Intersection data. 79 * vcross - Intersection points found so far. 80 * jncross - Number of intersection points found so far. 81 * ipar1 - Number of parameter directions of first object. 82 * ipar2 - Number of parameter directions of second object. 83 * 84 * OUTPUT : vcross - Intersection points found. 85 * jncross - Number of intersection points found. 86 * jstat - Status 87 * jstat = 0 => No set of points is found. 88 * jstat = 1 => Successful. 4 points are found. 89 * 90 * 91 * METHOD : 92 * 93 * 94 * REFERENCES : 95 * 96 * 97 * CALLS : s6dist - Distance between points. 98 * 99 * 100 * WRITTEN BY : Vibeke Skytt, SI, 12.92. 101 * 102 ********************************************************************* 103 */ 104 { 105 int ki,kj; /* Counters. */ 106 int kpt; /* Index of last intersection point found. */ 107 int kpar1; /* Start index of current parameter set. */ 108 int kpar2; /* Number of parameter in current set. */ 109 double tdist; /* Distance between parameter points. */ 110 SISLIntpt *pt; /* Current intersection point. */ 111 SISLIntpt *qnext; /* Next point to find. */ 112 113 114 /* Test if there is 4 points in pintdat. */ 115 116 if (pintdat->ipoint < 4) 117 { 118 /* No possibility of cross intersections. */ 119 120 *jstat = 0; 121 return; 122 } 123 124 /* Test if a set of cross intersections is found. */ 125 126 if (*jncross == 4) 127 { 128 /* Test if the second parameter set of the last intersection point 129 found is equal to that of the first point. */ 130 131 tdist = s6dist(vcross[0]->epar+ipar1,vcross[3]->epar+ipar1,ipar2); 132 if (DEQUAL(tdist+(double)1.0,(double)1.0)) 133 /* The set of points is found. */ 134 135 *jstat = 1; 136 else 137 *jstat = 0; 138 139 return; 140 } 141 142 /* Prepare for a search for the next point in the set. */ 143 144 kpt = (*jncross) - 1; 145 pt = vcross[kpt]; 146 kpar1 = (kpt % 2 == 0) ? 0 : ipar1; 147 kpar2 = (kpt % 2 == 0) ? ipar1 : ipar2; 148 149 /* Traverse the intersection points to find a point that has got 150 one parameter set equal to the current one. */ 151 152 for (ki=0; ki<pintdat->ipoint; ki++) 153 { 154 qnext = pintdat->vpoint[ki]; 155 156 /* Check if the point is found already. */ 157 158 for (kj=0; kj<=kpt; kj++) 159 if (qnext == vcross[kj]) break; 160 if (kj <= kpt) continue; 161 162 /* Check if the next point belongs to the wanted set. */ 163 164 tdist = s6dist(qnext->epar+kpar1,pt->epar+kpar1,kpar2); 165 if (DEQUAL(tdist+(double)1.0,(double)1.0)) 166 { 167 /* A point is found. */ 168 169 kpt++; 170 vcross[kpt] = qnext; 171 (*jncross)++; 172 173 /* Find next point. */ 174 175 sh6idfcross(pintdat,vcross,jncross,ipar1,ipar2,jstat); 176 if (*jstat == 1) return; /* The entire set is found. */ 177 178 (*jncross)--; 179 kpt--; 180 } 181 } 182 183 /* No set of cross intersections exist. */ 184 185 *jstat = 0; 186 return; 187 } 188