bridge/class-master/depend/pari/src/graph/plotport.c
/* Convert data from GEN to double before we call plotrecthrawin. */
Convert data from GEN to double before we call plotrecthrawin.
Convert data from GEN to double before we call plotrecthrawin .
static dblPointList*
gtodblList(GEN data, long flags)
{
  dblPointList *l, *L;
  double *X, *Y;
  long nl=lg(data)-1, lx1, i, j;
  const long param = (flags & (PLOT_PARAMETRIC|PLOT_COMPLEX));
  const long cplx = (flags & PLOT_COMPLEX);
  if (! is_vec_t(typ(data))) pari_err_TYPE("gtodblList",data);
  if (!nl) return NULL;
  lx1 = lg(gel(data,1));
  if (!param && lx1 == 1) return NULL;
  if (nl == 1 && !cplx) pari_err_DIM("gtodblList");
  l = (dblPointList*)pari_malloc((cplx? 2*nl: nl)*sizeof(dblPointList));
  L = &l[0];
  for (i = 0; i < nl; i += cplx? 1: 2)
  {
    GEN x = gel(data,i+1), y;
    long lx = lg(x);
    if (!is_vec_t(typ(x))) pari_err_TYPE("gtodblList",x);
    if (cplx) y = NULL;
    else
    {
      y = gel(data,i+2);
      if (!is_vec_t(typ(y))) pari_err_TYPE("gtodblList",y);
      if (lg(y) != lx || (!param && lx != lx1)) pari_err_DIM("gtodblList");
    }
    lx--;
    l[i].d   = X = (double*)pari_malloc(lx*sizeof(double));
    l[i+1].d = Y = (double*)pari_malloc(lx*sizeof(double));
    for (j=1; j<=lx; j++) get_xy_from_vec2(cplx, x, y, j, X+(j-1), Y+(j-1));
    l[i].nb = l[i+1].nb = lx;
  }
  if (param)
  {
    L->nb = cplx? nl: nl/2;
    for (i=0; i < L->nb; i+=2)
      if (l[i+1].nb) break;
    if (i >= L->nb) { pari_free(l); return NULL; }
    L->xsml = L->xbig = l[i  ].d[0];
    L->ysml = L->ybig = l[i+1].d[0];
    for (; i < L->nb; i+=2)
    {
      long nbi = l[i+1].nb; X = l[i].d; Y = l[i+1].d;
      for (j = 0; j < nbi; j++) { set_xrange(L, X[j]); set_yrange(L, Y[j]); }
    }
  }
  else
  {
    L->nb = nl-1;
    X = L->d;   L->xsml = L->xbig = X[0];
    Y = l[1].d; L->ysml = L->ybig = Y[0];
    for (j=0; j < l[1].nb; j++) set_xrange(L, X[j]);
    for (i=1; i <= L->nb; i++)
    {
      long nbi = l[i].nb; Y = l[i].d;
      for (j = 0; j < nbi; j++) set_yrange(L, Y[j]);
    }
  }
  return l;
}
static dblPointList * gtodblList ( GEN data , long flags ) { dblPointList * l , * L ; double * X , * Y ; long nl = lg ( data ) - 1 , lx1 , i , j ; const long param = ( flags & ( PLOT_PARAMETRIC | PLOT_COMPLEX ) ) ; const long cplx = ( flags & PLOT_COMPLEX ) ; if ( ! is_vec_t ( typ ( data ) ) ) pari_err_TYPE ( " " , data ) ; if ( ! nl ) return NULL ; lx1 = lg ( gel ( data , 1 ) ) ; if ( ! param && lx1 == 1 ) return NULL ; if ( nl == 1 && ! cplx ) pari_err_DIM ( " " ) ; l = ( dblPointList * ) pari_malloc ( ( cplx ? 2 * nl : nl ) * sizeof ( dblPointList ) ) ; L = & l [ 0 ] ; for ( i = 0 ; i < nl ; i += cplx ? 1 : 2 ) { GEN x = gel ( data , i + 1 ) , y ; long lx = lg ( x ) ; if ( ! is_vec_t ( typ ( x ) ) ) pari_err_TYPE ( " " , x ) ; if ( cplx ) y = NULL ; else { y = gel ( data , i + 2 ) ; if ( ! is_vec_t ( typ ( y ) ) ) pari_err_TYPE ( " " , y ) ; if ( lg ( y ) != lx || ( ! param && lx != lx1 ) ) pari_err_DIM ( " " ) ; } lx -- ; l [ i ] . d = X = ( double * ) pari_malloc ( lx * sizeof ( double ) ) ; l [ i + 1 ] . d = Y = ( double * ) pari_malloc ( lx * sizeof ( double ) ) ; for ( j = 1 ; j <= lx ; j ++ ) get_xy_from_vec2 ( cplx , x , y , j , X + ( j - 1 ) , Y + ( j - 1 ) ) ; l [ i ] . nb = l [ i + 1 ] . nb = lx ; } if ( param ) { L -> nb = cplx ? nl : nl / 2 ; for ( i = 0 ; i < L -> nb ; i += 2 ) if ( l [ i + 1 ] . nb ) break ; if ( i >= L -> nb ) { pari_free ( l ) ; return NULL ; } L -> xsml = L -> xbig = l [ i ] . d [ 0 ] ; L -> ysml = L -> ybig = l [ i + 1 ] . d [ 0 ] ; for ( ; i < L -> nb ; i += 2 ) { long nbi = l [ i + 1 ] . nb ; X = l [ i ] . d ; Y = l [ i + 1 ] . d ; for ( j = 0 ; j < nbi ; j ++ ) { set_xrange ( L , X [ j ] ) ; set_yrange ( L , Y [ j ] ) ; } } } else { L -> nb = nl - 1 ; X = L -> d ; L -> xsml = L -> xbig = X [ 0 ] ; Y = l [ 1 ] . d ; L -> ysml = L -> ybig = Y [ 0 ] ; for ( j = 0 ; j < l [ 1 ] . nb ; j ++ ) set_xrange ( L , X [ j ] ) ; for ( i = 1 ; i <= L -> nb ; i ++ ) { long nbi = l [ i ] . nb ; Y = l [ i ] . d ; for ( j = 0 ; j < nbi ; j ++ ) set_yrange ( L , Y [ j ] ) ; } } return l ; }
Convert data from GEN to double before we call plotrecthrawin.
Convert data from GEN to double before we call plotrecthrawin .
/* Allocate memory, then convert coord. to double */ /* Compute extremas */