bridge/class-master/depend/pari/src/graph/plotport.c
/* Given coordinates of ends of a line, and labels l1 l2 attached to the
 * ends, plot ticks where the label coordinate takes "round" values */
Given coordinates of ends of a line, and labels l1 l2 attached to the
ends, plot ticks where the label coordinate takes "round" values
Given coordinates of ends of a line and labels l1 l2 attached to the ends plot ticks where the label coordinate takes " round " values
static void
rectticks(PARI_plot *WW, long ne, double dx1, double dy1, double dx2,
          double dy2, double l1, double l2, long flags)
{
  long dx, dy, dxy, dxy1, x1, y1, x2, y2, nticks, n, n1, dn;
  double minstep, maxstep, step, l_min, l_max, minl, maxl, dl, dtx, dty, x, y;
  double ddx, ddy;
  const double mult[3] = { 2./1., 5./2., 10./5. };
  PariRect *e = check_rect_init(ne);
  int do_double = !(flags & TICKS_NODOUBLE);
  x1 = DTOL(dx1*RXscale(e) + RXshift(e));
  y1 = DTOL(dy1*RYscale(e) + RYshift(e));
  x2 = DTOL(dx2*RXscale(e) + RXshift(e));
  y2 = DTOL(dy2*RYscale(e) + RYshift(e));
  dx = x2 - x1; if (dx < 0) dx = -dx;
  dy = y2 - y1; if (dy < 0) dy = -dy;
  dxy1 = maxss(dx, dy);
  dx /= WW->hunit;
  dy /= WW->vunit;
  if (dx > 1000 || dy > 1000)
    dxy = 1000; 
  else
    dxy = usqrt(dx*dx + dy*dy);
  nticks = (long) ((dxy + 2.5)/4);
  if (!nticks) return;
  if (l1 < l2)
    l_min = l1, l_max = l2;
  else
    l_min = l2, l_max = l1;
  minstep = (l_max - l_min)/(nticks + 1);
  maxstep = 2.5*(l_max - l_min);
  step = exp(log(10.) * floor(log10(minstep)));
  if (!(flags & TICKS_ENDSTOO)) {
    double d = 2*(l_max - l_min)/dxy1; 
    l_min += d;
    l_max -= d;
  }
  for (n = 0; ; n++)
  {
    if (step >= maxstep) return;
    if (step >= minstep) {
      minl = ceil(l_min/step);
      maxl = floor(l_max/step);
      if (minl <= maxl && maxl - minl + 1 <= nticks) {
        nticks = (long) (maxl - minl + 1);
        l_min = minl * step;
        l_max = maxl * step; break;
      }
    }
    step *= mult[ n % 3 ];
  }
  dn = (n % 3 == 2)? 2: 5;
  n1 = ((long)minl) % dn; 
  if (nticks == 1) ddx = ddy = 0; 
  else {
    dl = (l_max - l_min)/(nticks - 1);
    ddx = (dx2 - dx1) * dl / (l2 - l1);
    ddy = (dy2 - dy1) * dl / (l2 - l1);
  }
  x = dx1 + (dx2 - dx1) * (l_min - l1) / (l2 - l1);
  y = dy1 + (dy2 - dy1) * (l_min - l1) / (l2 - l1);
  dtx = WW->hunit * dy/dxy * (y2 > y1 ? 1 : -1); 
  dty = WW->vunit * dx/dxy * (x2 > x1 ? 1 : -1);
  for (n = 0; n < nticks; n++, x += ddx, y += ddy) {
    RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj2P));
    double lunit = WW->hunit > 1 ? 1.5 : 2;
    double l = (do_double && (n + n1) % dn == 0) ? lunit: 1;
    double x1, x2, y1, y2;
    x1 = x2 = x*RXscale(e) + RXshift(e);
    y1 = y2 = y*RYscale(e) + RYshift(e);
    if (flags & TICKS_CLOCKW)  { x1 += dtx*l; y1 -= dty*l; }
    if (flags & TICKS_ACLOCKW) { x2 -= dtx*l; y2 += dty*l; }
    RoLNx1(z) = x1; RoLNy1(z) = y1;
    RoLNx2(z) = x2; RoLNy2(z) = y2;
    RoType(z) = ROt_LN;
    Rchain(e, z);
    RoCol(z) = current_color[ne];
  }
}
static void rectticks ( PARI_plot * WW , long ne , double dx1 , double dy1 , double dx2 , double dy2 , double l1 , double l2 , long flags ) { long dx , dy , dxy , dxy1 , x1 , y1 , x2 , y2 , nticks , n , n1 , dn ; double minstep , maxstep , step , l_min , l_max , minl , maxl , dl , dtx , dty , x , y ; double ddx , ddy ; const double mult [ 3 ] = { 2. / 1. , 5. / 2. , 10. / 5. } ; PariRect * e = check_rect_init ( ne ) ; int do_double = ! ( flags & TICKS_NODOUBLE ) ; x1 = DTOL ( dx1 * RXscale ( e ) + RXshift ( e ) ) ; y1 = DTOL ( dy1 * RYscale ( e ) + RYshift ( e ) ) ; x2 = DTOL ( dx2 * RXscale ( e ) + RXshift ( e ) ) ; y2 = DTOL ( dy2 * RYscale ( e ) + RYshift ( e ) ) ; dx = x2 - x1 ; if ( dx < 0 ) dx = - dx ; dy = y2 - y1 ; if ( dy < 0 ) dy = - dy ; dxy1 = maxss ( dx , dy ) ; dx /= WW -> hunit ; dy /= WW -> vunit ; if ( dx > 1000 || dy > 1000 ) dxy = 1000 ; else dxy = usqrt ( dx * dx + dy * dy ) ; nticks = ( long ) ( ( dxy + 2.5 ) / 4 ) ; if ( ! nticks ) return ; if ( l1 < l2 ) l_min = l1 , l_max = l2 ; else l_min = l2 , l_max = l1 ; minstep = ( l_max - l_min ) / ( nticks + 1 ) ; maxstep = 2.5 * ( l_max - l_min ) ; step = exp ( log ( 10. ) * floor ( log10 ( minstep ) ) ) ; if ( ! ( flags & TICKS_ENDSTOO ) ) { double d = 2 * ( l_max - l_min ) / dxy1 ; l_min += d ; l_max -= d ; } for ( n = 0 ; ; n ++ ) { if ( step >= maxstep ) return ; if ( step >= minstep ) { minl = ceil ( l_min / step ) ; maxl = floor ( l_max / step ) ; if ( minl <= maxl && maxl - minl + 1 <= nticks ) { nticks = ( long ) ( maxl - minl + 1 ) ; l_min = minl * step ; l_max = maxl * step ; break ; } } step *= mult [ n % 3 ] ; } dn = ( n % 3 == 2 ) ? 2 : 5 ; n1 = ( ( long ) minl ) % dn ; if ( nticks == 1 ) ddx = ddy = 0 ; else { dl = ( l_max - l_min ) / ( nticks - 1 ) ; ddx = ( dx2 - dx1 ) * dl / ( l2 - l1 ) ; ddy = ( dy2 - dy1 ) * dl / ( l2 - l1 ) ; } x = dx1 + ( dx2 - dx1 ) * ( l_min - l1 ) / ( l2 - l1 ) ; y = dy1 + ( dy2 - dy1 ) * ( l_min - l1 ) / ( l2 - l1 ) ; dtx = WW -> hunit * dy / dxy * ( y2 > y1 ? 1 : -1 ) ; dty = WW -> vunit * dx / dxy * ( x2 > x1 ? 1 : -1 ) ; for ( n = 0 ; n < nticks ; n ++ , x += ddx , y += ddy ) { RectObj * z = ( RectObj * ) pari_malloc ( sizeof ( RectObj2P ) ) ; double lunit = WW -> hunit > 1 ? 1.5 : 2 ; double l = ( do_double && ( n + n1 ) % dn == 0 ) ? lunit : 1 ; double x1 , x2 , y1 , y2 ; x1 = x2 = x * RXscale ( e ) + RXshift ( e ) ; y1 = y2 = y * RYscale ( e ) + RYshift ( e ) ; if ( flags & TICKS_CLOCKW ) { x1 += dtx * l ; y1 -= dty * l ; } if ( flags & TICKS_ACLOCKW ) { x2 -= dtx * l ; y2 += dty * l ; } RoLNx1 ( z ) = x1 ; RoLNy1 ( z ) = y1 ; RoLNx2 ( z ) = x2 ; RoLNy2 ( z ) = y2 ; RoType ( z ) = ROt_LN ; Rchain ( e , z ) ; RoCol ( z ) = current_color [ ne ] ; } }
Given coordinates of ends of a line, and labels l1 l2 attached to the
 ends, plot ticks where the label coordinate takes "round" values
Given coordinates of ends of a line and labels l1 l2 attached to the ends plot ticks where the label coordinate takes " round " values
/* avoid overflow */ /* Find nticks (or less) "round" numbers between l1 and l2. For our purpose
   * round numbers have "last significant" decimal digit either
   *    - any;
   *    - even;
   *    - divisible by 5.
   * We need to choose which alternative is better. */ /* Two pixels off */ /* Where to position doubleticks. Variants:
   * small: each 5, double: each 10  ; n=2 mod 3
   * small: each 2, double: each 10  ; n=1 mod 3
   * small: each 1, double: each  5 */ /* unused if do_double = FALSE */ /* now l_min and l_max keep min/max values of l with ticks, and nticks is
     the number of ticks to draw. */ /* -Wall */ /* assume hunit and vunit form a square. For clockwise ticks: */ /* y-coord runs down */