Revision: 52498
          http://brlcad.svn.sourceforge.net/brlcad/?rev=52498&view=rev
Author:   n_reed
Date:     2012-09-18 19:57:10 +0000 (Tue, 18 Sep 2012)
Log Message:
-----------
ws/style

Modified Paths:
--------------
    brlcad/trunk/src/librt/primitives/rhc/rhc.c

Modified: brlcad/trunk/src/librt/primitives/rhc/rhc.c
===================================================================
--- brlcad/trunk/src/librt/primitives/rhc/rhc.c 2012-09-18 18:31:24 UTC (rev 
52497)
+++ brlcad/trunk/src/librt/primitives/rhc/rhc.c 2012-09-18 19:57:10 UTC (rev 
52498)
@@ -205,7 +205,8 @@
  * Calculate the bounding RPP for an RHC
  */
 int
-rt_rhc_bbox(struct rt_db_internal *ip, point_t *min, point_t *max, const 
struct bn_tol *UNUSED(tol)) {
+rt_rhc_bbox(struct rt_db_internal *ip, point_t *min, point_t *max, const 
struct bn_tol *UNUSED(tol))
+{
 
     struct rt_rhc_internal *xip;
     vect_t rinv, rvect, rv2, working;
@@ -301,6 +302,7 @@
 
     /* Check for B.H == 0 */
     f = VDOT(xip->rhc_B, xip->rhc_H) / (mag_b * mag_h);
+
     if (! NEAR_ZERO(f, RT_DOT_TOL)) {
        return 1;               /* BAD */
     }
@@ -335,7 +337,7 @@
     bn_mat_trn(Rinv, R);                       /* inv of rot mat is trn */
 
     /* Compute S */
-    VSET(invsq, 1.0/magsq_h, 1.0/magsq_r, 1.0/magsq_b);
+    VSET(invsq, 1.0 / magsq_h, 1.0 / magsq_r, 1.0 / magsq_b);
     MAT_IDN(S);
     S[ 0] = sqrt(invsq[0]);
     S[ 5] = sqrt(invsq[1]);
@@ -351,11 +353,13 @@
           mag_h / 2.0, rhc->rhc_Hunit,
           mag_b / 2.0, rhc->rhc_Bunit);
     /* bounding radius */
-    stp->st_bradius = 0.5 * sqrt(magsq_h + 4.0*magsq_r + magsq_b);
+    stp->st_bradius = 0.5 * sqrt(magsq_h + 4.0 * magsq_r + magsq_b);
     /* approximate bounding radius */
     stp->st_aradius = stp->st_bradius;
 
-    if (rt_rhc_bbox(ip, &(stp->st_min), &(stp->st_max), &rtip->rti_tol)) 
return 1;
+    if (rt_rhc_bbox(ip, &(stp->st_min), &(stp->st_max), &rtip->rti_tol)) {
+       return 1;
+    }
 
     return 0;                  /* OK */
 }
@@ -418,23 +422,28 @@
 
     x = rhc->rhc_cprime;
 
-    if (ZERO(dprime[Y]) && ZERO(dprime[Z]))
+    if (ZERO(dprime[Y]) && ZERO(dprime[Z])) {
        goto check_plates;
+    }
 
     /* Find roots of the equation, using formula for quadratic */
     {
        fastf_t a, b, c;        /* coeffs of polynomial */
        fastf_t disc;           /* disc of radical */
 
-       a = dprime[Z] * dprime[Z] - dprime[Y] * dprime[Y] * (1 + 2*x);
-       b = 2*((pprime[Z] + x + 1) * dprime[Z]
-              - (2*x + 1) * dprime[Y] * pprime[Y]);
-       c = (pprime[Z]+x+1)*(pprime[Z]+x+1)
-           - (2*x + 1) * pprime[Y] * pprime[Y] - x*x;
+       a = dprime[Z] * dprime[Z] - dprime[Y] * dprime[Y] * (1 + 2 * x);
+       b = 2 * ((pprime[Z] + x + 1) * dprime[Z]
+                - (2 * x + 1) * dprime[Y] * pprime[Y]);
+       c = (pprime[Z] + x + 1) * (pprime[Z] + x + 1)
+           - (2 * x + 1) * pprime[Y] * pprime[Y] - x * x;
+
        if (!NEAR_ZERO(a, RT_PCOEF_TOL)) {
-           disc = b*b - 4 * a * c;
-           if (disc <= 0)
-               goto check_plates;
+           disc = b * b - 4 * a * c;
+
+           if (disc <= 0) {
+               goto check_plates;
+           }
+
            disc = sqrt(disc);
 
            k1 = (-b + disc) / (2.0 * a);
@@ -445,37 +454,40 @@
             * See if they fall in range.
             */
            VJOIN1(hitp->hit_vpriv, pprime, k1, dprime);                /* hit' 
*/
+
            if (hitp->hit_vpriv[X] >= -1.0
-               && hitp->hit_vpriv[X] <= 0.0
-               && hitp->hit_vpriv[Z] >= -1.0
-               && hitp->hit_vpriv[Z] <= 0.0) {
-               hitp->hit_magic = RT_HIT_MAGIC;
-               hitp->hit_dist = k1;
-               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
-               hitp++;
+               && hitp->hit_vpriv[X] <= 0.0
+               && hitp->hit_vpriv[Z] >= -1.0
+               && hitp->hit_vpriv[Z] <= 0.0) {
+               hitp->hit_magic = RT_HIT_MAGIC;
+               hitp->hit_dist = k1;
+               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
+               hitp++;
            }
 
            VJOIN1(hitp->hit_vpriv, pprime, k2, dprime);                /* hit' 
*/
+
            if (hitp->hit_vpriv[X] >= -1.0
-               && hitp->hit_vpriv[X] <= 0.0
-               && hitp->hit_vpriv[Z] >= -1.0
-               && hitp->hit_vpriv[Z] <= 0.0) {
-               hitp->hit_magic = RT_HIT_MAGIC;
-               hitp->hit_dist = k2;
-               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
-               hitp++;
+               && hitp->hit_vpriv[X] <= 0.0
+               && hitp->hit_vpriv[Z] >= -1.0
+               && hitp->hit_vpriv[Z] <= 0.0) {
+               hitp->hit_magic = RT_HIT_MAGIC;
+               hitp->hit_dist = k2;
+               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
+               hitp++;
            }
        } else if (!NEAR_ZERO(b, RT_PCOEF_TOL)) {
-           k1 = -c/b;
+           k1 = -c / b;
            VJOIN1(hitp->hit_vpriv, pprime, k1, dprime);                /* hit' 
*/
+
            if (hitp->hit_vpriv[X] >= -1.0
-               && hitp->hit_vpriv[X] <= 0.0
-               && hitp->hit_vpriv[Z] >= -1.0
-               && hitp->hit_vpriv[Z] <= 0.0) {
-               hitp->hit_magic = RT_HIT_MAGIC;
-               hitp->hit_dist = k1;
-               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
-               hitp++;
+               && hitp->hit_vpriv[X] <= 0.0
+               && hitp->hit_vpriv[Z] >= -1.0
+               && hitp->hit_vpriv[Z] <= 0.0) {
+               hitp->hit_magic = RT_HIT_MAGIC;
+               hitp->hit_dist = k1;
+               hitp->hit_surfno = RHC_NORM_BODY;       /* compute N */
+               hitp++;
            }
        }
     }
@@ -484,7 +496,8 @@
     /*
      * Check for hitting the top and end plates.
      */
- check_plates:
+check_plates:
+
     /* check front and back plates */
     if (hitp < &hits[2]  &&  !ZERO(dprime[X])) {
        /* 0 or 1 hits so far, this is worthwhile */
@@ -492,10 +505,11 @@
        k2 = (-1.0 - pprime[X]) / dprime[X];    /* back plate */
 
        VJOIN1(hitp->hit_vpriv, pprime, k1, dprime);    /* hit' */
+
        if ((hitp->hit_vpriv[Z] + x + 1.0)
            * (hitp->hit_vpriv[Z] + x + 1.0)
            - hitp->hit_vpriv[Y] * hitp->hit_vpriv[Y]
-           * (1.0 + 2*x) >= x*x
+           * (1.0 + 2 * x) >= x * x
            && hitp->hit_vpriv[Z] >= -1.0
            && hitp->hit_vpriv[Z] <= 0.0) {
            hitp->hit_magic = RT_HIT_MAGIC;
@@ -505,10 +519,11 @@
        }
 
        VJOIN1(hitp->hit_vpriv, pprime, k2, dprime);    /* hit' */
+
        if ((hitp->hit_vpriv[Z] + x + 1.0)
            * (hitp->hit_vpriv[Z] + x + 1.0)
            - hitp->hit_vpriv[Y] * hitp->hit_vpriv[Y]
-           * (1.0 + 2*x) >= x*x
+           * (1.0 + 2 * x) >= x * x
            && hitp->hit_vpriv[Z] >= -1.0
            && hitp->hit_vpriv[Z] <= 0.0) {
            hitp->hit_magic = RT_HIT_MAGIC;
@@ -524,6 +539,7 @@
        k1 = -pprime[Z] / dprime[Z];            /* top plate */
 
        VJOIN1(hitp->hit_vpriv, pprime, k1, dprime);    /* hit' */
+
        if (hitp->hit_vpriv[X] >= -1.0 &&  hitp->hit_vpriv[X] <= 0.0
            && hitp->hit_vpriv[Y] >= -1.0
            && hitp->hit_vpriv[Y] <= 1.0) {
@@ -534,8 +550,9 @@
        }
     }
 
-    if (hitp != &hits[2])
-       return 0;       /* MISS */
+    if (hitp != &hits[2]) {
+       return 0;    /* MISS */
+    }
 
     if (hits[0].hit_dist < hits[1].hit_dist) {
        /* entry is [0], exit is [1] */
@@ -556,6 +573,7 @@
        segp->seg_out = hits[0];        /* struct copy */
        BU_LIST_INSERT(&(seghead->l), &(segp->l));
     }
+
     return 2;                  /* HIT */
 }
 
@@ -574,28 +592,33 @@
        (struct rhc_specific *)stp->st_specific;
 
     VJOIN1(hitp->hit_point, rp->r_pt, hitp->hit_dist, rp->r_dir);
+
     switch (hitp->hit_surfno) {
-       case RHC_NORM_BODY:
-           c = rhc->rhc_cprime;
-           VSET(can_normal,
-                0.0,
-                hitp->hit_vpriv[Y] * (1.0 + 2.0*c),
-                -hitp->hit_vpriv[Z] - c - 1.0);
-           MAT4X3VEC(hitp->hit_normal, rhc->rhc_invRoS, can_normal);
-           VUNITIZE(hitp->hit_normal);
-           break;
-       case RHC_NORM_TOP:
-           VREVERSE(hitp->hit_normal, rhc->rhc_Bunit);
-           break;
-       case RHC_NORM_FRT:
-           VREVERSE(hitp->hit_normal, rhc->rhc_Hunit);
-           break;
-       case RHC_NORM_BACK:
-           VMOVE(hitp->hit_normal, rhc->rhc_Hunit);
-           break;
-       default:
-           bu_log("rt_rhc_norm: surfno=%d bad\n", hitp->hit_surfno);
-           break;
+    case RHC_NORM_BODY:
+       c = rhc->rhc_cprime;
+       VSET(can_normal,
+            0.0,
+            hitp->hit_vpriv[Y] * (1.0 + 2.0 * c),
+            -hitp->hit_vpriv[Z] - c - 1.0);
+       MAT4X3VEC(hitp->hit_normal, rhc->rhc_invRoS, can_normal);
+       VUNITIZE(hitp->hit_normal);
+       break;
+
+    case RHC_NORM_TOP:
+       VREVERSE(hitp->hit_normal, rhc->rhc_Bunit);
+       break;
+
+    case RHC_NORM_FRT:
+       VREVERSE(hitp->hit_normal, rhc->rhc_Hunit);
+       break;
+
+    case RHC_NORM_BACK:
+       VMOVE(hitp->hit_normal, rhc->rhc_Hunit);
+       break;
+
+    default:
+       bu_log("rt_rhc_norm: surfno=%d bad\n", hitp->hit_surfno);
+       break;
     }
 }
 
@@ -614,27 +637,28 @@
        (struct rhc_specific *)stp->st_specific;
 
     switch (hitp->hit_surfno) {
-       case RHC_NORM_BODY:
-           /* most nearly flat direction */
-           VMOVE(cvp->crv_pdir, rhc->rhc_Hunit);
-           cvp->crv_c1 = 0;
-           /* k = z'' / (1 + z'^2) ^ 3/2 */
-           b = rhc->rhc_b;
-           c = rhc->rhc_c;
-           y = hitp->hit_point[Y];
-           rsq = rhc->rhc_rsq;
-           zp1_sq = y * (b*b + 2*b*c) / rsq;
-           zp1_sq *= zp1_sq / (c*c + y*y*(b*b + 2*b*c)/rsq);
-           zp2 = c*c / (rsq*c*c + y*y*(b*b + 2*b*c));
-           cvp->crv_c2 = zp2 / pow((1 + zp1_sq), 1.5);
-           break;
-       case RHC_NORM_BACK:
-       case RHC_NORM_FRT:
-       case RHC_NORM_TOP:
-           /* any tangent direction */
-           bn_vec_ortho(cvp->crv_pdir, hitp->hit_normal);
-           cvp->crv_c1 = cvp->crv_c2 = 0;
-           break;
+    case RHC_NORM_BODY:
+       /* most nearly flat direction */
+       VMOVE(cvp->crv_pdir, rhc->rhc_Hunit);
+       cvp->crv_c1 = 0;
+       /* k = z'' / (1 + z'^2) ^ 3/2 */
+       b = rhc->rhc_b;
+       c = rhc->rhc_c;
+       y = hitp->hit_point[Y];
+       rsq = rhc->rhc_rsq;
+       zp1_sq = y * (b * b + 2 * b * c) / rsq;
+       zp1_sq *= zp1_sq / (c * c + y * y * (b * b + 2 * b * c) / rsq);
+       zp2 = c * c / (rsq * c * c + y * y * (b * b + 2 * b * c));
+       cvp->crv_c2 = zp2 / pow((1 + zp1_sq), 1.5);
+       break;
+
+    case RHC_NORM_BACK:
+    case RHC_NORM_FRT:
+    case RHC_NORM_TOP:
+       /* any tangent direction */
+       bn_vec_ortho(cvp->crv_pdir, hitp->hit_normal);
+       cvp->crv_c1 = cvp->crv_c2 = 0;
+       break;
     }
 }
 
@@ -656,7 +680,9 @@
     vect_t pprime;
     fastf_t len;
 
-    if (ap) RT_CK_APPLICATION(ap);
+    if (ap) {
+       RT_CK_APPLICATION(ap);
+    }
 
     /*
      * hit_point is on surface;  project back to unit rhc,
@@ -666,23 +692,25 @@
     MAT4X3VEC(pprime, rhc->rhc_SoR, work);
 
     switch (hitp->hit_surfno) {
-       case RHC_NORM_BODY:
-           /* Skin.  x, y coordinates define rotation.  radius = 1 */
-           len = sqrt(pprime[Y]*pprime[Y] + pprime[Z]*pprime[Z]);
-           uvp->uv_u = acos(pprime[Y]/len) * bn_invpi;
-           uvp->uv_v = -pprime[X];             /* height */
-           break;
-       case RHC_NORM_FRT:
-       case RHC_NORM_BACK:
-           /* end plates - circular mapping, not seamless w/body, top */
-           len = sqrt(pprime[Y]*pprime[Y] + pprime[Z]*pprime[Z]);
-           uvp->uv_u = acos(pprime[Y]/len) * bn_invpi;
-           uvp->uv_v = len;    /* rim v = 1 for both plates */
-           break;
-       case RHC_NORM_TOP:
-           uvp->uv_u = 1.0 - (pprime[Y] + 1.0)/2.0;
-           uvp->uv_v = -pprime[X];             /* height */
-           break;
+    case RHC_NORM_BODY:
+       /* Skin.  x, y coordinates define rotation.  radius = 1 */
+       len = sqrt(pprime[Y] * pprime[Y] + pprime[Z] * pprime[Z]);
+       uvp->uv_u = acos(pprime[Y] / len) * bn_invpi;
+       uvp->uv_v = -pprime[X];         /* height */
+       break;
+
+    case RHC_NORM_FRT:
+    case RHC_NORM_BACK:
+       /* end plates - circular mapping, not seamless w/body, top */
+       len = sqrt(pprime[Y] * pprime[Y] + pprime[Z] * pprime[Z]);
+       uvp->uv_u = acos(pprime[Y] / len) * bn_invpi;
+       uvp->uv_v = len;        /* rim v = 1 for both plates */
+       break;
+
+    case RHC_NORM_TOP:
+       uvp->uv_u = 1.0 - (pprime[Y] + 1.0) / 2.0;
+       uvp->uv_v = -pprime[X];         /* height */
+       break;
     }
 
     /* uv_du should be relative to rotation, uv_dv relative to height */
