ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/modobject.c
(Generate patch)

Comparing ray/src/common/modobject.c (file contents):
Revision 2.13 by greg, Sat Mar 9 18:53:05 2013 UTC vs.
Revision 2.16 by greg, Mon Dec 9 17:57:44 2013 UTC

# Line 88 | Line 88 | object(                                /* get an object number from its name */
88   #endif
89  
90  
91 + int
92 + eqreal(                         /* are two real values close enough to equal? */
93 +        double  d1,
94 +        double  d2
95 + )
96 + {
97 +        if (d2 != 0.0)
98 +                d1 = d1/d2 - 1.0;
99 +        return((-FTINY <= d1) & (d1 <= FTINY));
100 + }
101 +
102 +
103 + int
104 + eqobjects(                      /* check if two objects are equal */
105 +        OBJECT  obj1,
106 +        OBJECT  obj2
107 + )
108 + {
109 +        OBJREC  *op1, *op2;
110 +        int     i;
111 +
112 +        while (obj1 != obj2) {
113 +                if (obj1 == OVOID)
114 +                        return(0);
115 +                if (obj2 == OVOID)
116 +                        return(0);
117 +                op1 = objptr(obj1);
118 +                op2 = objptr(obj2);
119 +                if (op1->otype != op2->otype)
120 +                        return(0);
121 +                if (op1->oargs.nsargs != op2->oargs.nsargs)
122 +                        return(0);
123 +                if (op1->oargs.nfargs != op2->oargs.nfargs)
124 +                        return(0);
125 + #ifdef IARGS
126 +                if (op1->oargs.niargs != op2->oargs.niargs)
127 +                        return(0);
128 +                for (i = op1->oargs.niargs; i-- > 0; )
129 +                        if (op1->oargs.iarg[i] != op2->oargs.iarg[i])
130 +                                return(0);
131 + #endif
132 +                for (i = op1->oargs.nfargs; i-- > 0; )
133 +                        if (!eqreal(op1->oargs.farg[i], op2->oargs.farg[i]))
134 +                                return(0);
135 +                for (i = op1->oargs.nsargs; i-- > 0; )
136 +                        if (strcmp(op1->oargs.sarg[i], op2->oargs.sarg[i]))
137 +                                return(0);
138 +                i = 0;
139 +                switch (op1->otype) {   /* special cases (KEEP CONSISTENT!) */
140 +                case MOD_ALIAS:
141 +                case MAT_ILLUM:
142 +                case MAT_MIRROR:
143 +                        i = (op1->oargs.nsargs > 0);
144 +                        break;
145 +                case MIX_FUNC:
146 +                case MIX_DATA:
147 +                case MIX_TEXT:
148 +                case MIX_PICT:
149 +                        i = 2*(op1->oargs.nsargs >= 2);
150 +                        break;
151 +                case MAT_CLIP:
152 +                        i = op1->oargs.nsargs;
153 +                        break;
154 +                }
155 +                while (i-- > 0)         /* check modifier references */
156 +                        if (!eqobjects( lastmod(obj1, op1->oargs.sarg[i]),
157 +                                        lastmod(obj2, op2->oargs.sarg[i]) ))
158 +                                return(0);
159 +                obj1 = op1->omod;
160 +                obj2 = op2->omod;
161 +        }
162 +        return(1);
163 + }
164 +
165 +
166   void
167   insertobject(                   /* insert new object into our list */
168          OBJECT  obj
# Line 97 | Line 172 | insertobject(                  /* insert new object into our list */
172  
173          if (ismodifier(objptr(obj)->otype)) {
174                  i = otndx(objptr(obj)->oname, &modtab);
175 +                if (eqobjects(obj, modtab.htab[i]))
176 +                        return; /* don't index if same as earlier def. */
177                  modtab.htab[i] = obj;
178          }
179   #ifdef  GETOBJ

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines