Revision: 56181
          http://sourceforge.net/p/brlcad/code/56181
Author:   brlcad
Date:     2013-07-22 23:08:55 +0000 (Mon, 22 Jul 2013)
Log Message:
-----------
resort in usage order. eliminate dead code and need for forward declarations.

Modified Paths:
--------------
    brlcad/trunk/src/sig/fhor.c

Modified: brlcad/trunk/src/sig/fhor.c
===================================================================
--- brlcad/trunk/src/sig/fhor.c 2013-07-22 21:48:49 UTC (rev 56180)
+++ brlcad/trunk/src/sig/fhor.c 2013-07-22 23:08:55 UTC (rev 56181)
@@ -50,16 +50,21 @@
 /* Max and Min horizon holders */
 static int upper[HSCREEN], lower[HSCREEN];
 
-FBIO *fbp;     /* XXX - debug */
+FBIO *fbp = NULL;      /* XXX - debug */
 
-void Efill(void);
-void Horizon(int sx1, int sy1, int sx2, int sy2);
-void Intersect(int sx1, int sy1, int x2, int y2, int *hor, int *xi, int *yi);
-void Draw(int sx1, int sy1, int x2, int y2);
-int fhvis(int x, int y);
-int sign(int i);
 
-void
+static int
+sign(int i)
+{
+    if (i > 0)
+       return 1;
+    if (i < 0)
+       return -1;
+    return 0;
+}
+
+
+static void
 fhinit(void)
 {
     int i;
@@ -73,104 +78,6 @@
 
 
 /*
- * Add another Z cut to the display.
- * This one goes "behind" the last one.
- */
-void
-fhnewz(int *f, int num)
-{
-    int x, y, Xprev, Yprev, Xi, Yi;
-    int Previously, Currently;
-
-    /* Init previous X and Y values */
-    Xprev = Yi = Xi = y = x = 0;
-    Yprev = f[ 0 ];
-    /* VIEWING XFORM */
-
-    /* Fill left side */
-    Efill();
-    Previously = fhvis(Xprev, Yprev);          /* <<< WHAT ARE X AND Y? */
-
-    /* Do each point in Z plane */
-    for (x = 0; x < num; x++) {
-       y = f[x];
-       /* VIEWING XFORM */
-
-       /* Check visibility and fill horizon */
-       Currently = fhvis(x, y);
-       if (Currently == Previously) {
-           if (Currently != INVISIBLE) {
-               /*
-                * Current and Previous point both
-                * visible on same side of horizon.
-                */
-               Draw(Xprev, Yprev, x, y);
-               Horizon(Xprev, Yprev, x, y);
-           }
-           /* else both invisible */
-       } else {
-           /*
-            * Visibility has changed.
-            * Calculate intersection and fill horizon.
-            */
-           switch (Currently) {
-               case INVISIBLE:
-                   if (Previously == ABOVE)
-                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
-                   else /* previously BELOW */
-                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
-                   Draw(Xprev, Yprev, Xi, Yi);
-                   Horizon(Xprev, Yprev, Xi, Yi);
-                   break;
-
-               case ABOVE:
-                   if (Previously == INVISIBLE) {
-                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
-                       Draw(Xi, Yi, x, y);
-                       Horizon(Xi, Yi, x, y);
-                   } else {
-                       /* previously BELOW */
-                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
-                       Draw(Xprev, Yprev, Xi, Yi);
-                       Horizon(Xprev, Yprev, Xi, Yi);
-                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
-                       Draw(Xi, Yi, x, y);
-                       Horizon(Xi, Yi, x, y);
-                   }
-                   break;
-
-               case BELOW:
-                   if (Previously == INVISIBLE) {
-                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
-                       Draw(Xi, Yi, x, y);
-                       Horizon(Xi, Yi, x, y);
-                   } else {
-                       /* previously ABOVE */
-                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
-                       Draw(Xprev, Yprev, Xi, Yi);
-                       Horizon(Xprev, Yprev, Xi, Yi);
-                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
-                       Draw(Xi, Yi, x, y);
-                       Horizon(Xi, Yi, x, y);
-                   }
-                   break;
-           }
-       } /* end changed visibility */
-
-       /*
-        * Reset "previous" point values for next iteration.
-        */
-       Previously = Currently;
-       Xprev = x;
-       Yprev = y;
-    }
-
-    /* Fill Right Side */
-    Efill();
-}
-
-
-/*
  * INTERNAL Visibility routine.
  * Answers, Is Y visible at point X?
  *
@@ -178,7 +85,7 @@
  * 1 if visible above upper horizon.
  * -1 if visible below lower horizon.
  */
-int
+static int
 fhvis(int x, int y)
 {
     /* See if hidden behind horizons */
@@ -196,7 +103,7 @@
  * INTERNAL Edge fill routine.
  * NOT DONE YET.
  */
-void
+static void
 Efill(void)
 {
 }
@@ -206,7 +113,7 @@
  * Fill the upper and lower horizon arrays from x_1 to x_2
  * with a line spanning (x_1, y_1) to (x_2, y_2).
  */
-void
+static void
 Horizon(int x_1, int y_1, int x_2, int y_2)
 {
     int xinc, x, y;
@@ -229,86 +136,16 @@
 
 
 /*
- * Find the intersection (xi, yi) between the line (x_1, y_1)->(x_2, y_2)
- * and the horizon hor[].
- */
-void
-Intersect(int x_1, int y_1, int x_2, int y_2, int *hor, int *xi, int *yi)
-{
-    int xinc, ysign;
-    int slope;
-
-/*
-  printf("Intersect((%3d, %3d)->(%3d, %3d) & (%3d, %3d)->(%3d, %3d)) = ", x_1, 
y_1, x_2, y_2, x_1, hor[x_1], x_2, hor[x_2]);
-  fflush(stdout);
-*/
-    xinc = sign(x_2 - x_1);
-    if (xinc == 0) {
-       /* Vertical line */
-       *xi = x_2;
-       *yi = hor[x_2];
-/*printf("(vert x_2=%d) ", x_2);*/
-    } else {
-#ifdef FOOBARBAZ
-       denom = (hor[x_2]-hor[x_1])-(y_2-y_1);
-       if (denom == 0) {
-           /* same line! */
-           *xi = x_1;
-       } else
-           *xi = x_1 + ((x_2-x_1)*(hor[x_1]-y_1))/denom;
-       *yi = y_1 + (*xi-x_1)*((y_2-y_1)/(x_2-x_1)) + 0.5;
-/*printf("(%3d, %3d)\n", *xi, *yi);*/
-       return;
-#endif /* FOOBARBAZ */
-
-       slope = (y_2 - y_1) / (x_2 - x_1);
-       ysign = sign(y_1 - hor[x_1 + xinc]);
-#ifdef MYMETHOD
-       for (*xi = x_1; *xi <= x_2; *xi += xinc) {
-           *yi = y_1 + (*xi-x_1)*slope;        /* XXX */
-           if (sign(*yi - hor[*xi + xinc]) != ysign)
-               break;
-       }
-       if (xinc == 1 && *xi > x_2) *xi = x_2;
-       if (xinc == -1 && *xi < x_2) *xi = x_2;
-#else
-       *yi = y_1;
-       *xi = x_1;
-       while (sign(*yi - hor[*xi + xinc]) == ysign) {
-           for (*xi = x_1; *xi <= x_2; *xi += xinc)
-               *yi = *yi + slope;      /* XXX */
-/*printf("[%3d, %3d]", *xi, *yi);*/
-       }
-       *xi = *xi + xinc;
-#endif /* MYMETHOD */
-    }
-/*printf("(%3d, %3d)\n", *xi, *yi);*/
-}
-
-
-int
-sign(int i)
-{
-    if (i > 0)
-       return 1;
-    if (i < 0)
-       return -1;
-    return 0;
-}
-
-
-/*
  * DRAW - plot a line from (x_1, y_1) to (x_2, y_2)
  * An integer Bresenham algorithm for any quadrant.
  */
-void
+static void
 Draw(int x_1, int y_1, int x_2, int y_2)
 {
     int x, y, deltx, delty, error, i;
     int temp, s1, s2, interchange;
     static RGBpixel white = { 255, 255, 255 }; /* XXX - debug */
 
-/*printf("Draw (%d %d) -> (%d %d)\n", x_1, y_1, x_2, y_2);*/
     x = x_1;
     y = y_1;
     deltx = (x_2 > x_1 ? x_2 - x_1 : x_1 - x_2);
@@ -329,8 +166,6 @@
     error = 2 * delty - deltx;
 
     for (i = 0; i < deltx; i++) {
-/* plotxy(x, y);*/
-/* printf("(%3d, %3d)\n", x, y);*/
        fb_write(fbp, x, y, white, 1);
        while (error >= 0) {
            if (interchange == 1)
@@ -348,40 +183,148 @@
 }
 
 
-#ifdef SOMBRERO
-int main()
+/*
+ * Find the intersection (xi, yi) between the line (x_1, y_1)->(x_2, y_2)
+ * and the horizon hor[].
+ */
+void
+Intersect(int x_1, int y_1, int x_2, int y_2, int *hor, int *xi, int *yi)
 {
-    int f[500];
-    int x, y, z;
-    double r;
+    int xinc, ysign;
+    int slope;
 
-    fhinit();
+    xinc = sign(x_2 - x_1);
+    if (xinc == 0) {
+       /* Vertical line */
+       *xi = x_2;
+       *yi = hor[x_2];
+    } else {
+       slope = (y_2 - y_1) / (x_2 - x_1);
+       ysign = sign(y_1 - hor[x_1 + xinc]);
+#ifdef MYMETHOD
+       for (*xi = x_1; *xi <= x_2; *xi += xinc) {
+           *yi = y_1 + (*xi-x_1)*slope;        /* XXX */
+           if (sign(*yi - hor[*xi + xinc]) != ysign)
+               break;
+       }
+       if (xinc == 1 && *xi > x_2) *xi = x_2;
+       if (xinc == -1 && *xi < x_2) *xi = x_2;
+#else
+       *yi = y_1;
+       *xi = x_1;
+       while (sign(*yi - hor[*xi + xinc]) == ysign) {
+           for (*xi = x_1; *xi <= x_2; *xi += xinc)
+               *yi = *yi + slope;      /* XXX */
+       }
+       *xi = *xi + xinc;
+#endif /* MYMETHOD */
+    }
+}
 
-    fbp = fb_open(NULL, 512, 512);
-    fb_clear(fbp, PIXEL_NULL);
 
-    /* Nearest to Farthest */
-    for (z = 500; z > 0; z--) {
-       /* Left to Right */
-       for (x = 0; x < 500; x++) {
-           r = (x - 250) * (x - 250) + (z - 250) * (z - 250);
-           r = 0.10*sqrt(r) + 0.00001;
-           y = 250.0 * sin(r) / r + 100.0 + (500-z)/3;
-           f[x] = y;
-/* printf("f[%3d] = %d\n", x, y);*/
-       }
-       fhnewz(f, 500);
+/*
+ * Add another Z cut to the display.
+ * This one goes "behind" the last one.
+ */
+static void
+fhnewz(int *f, int num)
+{
+    int x, y, Xprev, Yprev, Xi, Yi;
+    int Previously, Currently;
+
+    /* Init previous X and Y values */
+    Xprev = Yi = Xi = y = x = 0;
+    Yprev = f[ 0 ];
+    /* VIEWING XFORM */
+
+    /* Fill left side */
+    Efill();
+    Previously = fhvis(Xprev, Yprev);          /* <<< WHAT ARE X AND Y? */
+
+    /* Do each point in Z plane */
+    for (x = 0; x < num; x++) {
+       y = f[x];
+       /* VIEWING XFORM */
+
+       /* Check visibility and fill horizon */
+       Currently = fhvis(x, y);
+       if (Currently == Previously) {
+           if (Currently != INVISIBLE) {
+               /*
+                * Current and Previous point both
+                * visible on same side of horizon.
+                */
+               Draw(Xprev, Yprev, x, y);
+               Horizon(Xprev, Yprev, x, y);
+           }
+           /* else both invisible */
+       } else {
+           /*
+            * Visibility has changed.
+            * Calculate intersection and fill horizon.
+            */
+           switch (Currently) {
+               case INVISIBLE:
+                   if (Previously == ABOVE)
+                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
+                   else /* previously BELOW */
+                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
+                   Draw(Xprev, Yprev, Xi, Yi);
+                   Horizon(Xprev, Yprev, Xi, Yi);
+                   break;
+
+               case ABOVE:
+                   if (Previously == INVISIBLE) {
+                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
+                       Draw(Xi, Yi, x, y);
+                       Horizon(Xi, Yi, x, y);
+                   } else {
+                       /* previously BELOW */
+                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
+                       Draw(Xprev, Yprev, Xi, Yi);
+                       Horizon(Xprev, Yprev, Xi, Yi);
+                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
+                       Draw(Xi, Yi, x, y);
+                       Horizon(Xi, Yi, x, y);
+                   }
+                   break;
+
+               case BELOW:
+                   if (Previously == INVISIBLE) {
+                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
+                       Draw(Xi, Yi, x, y);
+                       Horizon(Xi, Yi, x, y);
+                   } else {
+                       /* previously ABOVE */
+                       Intersect(Xprev, Yprev, x, y, upper, &Xi, &Yi);
+                       Draw(Xprev, Yprev, Xi, Yi);
+                       Horizon(Xprev, Yprev, Xi, Yi);
+                       Intersect(Xprev, Yprev, x, y, lower, &Xi, &Yi);
+                       Draw(Xi, Yi, x, y);
+                       Horizon(Xi, Yi, x, y);
+                   }
+                   break;
+           }
+       } /* end changed visibility */
+
+       /*
+        * Reset "previous" point values for next iteration.
+        */
+       Previously = Currently;
+       Xprev = x;
+       Yprev = y;
     }
 
-    return 0;
+    /* Fill Right Side */
+    Efill();
 }
-#endif
 
-static const char usage[] = "\
-Usage: fhor [width] < doubles\n";
 
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
 {
+    static const char usage[] = "Usage: fhor [width] < doubles\n";
+
     double inbuf[512];
     int f[512];
     int i, x, z;
@@ -414,7 +357,6 @@
     z = 0;
     while (fread(inbuf, sizeof(*inbuf), size, stdin) != 0) {
        /* Left to Right */
-       /*memset((char *)f, 0, 512*sizeof(*f));*/
        for (i = 0; i < 512; i++) {
            f[i] = 4*z; /* up 4 for every z back */
        }
@@ -423,7 +365,6 @@
            if (x >= 0 && x < 512) {
                f[x] += 128 * inbuf[i];
            }
-           /*printf("f[%3d] = %d\n", x, y);*/
        }
        fhnewz(f, 512);
        z++;

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


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to