@@ -748,6 +776,7 @@
 
     /* Check for B.H == 0 */
     f = VDOT(xip->rhc_B, xip->rhc_H) / (b * h);
+
     if (! NEAR_ZERO(f, RT_DOT_TOL)) {
        bu_log("rt_rhc_plot: B not perpendicular to H, f=%f\n", f);
        return -3;              /* BAD */
@@ -774,33 +803,39 @@
        dtol = 0.0;             /* none */
     } else {
        /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b)
+       if (rh < b) {
            dtol = ttol->rel * 2 * rh;
-       else
+       } else {
            dtol = ttol->rel * 2 * b;
+       }
     }
+
     if (ttol->abs <= 0.0) {
        if (dtol <= 0.0) {
            /* No tolerance given, use a default */
-           if (rh < b)
-               dtol = 2 * 0.10 * rh;   /* 10% */
-           else
-               dtol = 2 * 0.10 * b;    /* 10% */
+           if (rh < b) {
+               dtol = 2 * 0.10 * rh;    /* 10% */
+           } else {
+               dtol = 2 * 0.10 * b;    /* 10% */
+           }
        } else {
            /* Use absolute-ized relative tolerance */
        }
     } else {
        /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
+       if (ttol->rel <= 0.0 || dtol > ttol->abs) {
            dtol = ttol->abs;
+       }
     }
 
     /* To ensure normal tolerance, remain below this angle */
-    if (ttol->norm > 0.0)
+    if (ttol->norm > 0.0) {
        ntol = ttol->norm;
-    else
+    } else
        /* tolerate everything */
+    {
        ntol = bn_pi;
+    }
 
     /* initial hyperbola approximation is a single segment */
     pts = (struct rt_pt_node *)bu_malloc(sizeof(struct rt_pt_node), 
"rt_pt_node");
@@ -814,12 +849,13 @@
     n += rt_mk_hyperbola(pts, rh, b, c, dtol, ntol);
 
     /* get mem for arrays */
-    front = (fastf_t *)bu_malloc(3*n * sizeof(fastf_t), "fast_t");
-    back  = (fastf_t *)bu_malloc(3*n * sizeof(fastf_t), "fast_t");
+    front = (fastf_t *)bu_malloc(3 * n * sizeof(fastf_t), "fast_t");
+    back  = (fastf_t *)bu_malloc(3 * n * sizeof(fastf_t), "fast_t");
 
     /* generate front & back plates in world coordinates */
     pos = pts;
     i = 0;
+
     while (pos) {
        /* rotate back to original position */
        MAT4X3VEC(&front[i], invR, pos->p);
@@ -834,22 +870,24 @@
     }
 
     /* Draw the front */
