Revision: 52647
          http://brlcad.svn.sourceforge.net/brlcad/?rev=52647&view=rev
Author:   n_reed
Date:     2012-10-02 01:32:20 +0000 (Tue, 02 Oct 2012)
Log Message:
-----------
Added source file for primitive utility routines. Added routine to replace 
duplicated tolerance logic.

Modified Paths:
--------------
    brlcad/trunk/src/librt/CMakeLists.txt
    brlcad/trunk/src/librt/librt_private.h
    brlcad/trunk/src/librt/primitives/bspline/bspline.cpp
    brlcad/trunk/src/librt/primitives/ehy/ehy.c
    brlcad/trunk/src/librt/primitives/ell/ell.c
    brlcad/trunk/src/librt/primitives/epa/epa.c
    brlcad/trunk/src/librt/primitives/eto/eto.c
    brlcad/trunk/src/librt/primitives/hyp/hyp.c
    brlcad/trunk/src/librt/primitives/part/part.c
    brlcad/trunk/src/librt/primitives/rhc/rhc.c
    brlcad/trunk/src/librt/primitives/rpc/rpc.c
    brlcad/trunk/src/librt/primitives/tor/tor.c

Added Paths:
-----------
    brlcad/trunk/src/librt/primitives/primitive_util.c

Modified: brlcad/trunk/src/librt/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/librt/CMakeLists.txt       2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/CMakeLists.txt       2012-10-02 01:32:20 UTC (rev 
52647)
@@ -200,6 +200,7 @@
   primitives/poly/poly.c
   primitives/poly/poly_brep.cpp
   primitives/poly/poly_mirror.c
+  primitives/primitive_util.c
   primitives/rec/rec.c
   primitives/revolve/revolve.c
   primitives/revolve/revolve_brep.cpp

Modified: brlcad/trunk/src/librt/librt_private.h
===================================================================
--- brlcad/trunk/src/librt/librt_private.h      2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/librt_private.h      2012-10-02 01:32:20 UTC (rev 
52647)
@@ -91,6 +91,8 @@
 extern void rt_plot_cell(const union cutter *cutp, struct rt_shootray_status 
*ssp, struct bu_list *waiting_segs_hd, struct rt_i *rtip);
 
 
+extern fastf_t primitive_get_absolute_tolerance(const struct rt_tess_tol 
*ttol, fastf_t rel_to_abs);
+
 __END_DECLS
 
 /*

Modified: brlcad/trunk/src/librt/primitives/bspline/bspline.cpp
===================================================================
--- brlcad/trunk/src/librt/primitives/bspline/bspline.cpp       2012-10-01 
23:06:52 UTC (rev 52646)
+++ brlcad/trunk/src/librt/primitives/bspline/bspline.cpp       2012-10-02 
01:32:20 UTC (rev 52647)
@@ -626,7 +626,7 @@
        int coords;
        fastf_t bound;
        point_t tmp_pt;
-       fastf_t rel;
+       fastf_t dtol;
        struct knot_vector tkv1,
            tkv2;
        fastf_t tess;
@@ -639,33 +639,14 @@
 
        VSUB2(tmp_pt, n->min_pt, n->max_pt);
        bound =         MAGNITUDE(tmp_pt)/ 2.0;
-       /*
-        * Establish tolerances
-        */
-       if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-           rel = 0.0;              /* none */
-       } else {
-           /* Convert rel to absolute by scaling by diameter */
-           rel = ttol->rel * 2 * bound;
-       }
-       if (ttol->abs <= 0.0) {
-           if (rel <= 0.0) {
-               /* No tolerance given, use a default */
-               rel = 2 * 0.10 * bound;        /* 10% */
-           } else {
-               /* Use absolute-ized relative tolerance */
-           }
-       } else {
-           /* Absolute tolerance was given, pick smaller */
-           if (ttol->rel <= 0.0 || rel > ttol->abs)
-               rel = ttol->abs;
-       }
 
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * bound);
+
        if (n->order[0] < 3 || n->order[1] < 3) {
            /* cannot use rt_nurb_par_edge() in this case */
            tess = 0.25; /* hack for now */
        } else
-           tess = (fastf_t) rt_nurb_par_edge(n, rel);
+           tess = (fastf_t) rt_nurb_par_edge(n, dtol);
 
        num_knots = (int)floor(1.0/((M_SQRT1_2 / 2.0) * tess));
 

Modified: brlcad/trunk/src/librt/primitives/ehy/ehy.c
===================================================================
--- brlcad/trunk/src/librt/primitives/ehy/ehy.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/ehy/ehy.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -719,6 +719,7 @@
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
     dtol = ehy_dtol(xip, ttol);
