--- ray/src/common/cone.c 1992/10/02 16:01:06 2.3 +++ ray/src/common/cone.c 2016/04/21 00:40:35 2.10 @@ -1,15 +1,12 @@ -/* Copyright (c) 1992 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: cone.c,v 2.10 2016/04/21 00:40:35 greg Exp $"; #endif - /* * cone.c - routines for making cones - * - * 2/12/86 */ +#include "copyright.h" + #include "standard.h" #include "object.h" @@ -44,12 +41,13 @@ static char SCCSid[] = "$SunId$ LBL"; 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) { @@ -59,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) { @@ -82,7 +80,7 @@ int getxf; else sgn1 = 0; if (sgn0+sgn1 == 0) goto raderr; - if (sgn0 < 0 | sgn1 < 0) { + if ((sgn0 < 0) | (sgn1 < 0)) { objerror(o, o->otype==OBJ_RING?USER:WARNING, "negative radii"); o->otype = o->otype == OBJ_CONE ? @@ -123,13 +121,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 */ @@ -145,32 +146,34 @@ int getxf; argcerr: objerror(o, USER, "bad # arguments"); raderr: - objerror(o, USER, "illegal radii"); + objerror(o, WARNING, "illegal radii"); + free(co); + return(NULL); } -freecone(o) /* free memory associated with cone */ -OBJREC *o; +void +freecone(OBJREC *o) /* free memory associated with cone */ { - register CONE *co = (CONE *)o->os; + CONE *co = (CONE *)o->os; - if (o->os == NULL) + if (co == NULL) return; if (co->tm != NULL) - free((char *)co->tm); - free(o->os); + free((void *)co->tm); + free((void *)co); o->os = NULL; } -conexform(co) /* get cone transformation matrix */ -register CONE *co; +void +conexform(CONE *co) /* get cone transformation matrix */ { MAT4 m4; - register double d; - register int i; + double d; + int i; - co->tm = (FLOAT (*)[4])malloc(sizeof(MAT4)); + co->tm = (RREAL (*)[4])malloc(sizeof(MAT4)); if (co->tm == NULL) error(SYSTEM, "out of memory in conexform"); @@ -206,7 +209,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);