--- ray/src/common/cone.c 2003/06/26 00:58:09 2.8 +++ ray/src/common/cone.c 2016/09/16 15:09:21 2.11 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: cone.c,v 2.8 2003/06/26 00:58:09 schorsch Exp $"; +static const char RCSid[] = "$Id: cone.c,v 2.11 2016/09/16 15:09:21 greg Exp $"; #endif /* * cone.c - routines for making cones @@ -41,12 +41,13 @@ static const char RCSid[] = "$Id: cone.c,v 2.8 2003/06 CONE * -getcone(o, getxf) /* get cone structure */ -register OBJREC *o; -int getxf; +getcone( /* get cone structure */ + OBJREC *o, + int getxf +) { int sgn0, sgn1; - register CONE *co; + CONE *co; if ((co = (CONE *)o->os) == NULL) { @@ -56,7 +57,7 @@ int getxf; co->ca = o->oargs.farg; /* get radii */ - if (o->otype == OBJ_CYLINDER | o->otype == OBJ_TUBE) { + if ((o->otype == OBJ_CYLINDER) | (o->otype == OBJ_TUBE)) { if (o->oargs.nfargs != 7) goto argcerr; if (co->ca[6] < -FTINY) { @@ -79,9 +80,10 @@ int getxf; else sgn1 = 0; if (sgn0+sgn1 == 0) goto raderr; - if (sgn0 < 0 | sgn1 < 0) { - objerror(o, o->otype==OBJ_RING?USER:WARNING, - "negative radii"); + if ((sgn0 < 0) | (sgn1 < 0)) { + if (o->otype == OBJ_RING) + goto raderr; + objerror(o, WARNING, "negative radii"); o->otype = o->otype == OBJ_CONE ? OBJ_CUP : OBJ_CONE; } @@ -120,13 +122,16 @@ int getxf; co->ad[2] = CO_P1(co)[2] - CO_P0(co)[2]; } co->al = normalize(co->ad); - if (co->al == 0.0) - objerror(o, USER, "zero orientation"); + if (co->al == 0.0) { + objerror(o, WARNING, "unknown orientation"); + free(co); + return(NULL); + } /* compute axis and side lengths */ if (o->otype == OBJ_RING) { co->al = 0.0; co->sl = CO_R1(co) - CO_R0(co); - } else if (o->otype == OBJ_CONE | o->otype == OBJ_CUP) { + } else if ((o->otype == OBJ_CONE) | (o->otype == OBJ_CUP)) { co->sl = co->ca[7] - co->ca[6]; co->sl = sqrt(co->sl*co->sl + co->al*co->al); } else { /* OBJ_CYLINDER or OBJ_TUBE */ @@ -142,16 +147,16 @@ int getxf; argcerr: objerror(o, USER, "bad # arguments"); raderr: - objerror(o, USER, "illegal radii"); - return NULL; /* pro forma return */ + objerror(o, WARNING, "illegal radii"); + free(co); + return(NULL); } void -freecone(o) /* free memory associated with cone */ -OBJREC *o; +freecone(OBJREC *o) /* free memory associated with cone */ { - register CONE *co = (CONE *)o->os; + CONE *co = (CONE *)o->os; if (co == NULL) return; @@ -163,12 +168,11 @@ OBJREC *o; void -conexform(co) /* get cone transformation matrix */ -register CONE *co; +conexform(CONE *co) /* get cone transformation matrix */ { MAT4 m4; - register double d; - register int i; + double d; + int i; co->tm = (RREAL (*)[4])malloc(sizeof(MAT4)); if (co->tm == NULL) @@ -206,7 +210,7 @@ register CONE *co; multmat4(co->tm, co->tm, m4); /* scale z-axis */ - if (co->p0 != co->p1 & co->r0 != co->r1) { + if ((co->p0 != co->p1) & (co->r0 != co->r1)) { setident4(m4); m4[2][2] = (CO_R1(co) - CO_R0(co)) / co->al; multmat4(co->tm, co->tm, m4);