int dupl(int n) { /* duplicate the subtree whose root is n, return ptr to it */ int i; i = name[n]; if(i < NCH) return(mn0(i)); switch(i){ case RNULLS: return(mn0(i)); case RCCL: case RNCCL: return(mnp(i,ptr[n])); case FINAL: case S1FINAL: case S2FINAL: return(mn1(i,left[n])); case STAR: case QUEST: case PLUS: case CARAT: return(mn1(i,dupl(left[n]))); case RSTR: case RSCON: return(mn2(i,dupl(left[n]),right[n])); case BAR: case RNEWE: case RCAT: case DIV: return(mn2(i,dupl(left[n]),dupl(right[n]))); # ifdef DEBUG default: warning("bad switch dupl %d",n); # endif } return(0); }
void sphere::contactSphere(const sphere& s, vec3& v, float& f) const { vec3 mn1(c - r), mx1(c + r); vec3 mn2(s.c - s.r), mx2(s.c + s.r); if(mn2 < mn1) mn1 = mn2; if(mx2 > mx1) mx1 = mx2; v = vec3((mx1 + mn1) / 2.0f); mn1 = (mx1 - mn1) / 2.0f; f = max(mn1.z, max(mn1.x, mn1.y)); }