+    dtol = primitive_get_absolute_tolerance(ttol, 2.0 * xip->ehy_r2);
 
     /* stay below ntol to ensure normal tolerance */
     ntol = M_PI;
@@ -994,7 +995,7 @@
     bn_mat_mul(SoR, S, R);
     bn_mat_mul(invRoS, invR, S);
 
-    dtol = ehy_dtol(xip, ttol);
+    dtol = primitive_get_absolute_tolerance(ttol, 2.0 * xip->ehy_r2);
 
     /* stay below ntol to ensure normal tolerance */
     ntol = M_PI;

Modified: brlcad/trunk/src/librt/primitives/ell/ell.c
===================================================================
--- brlcad/trunk/src/librt/primitives/ell/ell.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/ell/ell.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -1001,7 +1001,7 @@
     int toff;          /* top offset */
     int blim;          /* base subscript limit */
     int tlim;          /* top subscript limit */
-    fastf_t rel;       /* Absolutized relative tolerance */
+    fastf_t dtol;      /* Absolutized relative tolerance */
 
     RT_CK_DB_INTERNAL(ip);
     state.eip = (struct rt_ell_internal *)ip->idb_ptr;
@@ -1079,35 +1079,16 @@
     if (Clen > radius)
        radius = Clen;
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       rel = 0.0;              /* none */
-    } else {
-       /* Convert rel to absolute by scaling by radius */
-       rel = ttol->rel * radius;
+    dtol = primitive_get_absolute_tolerance(ttol, radius);
+
+    if (dtol > radius) {
+       dtol = radius;
     }
-    if (ttol->abs <= 0.0) {
-       if (rel <= 0.0) {
-           /* No tolerance given, use a default */
-           rel = 0.10 * radius;        /* 10% */
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || rel > ttol->abs) {
-           rel = ttol->abs;
-           if (rel > radius)
-               rel = radius;
-       }
-    }
 
     /* Convert distance tolerance into a maximum permissible angle
      * tolerance.  'radius' is largest radius.
      */
-    state.theta_tol = 2 * acos(1.0 - rel / radius);
+    state.theta_tol = 2 * acos(1.0 - dtol / radius);
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0 && ttol->norm < state.theta_tol) {

Modified: brlcad/trunk/src/librt/primitives/epa/epa.c
===================================================================
--- brlcad/trunk/src/librt/primitives/epa/epa.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/epa/epa.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -714,25 +714,7 @@
     VREVERSE(&R[8], Hu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0)
-       dtol = 0.0;             /* none */
-    else
-       /* Convert rel to absolute by scaling by smallest side */
-       dtol = ttol->rel * 2 * r2;
-    if (ttol->abs <= 0.0) {
-       if (dtol <= 0.0) {
-           /* No tolerance given, use a default */
-           dtol = 2 * 0.10 * r2;       /* 10% */
-       }
-       /* Use absolute-ized relative tolerance */
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
-           dtol = ttol->abs;
-    }
+    dtol = primitive_get_absolute_tolerance(ttol, 2.0 * r2);
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)
@@ -1046,25 +1028,7 @@
     VREVERSE(&R[8], Hu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0)
-       dtol = 0.0;             /* none */
-    else
-       /* Convert rel to absolute by scaling by smallest side */
-       dtol = ttol->rel * 2 * r2;
-    if (ttol->abs <= 0.0) {
-       if (dtol <= 0.0) {
-           /* No tolerance given, use a default */
-           dtol = 2 * 0.10 * r2;       /* 10% */
-       }
-       /* Use absolute-ized relative tolerance */
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
-           dtol = ttol->abs;
-    }
+    dtol = primitive_get_absolute_tolerance(ttol, 2.0 * r2);
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)

Modified: brlcad/trunk/src/librt/primitives/eto/eto.c
===================================================================
--- brlcad/trunk/src/librt/primitives/eto/eto.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/eto/eto.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -894,34 +894,12 @@
        return 1;
     }
 
-    /* Establish tolerances */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (tip->eto_r < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * tip->eto_r);
     } else {
-       /*
-        * Convert relative to absolute by scaling smallest of radius
-        * and semi-minor axis
-        */
-       if (tip->eto_r < b)
-           dtol = ttol->rel * 2 * tip->eto_r;
-       else
-           dtol = ttol->rel * 2 * b;
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * b);
     }