-    RT_ADD_VLIST(vhead, &front[(n-1)*ELEMENTS_PER_VECT],
-                BN_VLIST_LINE_MOVE);
+    RT_ADD_VLIST(vhead, &front[(n - 1)*ELEMENTS_PER_VECT],
+                BN_VLIST_LINE_MOVE);
+
     for (i = 0; i < n; i++) {
-       RT_ADD_VLIST(vhead, &front[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
+       RT_ADD_VLIST(vhead, &front[i * ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
     }
 
     /* Draw the back */
-    RT_ADD_VLIST(vhead, &back[(n-1)*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE);
+    RT_ADD_VLIST(vhead, &back[(n - 1)*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE);
+
     for (i = 0; i < n; i++) {
-       RT_ADD_VLIST(vhead, &back[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
+       RT_ADD_VLIST(vhead, &back[i * ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
     }
 
     /* Draw connections */
     for (i = 0; i < n; i++) {
-       RT_ADD_VLIST(vhead, &front[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE);
-       RT_ADD_VLIST(vhead, &back[i*ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
+       RT_ADD_VLIST(vhead, &front[i * ELEMENTS_PER_VECT], BN_VLIST_LINE_MOVE);
+       RT_ADD_VLIST(vhead, &back[i * ELEMENTS_PER_VECT], BN_VLIST_LINE_DRAW);
     }
 
     /* free mem */
@@ -886,36 +924,48 @@
     intr = p0[Z] - m * p0[Y];
     /* find point on hyperbola with max dist between hyperbola and line */
     j = b + c;
-    k = 1 - m*m*r*r/(b*(b + 2*c));
+    k = 1 - m * m * r * r / (b * (b + 2 * c));
     A = k;
-    B = 2*j*k;
-    C = j*j*k - c*c;
-    discr = sqrt(B*B - 4*A*C);
+    B = 2 * j * k;
+    C = j * j * k - c * c;
+    discr = sqrt(B * B - 4 * A * C);
     z0 = (-B + discr) / (2. * A);
-    if (z0+RHC_TOL >= -b)      /* use top sheet of hyperboloid */
+
+    if (z0 + RHC_TOL >= -b) {  /* use top sheet of hyperboloid */
        mpt[Z] = z0;
-    else
+    } else {
        mpt[Z] = (-B - discr) / (2. * A);
-    if (NEAR_ZERO(mpt[Z], RHC_TOL))
+    }
+
+    if (NEAR_ZERO(mpt[Z], RHC_TOL)) {
        mpt[Z] = 0.;
+    }
+
     mpt[X] = 0;
-    mpt[Y] = ((mpt[Z] + b + c) * (mpt[Z] + b + c) - c*c) / (b*(b + 2*c));
-    if (NEAR_ZERO(mpt[Y], RHC_TOL))
+    mpt[Y] = ((mpt[Z] + b + c) * (mpt[Z] + b + c) - c * c) / (b * (b + 2 * c));
+
+    if (NEAR_ZERO(mpt[Y], RHC_TOL)) {
        mpt[Y] = 0.;
+    }
+
     mpt[Y] = r * sqrt(mpt[Y]);
-    if (p0[Y] < 0.)
+
+    if (p0[Y] < 0.) {
        mpt[Y] = -mpt[Y];
+    }
+
     /* max distance between that point and line */
     dist = fabs(m * mpt[Y] - mpt[Z] + intr) / sqrt(m * m + 1);
     /* angles between normal of line and of hyperbola at line endpoints */
     VSET(norm_line, m, -1., 0.);
-    VSET(norm_hyperb, 0., (2*c + 1) / (p0[Z] + c + 1), -1.);
+    VSET(norm_hyperb, 0., (2 * c + 1) / (p0[Z] + c + 1), -1.);
     VUNITIZE(norm_line);
     VUNITIZE(norm_hyperb);
     theta0 = fabs(acos(VDOT(norm_line, norm_hyperb)));
-    VSET(norm_hyperb, 0., (2*c + 1) / (p1[Z] + c + 1), -1.);
+    VSET(norm_hyperb, 0., (2 * c + 1) / (p1[Z] + c + 1), -1.);
     VUNITIZE(norm_hyperb);
     theta1 = fabs(acos(VDOT(norm_line, norm_hyperb)));
+
     /* split segment at widest point if not within error tolerances */
     if (dist > dtol || theta0 > ntol || theta1 > ntol) {
        /* split segment */
@@ -929,8 +979,10 @@
        n += rt_mk_hyperbola(pts, r, b, c, dtol, ntol);
        /* recurse on second new segment */
        n += rt_mk_hyperbola(newpt, r, b, c, dtol, ntol);
-    } else
+    } else {
        n  = 0;
+    }
+
     return n;
 }
 
@@ -958,7 +1010,7 @@
     struct vertex **vfront, **vback, **vtemp, *vertlist[4];
     vect_t *norms;
     fastf_t bb_plus_2bc, b_plus_c, r_sq;
-    int failure=0;
+    int failure = 0;
 
     NMG_CK_MODEL(m);
     BN_CK_TOL(tol);
@@ -983,6 +1035,7 @@
 
     /* Check for B.H == 0 */
     f = VDOT(xip->rhc_B, xip->rhc_H) / (b * h);
+
     if (! NEAR_ZERO(f, RT_DOT_TOL)) {
        bu_log("rt_rhc_tess: B not perpendicular to H, f=%f\n", f);
        return -3;              /* BAD */
@@ -1009,33 +1062,39 @@
        dtol = 0.0;             /* none */
     } else {
        /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b)
+       if (rh < b) {
            dtol = ttol->rel * 2 * rh;
-       else
+       } else {
            dtol = ttol->rel * 2 * b;
+       }
     }
+
     if (ttol->abs <= 0.0) {
        if (dtol <= 0.0) {
            /* No tolerance given, use a default */
-           if (rh < b)
-               dtol = 2 * 0.10 * rh;   /* 10% */
-           else
-               dtol = 2 * 0.10 * b;    /* 10% */
+           if (rh < b) {
+               dtol = 2 * 0.10 * rh;    /* 10% */
+           } else {
+               dtol = 2 * 0.10 * b;    /* 10% */
+           }
        } else {
            /* Use absolute-ized relative tolerance */
        }
     } else {
        /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
+       if (ttol->rel <= 0.0 || dtol > ttol->abs) {
            dtol = ttol->abs;
+       }
     }
 
     /* To ensure normal tolerance, remain below this angle */
-    if (ttol->norm > 0.0)
+    if (ttol->norm > 0.0) {
        ntol = ttol->norm;
-    else
+    } else
        /* tolerate everything */
+    {
        ntol = bn_pi;
+    }
 
     /* initial hyperbola approximation is a single segment */
     pts = (struct rt_pt_node *)bu_malloc(sizeof(struct rt_pt_node), 
"rt_pt_node");
@@ -1049,31 +1108,33 @@
     n += rt_mk_hyperbola(pts, rh, b, c, dtol, ntol);
 
     /* get mem for arrays */
-    front = (fastf_t *)bu_malloc(3*n * sizeof(fastf_t), "fastf_t");
-    back  = (fastf_t *)bu_malloc(3*n * sizeof(fastf_t), "fastf_t");
+    front = (fastf_t *)bu_malloc(3 * n * sizeof(fastf_t), "fastf_t");
+    back  = (fastf_t *)bu_malloc(3 * n * sizeof(fastf_t), "fastf_t");
     norms = (vect_t *)bu_calloc(n, sizeof(vect_t), "rt_rhc_tess: norms");
-    vfront = (struct vertex **)bu_malloc((n+1) * sizeof(struct vertex *), 
"vertex *");
-    vback = (struct vertex **)bu_malloc((n+1) * sizeof(struct vertex *), 
"vertex *");
-    vtemp = (struct vertex **)bu_malloc((n+1) * sizeof(struct vertex *), 
"vertex *");
+    vfront = (struct vertex **)bu_malloc((n + 1) * sizeof(struct vertex *), 
"vertex *");
+    vback = (struct vertex **)bu_malloc((n + 1) * sizeof(struct vertex *), 
"vertex *");
+    vtemp = (struct vertex **)bu_malloc((n + 1) * sizeof(struct vertex *), 
"vertex *");
     outfaceuses =
-       (struct faceuse **)bu_malloc((n+2) * sizeof(struct faceuse *), "faceuse 
*");
+       (struct faceuse **)bu_malloc((n + 2) * sizeof(struct faceuse *), 
"faceuse *");
+
     if (!front || !back || !vfront || !vback || !vtemp || !outfaceuses) {
        fprintf(stderr, "rt_rhc_tess: no memory!\n");
        goto fail;
     }
 
     /* generate front & back plates in world coordinates */
-    bb_plus_2bc = b*b + 2.0*b*c;
+    bb_plus_2bc = b * b + 2.0 * b * c;
     b_plus_c = b + c;
-    r_sq = rh*rh;
+    r_sq = rh * rh;
     pos = pts;
     i = 0;
     j = 0;
+
     while (pos) {
        vect_t tmp_norm;
 
        /* calculate normal for 2D hyperbola */
-       VSET(tmp_norm, 0.0, pos->p[Y]*bb_plus_2bc, 
(-r_sq*(pos->p[Z]+b_plus_c)));
+       VSET(tmp_norm, 0.0, pos->p[Y]*bb_plus_2bc, (-r_sq * (pos->p[Z] + 
b_plus_c)));
        MAT4X3VEC(norms[j], invR, tmp_norm);
        VUNITIZE(norms[j]);
        /* rotate back to original position */
@@ -1092,7 +1153,7 @@
     *r = nmg_mrsv(m);  /* Make region, empty shell, vertex */
     s = BU_LIST_FIRST(shell, &(*r)->s_hd);
 
-    for (i=0; i<n; i++) {
+    for (i = 0; i < n; i++) {
        vfront[i] = vtemp[i] = (struct vertex *)0;
     }
 
@@ -1103,8 +1164,11 @@
 
     /* Back face topology.  Verts must go in opposite dir (CW) */
     outfaceuses[1] = nmg_cface(s, vtemp, n);
-    for (i=0; i<n; i++) vback[i] = vtemp[n-1-i];
 
+    for (i = 0; i < n; i++) {
+       vback[i] = vtemp[n - 1 - i];
+    }
+
     (void)nmg_mark_edges_real(&outfaceuses[1]->l.magic);
 
     /* Duplicate [0] as [n] to handle loop end condition, below */
@@ -1115,31 +1179,32 @@
      * connecting the front and back faces.
      * increasing indices go towards counter-clockwise (CCW).
      */
-    for (i=0; i<n; i++) {
+    for (i = 0; i < n; i++) {
        vertlist[0] = vfront[i];        /* from top, */
        vertlist[1] = vback[i];         /* straight down, */
-       vertlist[2] = vback[i+1];       /* to left, */
-       vertlist[3] = vfront[i+1];      /* straight up. */
-       outfaceuses[2+i] = nmg_cface(s, vertlist, 4);
+       vertlist[2] = vback[i + 1];     /* to left, */
+       vertlist[3] = vfront[i + 1];    /* straight up. */
+       outfaceuses[2 + i] = nmg_cface(s, vertlist, 4);
     }
 
-    (void)nmg_mark_edges_real(&outfaceuses[n+1]->l.magic);
+    (void)nmg_mark_edges_real(&outfaceuses[n + 1]->l.magic);
 
-    for (i=0; i<n; i++) {
+    for (i = 0; i < n; i++) {
        NMG_CK_VERTEX(vfront[i]);
        NMG_CK_VERTEX(vback[i]);
     }
 
     /* Associate the vertex geometry, CCW */
-    for (i=0; i<n; i++) {
-       nmg_vertex_gv(vfront[i], &front[3*(i)]);
+    for (i = 0; i < n; i++) {
+       nmg_vertex_gv(vfront[i], &front[3 * (i)]);
     }
-    for (i=0; i<n; i++) {
-       nmg_vertex_gv(vback[i], &back[3*(i)]);
+
+    for (i = 0; i < n; i++) {
+       nmg_vertex_gv(vback[i], &back[3 * (i)]);
     }
 
     /* Associate the face geometry */
-    for (i=0; i < n+2; i++) {
+    for (i = 0; i < n + 2; i++) {
        if (nmg_fu_planeeqn(outfaceuses[i], tol) < 0) {
            failure = (-1);
            goto fail;
@@ -1147,7 +1212,7 @@
     }
 
     /* Associate vertexuse normals */
-    for (i=0; i<n; i++) {
+    for (i = 0; i < n; i++) {
        struct vertexuse *vu;
        struct faceuse *fu;
        vect_t rev_norm;
@@ -1156,54 +1221,62 @@
 
        /* do "front" vertices */
        NMG_CK_VERTEX(vfront[i]);
+
        for (BU_LIST_FOR(vu, vertexuse, &vfront[i]->vu_hd)) {
            NMG_CK_VERTEXUSE(vu);
            fu = nmg_find_fu_of_vu(vu);
            NMG_CK_FACEUSE(fu);
+
            if (fu->f_p == outfaceuses[0]->f_p ||
-               fu->f_p == outfaceuses[1]->f_p ||
-               fu->f_p == outfaceuses[n+1]->f_p)
-               continue;       /* skip flat faces */
+               fu->f_p == outfaceuses[1]->f_p ||
+               fu->f_p == outfaceuses[n + 1]->f_p) {
+               continue;    /* skip flat faces */
+           }
 
-           if (fu->orientation == OT_SAME)
-               nmg_vertexuse_nv(vu, norms[i]);
-           else if (fu->orientation == OT_OPPOSITE)
-               nmg_vertexuse_nv(vu, rev_norm);
+           if (fu->orientation == OT_SAME) {
+               nmg_vertexuse_nv(vu, norms[i]);
+           } else if (fu->orientation == OT_OPPOSITE) {
+               nmg_vertexuse_nv(vu, rev_norm);
+           }
        }
 
        /* and "back" vertices */
        NMG_CK_VERTEX(vback[i]);
+
        for (BU_LIST_FOR(vu, vertexuse, &vback[i]->vu_hd)) {
            NMG_CK_VERTEXUSE(vu);
            fu = nmg_find_fu_of_vu(vu);
            NMG_CK_FACEUSE(fu);
+
            if (fu->f_p == outfaceuses[0]->f_p ||
-               fu->f_p == outfaceuses[1]->f_p ||
-               fu->f_p == outfaceuses[n+1]->f_p)
-               continue;       /* skip flat faces */
+               fu->f_p == outfaceuses[1]->f_p ||
+               fu->f_p == outfaceuses[n + 1]->f_p) {
+               continue;    /* skip flat faces */
+           }
 
-           if (fu->orientation == OT_SAME)
-               nmg_vertexuse_nv(vu, norms[i]);
-           else if (fu->orientation == OT_OPPOSITE)
-               nmg_vertexuse_nv(vu, rev_norm);
+           if (fu->orientation == OT_SAME) {
+               nmg_vertexuse_nv(vu, norms[i]);
+           } else if (fu->orientation == OT_OPPOSITE) {
+               nmg_vertexuse_nv(vu, rev_norm);
+           }
        }
     }
 
     /* Glue the edges of different outward pointing face uses together */
-    nmg_gluefaces(outfaceuses, n+2, tol);
+    nmg_gluefaces(outfaceuses, n + 2, tol);
 
     /* Compute "geometry" for region and shell */
     nmg_region_a(*r, tol);
 
- fail:
+fail:
     /* free mem */
     bu_free((char *)front, "fastf_t");
     bu_free((char *)back, "fastf_t");
-    bu_free((char*)vfront, "vertex *");
-    bu_free((char*)vback, "vertex *");
-    bu_free((char*)vtemp, "vertex *");
+    bu_free((char *)vfront, "vertex *");
+    bu_free((char *)vback, "vertex *");
+    bu_free((char *)vtemp, "vertex *");
     bu_free((char *)norms, "rt_rhc_tess: norms");
-    bu_free((char*)outfaceuses, "faceuse *");
+    bu_free((char *)outfaceuses, "faceuse *");
 
     return failure;
 }
@@ -1222,10 +1295,13 @@
     union record *rp;
     vect_t v1, v2, v3;
 
-    if (dbip) RT_CK_DBI(dbip);
+    if (dbip) {
+       RT_CK_DBI(dbip);
+    }
 
     BU_CK_EXTERNAL(ep);
     rp = (union record *)ep->ext_buf;
+
     /* Check record type */
     if (rp->u_id != ID_SOLID) {
        bu_log("rt_rhc_import4: defective record\n");
@@ -1241,16 +1317,18 @@
     xip->rhc_magic = RT_RHC_INTERNAL_MAGIC;
 
     /* Warning:  type conversion */
-    if (mat == NULL) mat = bn_mat_identity;
+    if (mat == NULL) {
+       mat = bn_mat_identity;
+    }
 
     if (dbip->dbi_version < 0) {
-       flip_fastf_float(v1, &rp->s.s_values[0*3], 1, 1);
-       flip_fastf_float(v2, &rp->s.s_values[1*3], 1, 1);
-       flip_fastf_float(v3, &rp->s.s_values[2*3], 1, 1);
+       flip_fastf_float(v1, &rp->s.s_values[0 * 3], 1, 1);
+       flip_fastf_float(v2, &rp->s.s_values[1 * 3], 1, 1);
+       flip_fastf_float(v3, &rp->s.s_values[2 * 3], 1, 1);
     } else {
-       VMOVE(v1, &rp->s.s_values[0*3]);
-       VMOVE(v2, &rp->s.s_values[1*3]);
-       VMOVE(v3, &rp->s.s_values[2*3]);
+       VMOVE(v1, &rp->s.s_values[0 * 3]);
+       VMOVE(v2, &rp->s.s_values[1 * 3]);
+       VMOVE(v3, &rp->s.s_values[2 * 3]);
     }
 
     MAT4X3PNT(xip->rhc_V, mat, v1);
@@ -1258,11 +1336,11 @@
     MAT4X3VEC(xip->rhc_B, mat, v3);
 
     if (dbip->dbi_version < 0) {
-       v1[X] = flip_dbfloat(rp->s.s_values[3*3+0]);
-       v1[Y] = flip_dbfloat(rp->s.s_values[3*3+1]);
+       v1[X] = flip_dbfloat(rp->s.s_values[3 * 3 + 0]);
+       v1[Y] = flip_dbfloat(rp->s.s_values[3 * 3 + 1]);
     } else {
-       v1[X] = rp->s.s_values[3*3+0];
-       v1[Y] = rp->s.s_values[3*3+1];
+       v1[X] = rp->s.s_values[3 * 3 + 0];
+       v1[Y] = rp->s.s_values[3 * 3 + 1];
     }
 
     xip->rhc_r = v1[X] / mat[15];
@@ -1289,10 +1367,16 @@
     struct rt_rhc_internal *xip;
     union record *rhc;
 
-    if (dbip) RT_CK_DBI(dbip);
+    if (dbip) {
+       RT_CK_DBI(dbip);
+    }
 
     RT_CK_DB_INTERNAL(ip);
-    if (ip->idb_type != ID_RHC) return -1;
+
+    if (ip->idb_type != ID_RHC) {
+       return -1;
+    }
+
     xip = (struct rt_rhc_internal *)ip->idb_ptr;
     RT_RHC_CK_MAGIC(xip);
 
@@ -1319,6 +1403,7 @@
        VUNITIZE(ub);
        VMOVE(uh, xip->rhc_H);
        VUNITIZE(uh);
+
        if (!NEAR_ZERO(VDOT(ub, uh), RT_DOT_TOL)) {
            bu_log("rt_rhc_export4: B and H are not perpendicular!\n");
            return -1;
@@ -1326,11 +1411,11 @@
     }
 
     /* Warning:  type conversion */
-    VSCALE(&rhc->s.s_values[0*3], xip->rhc_V, local2mm);
-    VSCALE(&rhc->s.s_values[1*3], xip->rhc_H, local2mm);
-    VSCALE(&rhc->s.s_values[2*3], xip->rhc_B, local2mm);
-    rhc->s.s_values[3*3] = xip->rhc_r * local2mm;
-    rhc->s.s_values[3*3+1] = xip->rhc_c * local2mm;
+    VSCALE(&rhc->s.s_values[0 * 3], xip->rhc_V, local2mm);
+    VSCALE(&rhc->s.s_values[1 * 3], xip->rhc_H, local2mm);
+    VSCALE(&rhc->s.s_values[2 * 3], xip->rhc_B, local2mm);
+    rhc->s.s_values[3 * 3] = xip->rhc_r * local2mm;
+    rhc->s.s_values[3 * 3 + 1] = xip->rhc_c * local2mm;
 
     return 0;
 }
@@ -1348,10 +1433,12 @@
     struct rt_rhc_internal *xip;
     fastf_t vec[11];
 
-    if (dbip) RT_CK_DBI(dbip);
+    if (dbip) {
+       RT_CK_DBI(dbip);
+    }
 
     BU_CK_EXTERNAL(ep);
-    BU_ASSERT_LONG(ep->ext_nbytes, ==, SIZEOF_NETWORK_DOUBLE * 11);
+    BU_ASSERT_LONG(ep->ext_nbytes, == , SIZEOF_NETWORK_DOUBLE * 11);
 
     RT_CK_DB_INTERNAL(ip);
     ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
@@ -1366,13 +1453,16 @@
     ntohd((unsigned char *)vec, ep->ext_buf, 11);
 
     /* Apply modeling transformations */
-    if (mat == NULL) mat = bn_mat_identity;
-    MAT4X3PNT(xip->rhc_V, mat, &vec[0*3]);
-    MAT4X3VEC(xip->rhc_H, mat, &vec[1*3]);
-    MAT4X3VEC(xip->rhc_B, mat, &vec[2*3]);
-    xip->rhc_r = vec[3*3] / mat[15];
-    xip->rhc_c = vec[3*3+1] / mat[15];
+    if (mat == NULL) {
+       mat = bn_mat_identity;
+    }
 
+    MAT4X3PNT(xip->rhc_V, mat, &vec[0 * 3]);
+    MAT4X3VEC(xip->rhc_H, mat, &vec[1 * 3]);
+    MAT4X3VEC(xip->rhc_B, mat, &vec[2 * 3]);
+    xip->rhc_r = vec[3 * 3] / mat[15];
+    xip->rhc_c = vec[3 * 3 + 1] / mat[15];
+
     if (xip->rhc_r <= SMALL_FASTF || xip->rhc_c <= SMALL_FASTF) {
        bu_log("rt_rhc_import4: r or c are zero\n");
        bu_free((char *)ip->idb_ptr, "rt_rhc_import4: ip->idb_ptr");
@@ -1394,10 +1484,16 @@
     struct rt_rhc_internal *xip;
     fastf_t vec[11];
 
-    if (dbip) RT_CK_DBI(dbip);
+    if (dbip) {
+       RT_CK_DBI(dbip);
+    }
 
     RT_CK_DB_INTERNAL(ip);
-    if (ip->idb_type != ID_RHC) return -1;
+
+    if (ip->idb_type != ID_RHC) {
+       return -1;
+    }
+
     xip = (struct rt_rhc_internal *)ip->idb_ptr;
     RT_RHC_CK_MAGIC(xip);
 
@@ -1420,6 +1516,7 @@
        VUNITIZE(ub);
        VMOVE(uh, xip->rhc_H);
        VUNITIZE(uh);
+
        if (!NEAR_ZERO(VDOT(ub, uh), RT_DOT_TOL)) {
            bu_log("rt_rhc_export4: B and H are not perpendicular!\n");
            return -1;
@@ -1427,11 +1524,11 @@
     }
 
     /* scale 'em into local buffer */
-    VSCALE(&vec[0*3], xip->rhc_V, local2mm);
-    VSCALE(&vec[1*3], xip->rhc_H, local2mm);
-    VSCALE(&vec[2*3], xip->rhc_B, local2mm);
-    vec[3*3] = xip->rhc_r * local2mm;
-    vec[3*3+1] = xip->rhc_c * local2mm;
+    VSCALE(&vec[0 * 3], xip->rhc_V, local2mm);
+    VSCALE(&vec[1 * 3], xip->rhc_H, local2mm);
+    VSCALE(&vec[2 * 3], xip->rhc_B, local2mm);
+    vec[3 * 3] = xip->rhc_r * local2mm;
+    vec[3 * 3 + 1] = xip->rhc_c * local2mm;
 
     /* Convert from internal (host) to database (network) format */
     htond(ep->ext_buf, (unsigned char *)vec, 11);
@@ -1457,8 +1554,9 @@
     RT_RHC_CK_MAGIC(xip);
     bu_vls_strcat(str, "Right Hyperbolic Cylinder (RHC)\n");
 
-    if (!verbose)
+    if (!verbose) {
        return 0;
+    }
 
     sprintf(buf, "\tV (%g, %g, %g)\n",
            INTCLAMP(xip->rhc_V[X] * mm2local),
@@ -1518,7 +1616,9 @@
 int
 rt_rhc_params(struct pc_pc_set *UNUSED(ps), const struct rt_db_internal *ip)
 {
-    if (ip) RT_CK_DB_INTERNAL(ip);
+    if (ip) {
+       RT_CK_DB_INTERNAL(ip);
+    }
 
     return 0;                  /* OK */
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to