Revision: 52492
          http://brlcad.svn.sourceforge.net/brlcad/?rev=52492&view=rev
Author:   n_reed
Date:     2012-09-18 15:22:24 +0000 (Tue, 18 Sep 2012)
Log Message:
-----------
clean up ehy validity checks in rt_ehy_plot

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

Modified: brlcad/trunk/src/librt/primitives/ehy/ehy.c
===================================================================
--- brlcad/trunk/src/librt/primitives/ehy/ehy.c 2012-09-18 14:59:38 UTC (rev 
52491)
+++ brlcad/trunk/src/librt/primitives/ehy/ehy.c 2012-09-18 15:22:24 UTC (rev 
52492)
@@ -671,14 +671,50 @@
     return 0;
 }
 
+static int
+ehy_is_valid(struct rt_ehy_internal *ehy)
+{
+    fastf_t mag_h, cos_angle_ah;
+    vect_t a, h;
 
+    RT_EHY_CK_MAGIC(ehy);
+
+    if (!(ehy->ehy_r1 > 0.0 && ehy->ehy_r2 > 0.0 && ehy->ehy_c > 0.0)) {
+       return 0;
+    }
+
+    VMOVE(h, ehy->ehy_H);
+    VMOVE(a, ehy->ehy_Au);
+
+    /* Check that A is a unit vector. If it is, then it should be true that
+     * |A| == |A|^2 == 1.0.
+     */
+    if (!NEAR_EQUAL(MAGSQ(a), 1.0, RT_LEN_TOL)) {
+       return 0;
+    }
+
+    /* check that |H| > 0.0 */
+    mag_h = MAGNITUDE(h);
+    if (NEAR_ZERO(mag_h, RT_LEN_TOL)) {
+       return 0;
+    }
+
+    /* check that A and H are orthogonal */
+    cos_angle_ah = VDOT(a, h) / mag_h;
+    if (!NEAR_ZERO(cos_angle_ah, RT_DOT_TOL)) {
+       return 0;
+    }
+
+    return 1;
+}
+
 /**
  * R T _ E H Y _ P L O T
  */
 int
 rt_ehy_plot(struct bu_list *vhead, struct rt_db_internal *ip, const struct 
rt_tess_tol *ttol, const struct bn_tol *UNUSED(tol), const struct rt_view_info 
*UNUSED(info))
 {
-    fastf_t c, dtol, f, mag_a, mag_h, ntol, r1, r2;
+    fastf_t c, dtol, mag_h, ntol, r1, r2;
     fastf_t **ellipses, theta_prev, theta_new;
     int *pts_dbl, i, j, nseg;
     int jj, na, nb, nell, recalc_b;
@@ -692,31 +728,16 @@
     BU_CK_LIST_HEAD(vhead);
     RT_CK_DB_INTERNAL(ip);
     xip = (struct rt_ehy_internal *)ip->idb_ptr;
-    RT_EHY_CK_MAGIC(xip);
 
-    /*
-     * make sure ehy description is valid
-     */
+    if (!ehy_is_valid(xip)) {
+       return -2;
+    }
 
-    /* compute |A| |H| */
-    mag_a = MAGSQ(xip->ehy_Au);        /* should already be unit vector */
     mag_h = MAGNITUDE(xip->ehy_H);
-    c = xip->ehy_c;
     r1 = xip->ehy_r1;
     r2 = xip->ehy_r2;
-    /* Check for |H| > 0, |A| == 1, r1 > 0, r2 > 0, c > 0 */
-    if (NEAR_ZERO(mag_h, RT_LEN_TOL)
-       || !NEAR_EQUAL(mag_a, 1.0, RT_LEN_TOL)
-       || r1 <= 0.0 || r2 <= 0.0 || c <= 0.) {
-       return -2;              /* BAD */
-    }
+    c = xip->ehy_c;
 
-    /* Check for A.H == 0 */
-    f = VDOT(xip->ehy_Au, xip->ehy_H) / mag_h;
-    if (! NEAR_ZERO(f, RT_DOT_TOL)) {
-       return -2;              /* BAD */
-    }
-
     /* make unit vectors in A, H, and BxH directions */
     VMOVE(Hu, xip->ehy_H);
     VUNITIZE(Hu);

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