-    if (ttol->abs <= 0.0) {
-       if (dtol <= 0.0) {
-           /* No tolerance given, use a default */
-           if (tip->eto_r < b)
-               dtol = 2 * 0.10 * tip->eto_r;   /* 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)
-           dtol = ttol->abs;
-    }
+
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)
        ntol = ttol->norm;
@@ -1037,34 +1015,12 @@
        goto failure;
     }
 
-    /* Establish tolerances */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (tip->eto_r < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * tip->eto_r);
     } else {
-       /*
-        * Convert relative to absolute by scaling smallest of
-        * radius and semi-minor axis
-        */
-       if (tip->eto_r < b)
-           dtol = ttol->rel * 2 * tip->eto_r;
-       else
-           dtol = ttol->rel * 2 * b;
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * b);
     }
-    if (ttol->abs <= 0.0) {
-       if (dtol <= 0.0) {
-           /* No tolerance given, use a default */
-           if (tip->eto_r < b)
-               dtol = 2 * 0.10 * tip->eto_r;   /* 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)
-           dtol = ttol->abs;
-    }
+
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)
        ntol = ttol->norm;

Modified: brlcad/trunk/src/librt/primitives/hyp/hyp.c
===================================================================
--- brlcad/trunk/src/librt/primitives/hyp/hyp.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/hyp/hyp.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -776,25 +776,7 @@
     VMOVE(Au, xip->hyp_Au);
     VCROSS(Bu, Hu, Au);
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0)
-       dtol = 0.0;             /* none */
-    else
-       /* Convert rel to absolute by scaling by smallest side */
-       dtol = ttol->rel * 2 * r2;
-    if (ttol->abs <= 0.0) {
-       if (dtol <= 0.0) {
-           /* No tolerance given, use a default */
-           dtol = 2 * 0.10 * r2;       /* 10% */
-       }
-       /* else, use absolute-ized relative tolerance */
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
-           dtol = ttol->abs;
-    }
+    dtol = primitive_get_absolute_tolerance(ttol, 2.0 * r2);
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)

Modified: brlcad/trunk/src/librt/primitives/part/part.c
===================================================================
--- brlcad/trunk/src/librt/primitives/part/part.c       2012-10-01 23:06:52 UTC 
(rev 52646)
+++ brlcad/trunk/src/librt/primitives/part/part.c       2012-10-02 01:32:20 UTC 
(rev 52647)
@@ -190,6 +190,7 @@
 #include "rtgeom.h"
 #include "raytrace.h"
 #include "nmg.h"
+#include "../../librt_private.h"
 
 
 struct part_specific {
@@ -1109,7 +1110,7 @@
     int toff;          /* top offset */
     int blim;          /* base subscript limit */
     int tlim;          /* top subscrpit limit */
-    fastf_t rel;       /* Absolutized relative tolerance */
+    fastf_t dtol;      /* Absolutized relative tolerance */
 
     RT_CK_DB_INTERNAL(ip);
     pip = (struct rt_part_internal *)ip->idb_ptr;
@@ -1162,36 +1163,17 @@
     if (pip->part_hrad > radius)
        radius = pip->part_hrad;
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       rel = 0.0;              /* none */
-    } else {
-       /* Convert rel to absolute by scaling by radius */
-       rel = ttol->rel * radius;
+    dtol = primitive_get_absolute_tolerance(ttol, radius);
+
+    if (dtol > radius) {
+       dtol = radius;
     }
-    if (ttol->abs <= 0.0) {
-       if (rel <= 0.0) {
-           /* No tolerance given, use a default */
-           rel = 0.10 * radius;        /* 10% */
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || rel > ttol->abs) {
-           rel = ttol->abs;
-           if (rel > radius)
-               rel = radius;
-       }
-    }
 
     /*
      * Converte distance tolerance into a maximum permissible
      * angle tolerance.  'radius' is largest radius.
      */
-    state.theta_tol = 2 * acos(1.0 - rel / radius);
+    state.theta_tol = 2 * acos(1.0 - dtol / radius);
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0 && ttol->norm < state.theta_tol) {

Added: brlcad/trunk/src/librt/primitives/primitive_util.c
===================================================================
--- brlcad/trunk/src/librt/primitives/primitive_util.c                          
(rev 0)
+++ brlcad/trunk/src/librt/primitives/primitive_util.c  2012-10-02 01:32:20 UTC 
(rev 52647)
@@ -0,0 +1,63 @@
+/*               P R I M I T I V E _ U T I L . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2012 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+/** @file primitive_util.c
+ *
+ * General utility routines for librt primitives that are not part of
+ * the librt API. Prototypes for these routines are located in
+ * librt_private.h.
+ */
+
+#include "../librt_private.h"
+
+/**
+ * If only the absolute tolerance is valid (positive), it is returned.
+ *
+ * If only the relative tolerance is valid (in (0.0, 1.0)), the return value
+ * is the relative tolerance multiplied by rel_to_abs.
+ *
+ * If both tolerances are valid, the smaller is used.
+ * If neither is valid, a default of .1 * rel_to_abs is used.
+ */
+#define DEFAULT_REL_TOL .1
+fastf_t
+primitive_get_absolute_tolerance(const struct rt_tess_tol *ttol, fastf_t 
rel_to_abs)
+{
+    fastf_t tol, rel_tol, abs_tol;
+    int rel_tol_is_valid;
+
+    rel_tol = ttol->rel;
+    abs_tol = ttol->abs;
+
+    rel_tol_is_valid = 0;
+    if (rel_tol > 0.0 && rel_tol < 1.0) {
+       rel_tol_is_valid = 1;
+    }
+
+    if (abs_tol > 0.0 && (!rel_tol_is_valid || rel_tol > abs_tol)) {
+       tol = abs_tol;
+    } else {
+       if (!rel_tol_is_valid) {
+           rel_tol = DEFAULT_REL_TOL;
+       }
+       tol = rel_tol * rel_to_abs;
+    }
+
+    return tol;
+}


Property changes on: brlcad/trunk/src/librt/primitives/primitive_util.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Modified: brlcad/trunk/src/librt/primitives/rhc/rhc.c
===================================================================
--- brlcad/trunk/src/librt/primitives/rhc/rhc.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/rhc/rhc.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -796,38 +796,12 @@
     VREVERSE(&R[8], Bu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (rh < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * rh);
     } else {
-       /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b) {
-           dtol = ttol->rel * 2 * rh;
-       } else {
-           dtol = ttol->rel * 2 * b;
-       }
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * 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% */
-           }
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs) {
-           dtol = ttol->abs;
-       }
-    }
-
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0) {
        ntol = ttol->norm;
@@ -1055,38 +1029,12 @@
     VREVERSE(&R[8], Bu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (rh < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * rh);
     } else {
-       /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b) {
-           dtol = ttol->rel * 2 * rh;
-       } else {
-           dtol = ttol->rel * 2 * b;
-       }
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * 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% */
-           }
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs) {
-           dtol = ttol->abs;
-       }
-    }
-
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0) {
        ntol = ttol->norm;

Modified: brlcad/trunk/src/librt/primitives/rpc/rpc.c
===================================================================
--- brlcad/trunk/src/librt/primitives/rpc/rpc.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/rpc/rpc.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -725,33 +725,11 @@
     VREVERSE(&R[8], Bu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (rh < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * rh);
     } else {
-       /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b)
-           dtol = ttol->rel * 2 * rh;
-       else
-           dtol = ttol->rel * 2 * b;
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * 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% */
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
-           dtol = ttol->abs;
-    }
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)
@@ -985,33 +963,11 @@
     VREVERSE(&R[8], Bu);
     bn_mat_trn(invR, R);                       /* inv of rot mat is trn */
 
