示例#1
0
void
c_plbin( PLINT nbin, const PLFLT *x, const PLFLT *y, PLINT flags )
{
    PLINT i;
    PLFLT xmin, xmax, vpwxmi, vpwxma, vpwymi, vpwyma;

    if ( m_plsc->level < 3 )
    {
        plabort( "plbin: Please set up window first" );
        return;
    }

    // Check x[i] are in ascending order

    for ( i = 0; i < nbin - 1; i++ )
    {
        if ( x[i] >= x[i + 1] )
        {
            plabort( "plbin: Elements of x array must be increasing" );
            return;
        }
    }

    plP_xgvpw( &vpwxmi, &vpwxma, &vpwymi, &vpwyma );
    if ( !( flags & 1 ) )
    {
        for ( i = 0; i < nbin - 1; i++ )
        {
            if ( !( flags & 4 ) || ( y[i] != vpwymi ) )
            {
                pljoin( x[i], vpwymi, x[i], y[i] );
                pljoin( x[i], y[i], x[i + 1], y[i] );
                pljoin( x[i + 1], y[i], x[i + 1], vpwymi );
            }
        }
        if ( flags & 2 )
        {
            if ( !( flags & 4 ) || ( y[i] != vpwymi ) )
            {
                int xm = (int) ( x[i] + ( x[i] - x[i - 1] ) );
                pljoin( x[i], vpwymi, x[i], y[i] );
                pljoin( x[i], y[i], xm, y[i] );
                pljoin( xm, y[i], xm, vpwymi );
            }
        }
        else
        {
            if ( x[i] < vpwxma )
            {
                if ( !( flags & 4 ) || ( y[i] != vpwymi ) )
                {
                    pljoin( x[i], vpwymi, x[i], y[i] );
                    pljoin( x[i], y[i], vpwxma, y[i] );
                    pljoin( vpwxma, y[i], vpwxma, vpwymi );
                }
            }
        }
    }
    else
    {
        if ( nbin < 2 )
            return;
        if ( flags & 2 )
        {
            xmin = MAX( vpwxmi, 0.5 * ( 3 * x[0] - x[1] ) );
        }
        else
        {
            xmin = vpwxmi;
        }
        // Vince fixed bug May 1998
        xmax = MAX( 0.5 * ( x[0] + x[1] ), vpwxmi );
        if ( xmin < xmax )
        {
            pljoin( xmin, vpwymi, xmin, y[0] );
            pljoin( xmin, y[0], xmax, y[0] );
            pljoin( xmax, y[0], xmax, vpwymi );
        }
        for ( i = 1; i < nbin - 1; i++ )
        {
            xmin = xmax;
            xmax = MIN( 0.5 * ( x[i] + x[i + 1] ), vpwxma );
            if ( !( flags & 4 ) || ( y[i] != vpwymi ) )
            {
                pljoin( xmin, vpwymi, xmin, y[i] );
                pljoin( xmin, y[i], xmax, y[i] );
                pljoin( xmax, y[i], xmax, vpwymi );
            }
        }
        xmin = xmax;
        xmax = vpwxma;
        if ( flags & 2 )
        {
            xmax = MIN( vpwxma, 0.5 * ( 3 * x[i] - x[i - 1] ) );
        }
        else
        {
            xmax = vpwxma;
        }
        if ( xmin < xmax )
        {
            if ( !( flags & 4 ) || ( y[i] != vpwymi ) )
            {
                pljoin( xmin, vpwymi, xmin, y[i] );
                pljoin( xmin, y[i], xmax, y[i] );
                pljoin( xmax, y[i], xmax, vpwymi );
            }
        }
    }
}
示例#2
0
void
c_plwind(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax)
{
    PLFLT dx, dy, mmxmi, mmxma, mmymi, mmyma;
    PLFLT xvpwxmin, xvpwxmax, xvpwymin, xvpwymax;
    PLWindow w;

    if (plsc->level < 2) {
	plabort("plwind: Please set up viewport first");
	return;
    }

/* Best to just warn and recover on bounds errors */

    if (xmin == xmax) {
	plwarn("plwind: Invalid window limits in x.");
	xmin--; xmax++;
    }
    if (ymin == ymax) {
	plwarn("plwind: Invalid window limits in y.");
	ymin--; ymax++;
    }

    plsc->vpwxmi = xmin;
    plsc->vpwxma = xmax;
    plsc->vpwymi = ymin;
    plsc->vpwyma = ymax;
   
/* The true plot window is made slightly larger than requested so that */
/* the end limits will be on the graph  */
/* Get the (slightly extended) window limits. */
    plP_xgvpw(&xvpwxmin, &xvpwxmax, &xvpwymin, &xvpwymax);

/* Compute the scaling between coordinate systems */

    dx = xvpwxmax - xvpwxmin;
    dy = xvpwymax - xvpwymin;

    plsc->wpxscl = (plsc->vppxma - plsc->vppxmi) / dx;
    plsc->wpxoff = (xmax * plsc->vppxmi - xmin * plsc->vppxma) / dx;
    plsc->wpyscl = (plsc->vppyma - plsc->vppymi) / dy;
    plsc->wpyoff = (ymax * plsc->vppymi - ymin * plsc->vppyma) / dy;

    mmxmi = plP_dcmmx(plsc->vpdxmi);
    mmxma = plP_dcmmx(plsc->vpdxma);
    mmymi = plP_dcmmy(plsc->vpdymi);
    mmyma = plP_dcmmy(plsc->vpdyma);

/* Set transformation variables for world coordinates to mm */

    plsc->wmxscl = (mmxma - mmxmi) / dx;
    plsc->wmxoff = (xmax * mmxmi - xmin * mmxma) / dx;
    plsc->wmyscl = (mmyma - mmymi) / dy;
    plsc->wmyoff = (ymax * mmymi - ymin * mmyma) / dy;

/* Set transformation variables for world coordinates to device coords */

    plsc->wdxscl = plsc->wmxscl * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
    plsc->wdxoff = plsc->wmxoff * plsc->xpmm / (plsc->phyxma - plsc->phyxmi);
    plsc->wdyscl = plsc->wmyscl * plsc->ypmm / (plsc->phyyma - plsc->phyymi);
    plsc->wdyoff = plsc->wmyoff * plsc->ypmm / (plsc->phyyma - plsc->phyymi);

/* Register plot window attributes */

    w.dxmi = plsc->vpdxmi;
    w.dxma = plsc->vpdxma;
    w.dymi = plsc->vpdymi;
    w.dyma = plsc->vpdyma;

    w.wxmi = xvpwxmin;
    w.wxma = xvpwxmax;
    w.wymi = xvpwymin;
    w.wyma = xvpwymax;

    plP_swin(&w);

/* Go to level 3 */

    plsc->level = 3;
}