/* doprnt: 1 == print ticks, 0 == just count */ int setmark(struct xy *p, int doprt) { int xn = 0; float x,xl,xu; float q; if(p->xf==log10&&!p->xqf) { for(x=p->xquant; x<p->xub; x*=10) { xn += submark(x, p, doprt); if(p->xub/p->xlb<=100) { xn += submark(2*x, p, doprt); xn += submark(5*x, p, doprt); } } } else { q = p->xquant; if(q>0) { xl = modceil(p->xlb+q/6,q); xu = modfloor(p->xub-q/6,q)+q/2; } else { xl = modceil(p->xub-q/6,q); xu = modfloor(p->xlb+q/6,q)-q/2; } for(x=xl; x<=xu; x+=fabs(p->xquant)) { xn++; if (doprt) domark((*p->xf)(x)*p->xa + p->xb, p); } } return(xn); }
void do_autoticks(Obj *p) /* make set of ticks for default coord only */ { double x, xl, xu, q; if (p == NULL) return; fprintf(tfd, "Autoticks:\t# x %g..%g, y %g..%g", p->pt.x, p->pt1.x, p->pt.y, p->pt1.y); fprintf(tfd, "; xt %g,%g, yt %g,%g, xq,xm = %g,%g, yq,ym = %g,%g\n", xtmin, xtmax, ytmin, ytmax, xquant, xmult, yquant, ymult); if ((autoticks & (BOT|TOP)) && p->pt1.x >= p->pt.x) { /* make x ticks */ q = xquant; xl = p->pt.x; xu = p->pt1.x; if (xl >= xu) dflt_tick(xl); else if ((p->log & XFLAG) && xu/xl >= lograt) { for (x = q; x < xu; x *= 10) { logtick(x, xl, xu); if (xu/xl <= 100) { logtick(2*x, xl, xu); logtick(5*x, xl, xu); } } } else { xl = modceil(xtmin - q/100, q); xu = modfloor(xtmax + q/100, q) + q/2; for (x = xl; x <= xu; x += q) dflt_tick(x); } tside = autoticks & (BOT|TOP); ticklist(p, 0); } if ((autoticks & (LEFT|RIGHT)) && p->pt1.y >= p->pt.y) { /* make y ticks */ q = yquant; xl = p->pt.y; xu = p->pt1.y; if (xl >= xu) dflt_tick(xl); else if ((p->log & YFLAG) && xu/xl >= lograt) { for (x = q; x < xu; x *= 10) { logtick(x, xl, xu); if (xu/xl <= 100) { logtick(2*x, xl, xu); logtick(5*x, xl, xu); } } } else { xl = modceil(ytmin - q/100, q); xu = modfloor(ytmax + q/100, q) + q/2; for (x = xl; x <= xu; x += q) dflt_tick(x); } tside = autoticks & (LEFT|RIGHT); ticklist(p, 0); } }
struct z setlinlim(int lbf, int ubf, float xlb, float xub) { struct z z; float r,s,delta; float ub,lb; loop: ub = xub; lb = xlb; delta = ub - lb; /*scale up by s, a power of 10, so range (delta) exceeds 1*/ /*find power of 10 quantum, r, such that delta/10<=r<delta*/ r = s = 1; while(delta*s < 10) s *= 10; delta *= s; while(10*r < delta) r *= 10; lb *= s; ub *= s; /*set r=(1,2,5)*10**n so that 3-5 quanta cover range*/ if(r>=delta/2) r /= 2; else if(r<delta/5) r *= 2; z.ub = ubf? ub: modceil(ub,r); z.lb = lbf? lb: modfloor(lb,r); if(!lbf && z.lb<=r && z.lb>0) { xlb = 0; goto loop; } else if(!ubf && z.ub>=-r && z.ub<0) { xub = 0; goto loop; } z.quant = r; z.mult = s; return(z); }