-    /*
-     * Establish tolerances
-     */
-    if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
-       dtol = 0.0;             /* none */
+    if (rh < b) {
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * rh);
     } else {
-       /* Convert rel to absolute by scaling by smallest side */
-       if (rh < b)
-           dtol = ttol->rel * 2 * rh;
-       else
-           dtol = ttol->rel * 2 * b;
+       dtol = primitive_get_absolute_tolerance(ttol, 2.0 * 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% */
-       } else {
-           /* Use absolute-ized relative tolerance */
-       }
-    } else {
-       /* Absolute tolerance was given, pick smaller */
-       if (ttol->rel <= 0.0 || dtol > ttol->abs)
-           dtol = ttol->abs;
-    }
 
     /* To ensure normal tolerance, remain below this angle */
     if (ttol->norm > 0.0)

Modified: brlcad/trunk/src/librt/primitives/tor/tor.c
===================================================================
--- brlcad/trunk/src/librt/primitives/tor/tor.c 2012-10-01 23:06:52 UTC (rev 
52646)
+++ brlcad/trunk/src/librt/primitives/tor/tor.c 2012-10-02 01:32:20 UTC (rev 
52647)
@@ -1037,6 +1037,8 @@
     tip = (struct rt_tor_internal *)ip->idb_ptr;
     RT_TOR_CK_MAGIC(tip);
 
+    rel = primitive_get_absolute_tolerance(ttol, 2.0 * (tip->r_a + tip->r_h));
+
     if (ttol->rel <= 0.0 || ttol->rel >= 1.0) {
        rel = 0.0;              /* none */
     } else {

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


------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to