Revision: 54419
http://brlcad.svn.sourceforge.net/brlcad/?rev=54419&view=rev
Author: brlcad
Date: 2013-02-15 14:09:50 +0000 (Fri, 15 Feb 2013)
Log Message:
-----------
document the curious scale behavior where positive multiplies and negative sets
a value, refactor all of the uses into one place for some nice reduction too.
Modified Paths:
--------------
brlcad/trunk/src/libged/edpipe.c
Modified: brlcad/trunk/src/libged/edpipe.c
===================================================================
--- brlcad/trunk/src/libged/edpipe.c 2013-02-14 22:05:50 UTC (rev 54418)
+++ brlcad/trunk/src/libged/edpipe.c 2013-02-15 14:09:50 UTC (rev 54419)
@@ -90,6 +90,18 @@
}
+static fastf_t
+edpipe_scale(fastf_t d, fastf_t scale)
+{
+ if (scale < 0.0) {
+ /* negative value sets the scale */
+ return (-scale);
+ }
+
+ /* positive value gets multiplied */
+ return (d * scale);
+}
+
void
pipe_scale_od(struct rt_pipe_internal *pipeip, fastf_t scale)
{
@@ -101,10 +113,8 @@
for (BU_LIST_FOR(ps, wdb_pipept, &pipeip->pipe_segs_head)) {
fastf_t tmp_od;
- if (scale < 0.0)
- tmp_od = (-scale);
- else
- tmp_od = ps->pp_od*scale;
+ tmp_od = edpipe_scale(ps->pp_od, scale);
+
if (ps->pp_id > tmp_od) {
/* Silently ignore */
return;
@@ -115,11 +125,9 @@
}
}
- for (BU_LIST_FOR(ps, wdb_pipept, &pipeip->pipe_segs_head))
- if (scale > 0.0)
- ps->pp_od *= scale;
- else
- ps->pp_od = -scale;
+ for (BU_LIST_FOR(ps, wdb_pipept, &pipeip->pipe_segs_head)) {
+ ps->pp_od = edpipe_scale(ps->pp_od, scale);
+ }
}
@@ -134,10 +142,8 @@
for (BU_LIST_FOR(ps, wdb_pipept, &pipeip->pipe_segs_head)) {
fastf_t tmp_id;
- if (scale > 0.0)
- tmp_id = ps->pp_id*scale;
- else
- tmp_id = (-scale);
+ tmp_id = edpipe_scale(ps->pp_id, scale);
+
if (ps->pp_od < tmp_id) {
/* Silently ignore */
return;
@@ -149,10 +155,7 @@
}
for (BU_LIST_FOR(ps, wdb_pipept, &pipeip->pipe_segs_head)) {
- if (scale > 0.0)
- ps->pp_id *= scale;
- else
- ps->pp_id = (-scale);
+ ps->pp_id = edpipe_scale(ps->pp_id, scale);
}
}
@@ -164,13 +167,11 @@
BU_CKMAG(ps, WDB_PIPESEG_MAGIC, "pipe segment");
+ tmp_od = edpipe_scale(ps->pp_od, scale);
+
/* need to check that the new OD is not less than ID
* of any affected segment.
*/
- if (scale < 0.0)
- tmp_od = (-scale);
- else
- tmp_od = scale*ps->pp_od;
if (ps->pp_id > tmp_od) {
#if 0
Tcl_AppendResult(INTERP, "Cannot make OD smaller than ID\n", (char
*)NULL);
@@ -184,10 +185,7 @@
return;
}
- if (scale > 0.0)
- ps->pp_od *= scale;
- else
- ps->pp_od = (-scale);
+ ps->pp_od = edpipe_scale(ps->pp_od, scale);
}
@@ -198,11 +196,9 @@
BU_CKMAG(ps, WDB_PIPESEG_MAGIC, "pipe segment");
+ tmp_id = edpipe_scale(ps->pp_id, scale);
+
/* need to check that the new ID is not greater than OD */
- if (scale > 0.0)
- tmp_id = scale*ps->pp_id;
- else
- tmp_id = (-scale);
if (ps->pp_od < tmp_id) {
#if 0
Tcl_AppendResult(INTERP, "Cannot make ID greater than OD\n", (char
*)NULL);
@@ -216,10 +212,7 @@
return;
}
- if (scale > 0.0)
- ps->pp_id *= scale;
- else
- ps->pp_id = (-scale);
+ ps->pp_id = edpipe_scale(ps->pp_id, scale);
}
@@ -237,11 +230,9 @@
/* make sure we can make this change */
old_radius = ps->pp_bendradius;
- if (scale > 0.0)
- ps->pp_bendradius *= scale;
- else
- ps->pp_bendradius = (-scale);
+ ps->pp_bendradius = edpipe_scale(ps->pp_bendradius, scale);
+
if (ps->pp_bendradius < ps->pp_od * 0.5) {
#if 0
Tcl_AppendResult(INTERP, "Cannot make bend radius less than pipe outer
radius\n", (char *)NULL);
@@ -295,10 +286,7 @@
/* make the desired editing changes to the copy */
for (BU_LIST_FOR(new_ps, wdb_pipept, &head)) {
- if (scale < 0.0)
- new_ps->pp_bendradius = (-scale);
- else
- new_ps->pp_bendradius *= scale;
+ new_ps->pp_bendradius = edpipe_scale(new_ps->pp_bendradius, scale);
}
/* check if the copy is O.K. */
@@ -321,10 +309,7 @@
/* make changes to the original */
for (BU_LIST_FOR(old_ps, wdb_pipept, &pipeip->pipe_segs_head)) {
- if (scale < 0.0)
- old_ps->pp_bendradius = (-scale);
- else
- old_ps->pp_bendradius *= scale;
+ old_ps->pp_bendradius = edpipe_scale(old_ps->pp_bendradius, scale);
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits