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: pickcrvsf.c,v 1.2 2001-03-19 15:58:40 afr Exp $ 45 * 46 */ 47 48 49 #define PICK_CRV_SF 50 51 #include "sislP.h" 52 53 #if defined(SISLNEEDPROTOTYPES) 54 void pick_crv_sf(SISLObject * po1,SISLObject * po2,int ipar,SISLIntpt * pt1,SISLIntpt * pt2,SISLCurve ** rcrv,int * jstat)55 pick_crv_sf(SISLObject *po1, SISLObject *po2,int ipar, 56 SISLIntpt *pt1,SISLIntpt *pt2,SISLCurve **rcrv, 57 int *jstat) 58 #else 59 void pick_crv_sf(po1,po2,ipar,pt1,pt2,rcrv,jstat) 60 SISLObject *po1; 61 SISLObject *po2; 62 int ipar; 63 SISLIntpt *pt1; 64 SISLIntpt *pt2; 65 SISLCurve **rcrv; 66 int *jstat; 67 #endif 68 /* 69 ********************************************************************* 70 * 71 ********************************************************************* 72 * 73 * PURPOSE : Pick a curve along a given parameter direction 74 * in a surface. 75 * 76 * 77 * INPUT : po1 - first object in intersection. 78 * po2 - second object in intersection. 79 * pt1 - first intersection point. 80 * pt2 - second intersection point. 81 * ipar - index of constant parameter value 82 * 83 * 84 * 85 * OUTPUT : rcrv - SISL curve. 86 * jstat - status messages 87 * > 0 : warning 88 * = 0 : ok 89 * < 0 : error 90 * 91 * 92 * METHOD : 93 * 94 * 95 * REFERENCES : 96 * 97 *- 98 * CALLS : s1436 - Pick curve with constant second parameter. 99 * s1437 - Pick curve with constant first parameter. 100 * 101 * WRITTEN BY : UJK, SI, 91-09. 102 * 103 ********************************************************************* 104 */ 105 { 106 int kstat = 0; /* Local status parameter. */ 107 int kpos = 0; /* Position of error. */ 108 int index=0; /* Index of other par dir in surf. */ 109 int first_const; /* Flag, const first direction or not */ 110 double tpar; /* Parameter value of curve in constant parameter 111 direction. */ 112 SISLSurf *ps1=SISL_NULL; /* Pointer to surf to pick crv from */ 113 SISLCurve *pick_crv=SISL_NULL;/* Picked curve before trimming. */ 114 /* -------------------------------------------------------------------- */ 115 if (ipar < 0 || ipar >= po1->iobj + po2->iobj) goto errinp; 116 117 if (ipar >= po1->iobj) 118 { 119 /* pick from second object (must be a sf) */ 120 if (po2->iobj != SISLSURFACE) goto errinp; 121 ps1 = po2->s1; 122 index = (ipar == po1->iobj) ? po1->iobj + 1 : po1->iobj; 123 } 124 else 125 { 126 /* pick from first object (must be a sf) */ 127 if (po1->iobj != SISLSURFACE) goto errinp; 128 ps1 = po1->s1; 129 index = (ipar == 0) ? 1 : 0; 130 } 131 132 if (ipar < index) first_const = TRUE; 133 else first_const = FALSE; 134 tpar = pt1->epar[ipar]; 135 136 137 if (first_const == FALSE) 138 { 139 /* Pick curve with constant second parameter. */ 140 s1436(ps1,tpar,&pick_crv,&kstat); 141 if (kstat < 0) goto error; 142 } 143 else 144 { 145 /* Pick curve with constant first parameter. */ 146 s1437(ps1,tpar,&pick_crv,&kstat); 147 if (kstat < 0) goto error; 148 } 149 150 /* SISLCurve picked, now trim it. */ 151 if (DEQUAL(pt1->epar[index], pick_crv->et[pick_crv->ik-1]) && 152 DEQUAL(pt2->epar[index], pick_crv->et[pick_crv->in])) 153 { 154 /* Return the whole curve */ 155 (*rcrv) = pick_crv; 156 pick_crv = SISL_NULL; 157 } 158 159 160 else if(DEQUAL(pt1->epar[index], pick_crv->et[pick_crv->in]) && 161 DEQUAL(pt2->epar[index], pick_crv->et[pick_crv->ik-1])) 162 { 163 /* Return the whole curve, but turn it first */ 164 /* Return the whole curve */ 165 (*rcrv) = pick_crv; 166 pick_crv = SISL_NULL; 167 s1706(*rcrv); 168 } 169 else 170 { 171 /* Return a part of the curve */ 172 double amin = min(pt1->epar[index], pt2->epar[index]); 173 double amax = max(pt1->epar[index], pt2->epar[index]); 174 175 if (pick_crv->cuopen == SISL_CRV_PERIODIC) 176 s1713(pick_crv,amin,amax,rcrv,&kstat); 177 else 178 s1712(pick_crv,amin,amax,rcrv,&kstat); 179 180 if (kstat < 0) goto error; 181 182 if (pt1->epar[index] > pt2->epar[index]) s1706(*rcrv); 183 184 } 185 186 *jstat = 0; 187 goto out; 188 189 /* Error in input. */ 190 errinp : *jstat = -1; 191 s6err("pick_crv_sf",*jstat,kpos); 192 goto out; 193 194 /* Error in lower level routine. */ 195 error : *jstat = kstat; 196 s6err("pick_crv_sf",*jstat,kpos); 197 goto out; 198 199 out: if (pick_crv) freeCurve(pick_crv); 200 } 201