~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/draw/plot/plot_axes.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/tv.h>
  7 #include <tina/vision.h>
  8 #include <tina/draw.h>
  9 
 10 double  fvector_min();
 11 double  fvector_max();
 12 
 13 double  pl_get_pos(double amin, double amax)
 14 {
 15     double  apos;
 16 
 17     if (amin == 0.0 || amax == 0.0)
 18         apos = 0.0;
 19     else if (amin < 0.0 && amax > 0.0)
 20         apos = 0.0;
 21     else if (amin > 0.0)
 22         apos = amin;
 23     else if (amax < 0.0)
 24         apos = amax;
 25 
 26     return (apos);
 27 }
 28 
 29 void    pl_scale(double *amin, double *amax, double *ainc, double *apos)
 30 {
 31     double  bmin, bmax, binc, binc_exp, binc_mag;
 32 
 33     bmin = *amin;
 34     bmax = *amax;
 35 
 36     if (bmin > 0.0 && bmin <= 0.25 * bmax)
 37         bmin = 0.0;
 38     else if (bmax < 0.0 && bmax >= 0.25 * bmin)
 39         bmax = 0.0;
 40 
 41     binc = (bmax - bmin) / 5.0;
 42     if (binc == 0.0)
 43         binc = 1.0;
 44     binc_exp = pow(10.0, floor(log10(binc)));
 45     binc_mag = binc / binc_exp;
 46 
 47     if (binc_mag < 2.0)
 48         binc_mag = 1.0;
 49     else if (binc_mag < 5.0)
 50         binc_mag = 2.0;
 51     else
 52         binc_mag = 5.0;
 53 
 54     binc = binc_mag * binc_exp;
 55     if ((bmax-bmin)/binc > 8.0) binc *= 2.0;
 56 
 57     bmin = binc * ceil(bmin / binc);    /* avoid too small first */
 58     if (bmin > *amin)
 59         bmin -= binc;
 60     bmax = binc * ceil(bmax / binc);
 61 
 62     *amin = bmin;
 63     *amax = bmax;
 64     *ainc = binc;
 65     *apos = pl_get_pos(bmin, bmax);
 66 }
 67 
 68 
 69 void    pl_scale_xdata(List * list, double *xmin, double *xmax, double *xinc, double *xpos)
 70 {
 71     List   *ptr;
 72 
 73     *xmin = 1e10;
 74     *xmax = -1e10;
 75     for (ptr = list; ptr != NULL; ptr = ptr->next)
 76     {
 77         switch (ptr->type)
 78         {
 79         case PL_GRAPH_TYPE:
 80             {
 81                 Pl_graph *graph = (Pl_graph *) ptr->to;
 82 
 83                 *xmin = MIN(*xmin, fvector_min(graph->x, 0, graph->n));
 84                 *xmax = MAX(*xmax, fvector_max(graph->x, 0, graph->n));
 85                 break;
 86             }
 87         case PL_SCATTER_TYPE:
 88             {
 89                 Pl_graph *graph = (Pl_graph *) ptr->to;
 90 
 91                 *xmin = MIN(*xmin, fvector_min(graph->x, 0, graph->n));
 92                 *xmax = MAX(*xmax, fvector_max(graph->x, 0, graph->n));
 93                 break;
 94             }
 95         case PL_CTR_TYPE:
 96             {
 97                 Pl_ctr *ctr = (Pl_ctr *) ptr->to;
 98 
 99                 *xmin = MIN(*xmin, fvector_min(ctr->x, 0, ctr->nx));
100                 *xmax = MAX(*xmax, fvector_max(ctr->x, 0, ctr->nx));
101                 break;
102             }
103         }
104     }
105     if(*xmax == *xmin)
106     {
107         *xmin -= 1;
108         *xmax += 1;
109     }
110         
111     pl_scale(xmin, xmax, xinc, xpos);
112 }
113 
114 void    pl_scale_ydata(List * list, double *ymin, double *ymax, double *yinc, double *ypos)
115 {
116     List   *ptr;
117 
118     *ymin = 1e10;
119     *ymax = -1e10;
120     for (ptr = list; ptr != NULL; ptr = ptr->next)
121     {
122         switch (ptr->type)
123         {
124         case PL_GRAPH_TYPE:
125             {
126                 Pl_graph *graph = (Pl_graph *) ptr->to;
127 
128                 *ymin = MIN(*ymin, fvector_min(graph->y, 0, graph->n));
129                 *ymax = MAX(*ymax, fvector_max(graph->y, 0, graph->n));
130                 break;
131             }
132         case PL_SCATTER_TYPE:
133             {
134                 Pl_graph *graph = (Pl_graph *) ptr->to;
135 
136                 *ymin = MIN(*ymin, fvector_min(graph->y, 0, graph->n));
137                 *ymax = MAX(*ymax, fvector_max(graph->y, 0, graph->n));
138                 break;
139             }
140         case PL_CTR_TYPE:
141             {
142                 Pl_ctr *ctr = (Pl_ctr *) ptr->to;
143 
144                 *ymin = MIN(*ymin, fvector_min(ctr->y, 0, ctr->ny));
145                 *ymax = MAX(*ymax, fvector_max(ctr->y, 0, ctr->ny));
146                 break;
147             }
148         }
149     }
150     if(*ymax == *ymin)
151     {
152         *ymin -= 1;
153         *ymax += 1;
154     }
155     pl_scale(ymin, ymax, yinc, ypos);
156 }
157 
158 void    pl_scale_axes(List * list, Pl_axes * axes)
159 {
160     if (axes->xscale)
161         pl_scale_xdata(list, &axes->xmin, &axes->xmax, &axes->xinc, &axes->xpos);
162     if (axes->yscale)
163         pl_scale_ydata(list, &axes->ymin, &axes->ymax, &axes->yinc, &axes->ypos);
164 }
165 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.