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: sh6count.c,v 1.2 2001-03-19 15:59:07 afr Exp $ 45 * 46 */ 47 48 49 #define SH6COUNT 50 51 #include "sislP.h" 52 53 54 #if defined(SISLNEEDPROTOTYPES) 55 int sh6count(SISLIntpt * pt,int * jstat)56 sh6count(SISLIntpt *pt,int *jstat) 57 #else 58 int sh6count(pt,jstat) 59 SISLIntpt *pt; 60 int *jstat; 61 #endif 62 /* 63 ********************************************************************* 64 * 65 ********************************************************************* 66 * 67 * PURPOSE : Given a main Intpt 68 * return the number of points in the list (of 69 * main points) 70 * and determine whether it is open or closed 71 * through *jstat. If the Intpt is not 72 * in a unique list, say so. 73 * 74 * 75 * INPUT : pt - Pointer to the Intpt. 76 * index - Index specifying a list containing pt. 77 * jstat - Error flag. 78 * jstat = 0 => Successful. List is open. 79 * jstat = 1 => Successful. List is closed. 80 * jstat = 2 => pt is a junction pt. 81 * jstat = 3 => pt is isolated. 82 * jstat = -1 => Error in pt. 83 * jstat = -2 => List is inconsistent. 84 * 85 * 86 * 87 * METHOD : 1. Traverse forwards from pt to one end of 88 * the list. 89 * 2. Then (unless list is closed) go to the 90 * other end of the list. 91 * 92 * 93 * REFERENCES : 94 * 95 * WRITTEN BY : Michael Floater, SI, Oslo, Norway. Sept. 91. 96 * 97 ********************************************************************* 98 */ 99 { 100 int ki; /* Counter. */ 101 SISLIntpt *pt1, *pt2; /* Neighbours of pt. */ 102 SISLIntpt *lastpt, *nowpt, *nextpt; 103 /* 3 adjacents pts in the list. */ 104 int kstat; /* Status variable. */ 105 106 *jstat = 0; 107 ki=1; 108 109 if(pt == SISL_NULL) goto err1; 110 if(!sh6ismain(pt)) goto err1; 111 112 sh6getnhbrs(pt,&pt1,&pt2,&kstat); 113 if(kstat < 0) goto err2; /* Bad list. */ 114 if(kstat == 2) 115 { 116 *jstat = 2; 117 goto out; 118 } 119 if(kstat == 3) 120 { 121 *jstat = 3; 122 goto out; 123 } 124 125 126 /* Traverse in the first direction unless at the end. */ 127 128 nextpt=pt1; 129 nowpt=pt; 130 while(nextpt != SISL_NULL && nextpt != pt) 131 { 132 ki++; 133 lastpt=nowpt; 134 nowpt=nextpt; 135 sh6getother(nowpt,lastpt,&nextpt,&kstat); 136 if(kstat < 0) goto err2; /* Bad list. */ 137 } 138 139 /* Now if nextpt == pt the list is closed and we're finished. */ 140 141 if(nextpt == pt) 142 { 143 *jstat=1; 144 goto out; 145 } 146 147 /* Otherwise traverse in the second direction. */ 148 149 nextpt=pt2; 150 nowpt=pt; 151 while(nextpt != SISL_NULL) 152 { 153 ki++; 154 lastpt=nowpt; 155 nowpt=nextpt; 156 sh6getother(nowpt,lastpt,&nextpt,&kstat); 157 if(kstat < 0) goto err2; /* Bad list. */ 158 } 159 160 goto out; 161 162 err1: 163 /* Error. Error in pt or index. */ 164 *jstat = -1; 165 s6err("sh6count",*jstat,0); 166 goto out; 167 168 err2: 169 /* Error. List is inconsistent. */ 170 *jstat = -2; 171 s6err("sh6count",*jstat,0); 172 goto out; 173 174 out : 175 return ki; 176 } 177