The R Project SVN R

Rev

Rev 14357 | Rev 15508 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14357 Rev 15168
Line 1581... Line 1581...
1581
 
1581
 
1582
 
1582
 
1583
SEXP do_rect(SEXP call, SEXP op, SEXP args, SEXP env)
1583
SEXP do_rect(SEXP call, SEXP op, SEXP args, SEXP env)
1584
{
1584
{
1585
    /* rect(xl, yb, xr, yt, col, border, lty, lwd, xpd) */
1585
    /* rect(xl, yb, xr, yt, col, border, lty, lwd, xpd) */
1586
    SEXP sxl, sxr, syb, syt, col, lty, lwd, border;
1586
    SEXP sxl, sxr, syb, syt, sxpd, col, lty, lwd, border;
1587
    double *xl, *xr, *yb, *yt, x0, y0, x1, y1;
1587
    double *xl, *xr, *yb, *yt, x0, y0, x1, y1;
1588
    int i, n, nxl, nxr, nyb, nyt, ncol, nlty, nlwd, nborder, xpd;
1588
    int i, n, nxl, nxr, nyb, nyt, ncol, nlty, nlwd, nborder, xpd;
1589
    SEXP originalArgs = args;
1589
    SEXP originalArgs = args;
1590
    DevDesc *dd = CurrentDevice();
1590
    DevDesc *dd = CurrentDevice();
1591
 
1591
 
Line 1612... Line 1612...
1612
 
1612
 
1613
    PROTECT(lwd = FixupLwd(CAR(args), dd->gp.lwd));
1613
    PROTECT(lwd = FixupLwd(CAR(args), dd->gp.lwd));
1614
    nlwd = length(lwd);
1614
    nlwd = length(lwd);
1615
    args = CDR(args);
1615
    args = CDR(args);
1616
 
1616
 
1617
    xpd = asInteger(CAR(args));
1617
    sxpd = CAR(args);
-
 
1618
    if (sxpd != R_NilValue)
-
 
1619
	xpd = asInteger(sxpd);
-
 
1620
    else
-
 
1621
	xpd = dd->gp.xpd;
1618
    args = CDR(args);
1622
    args = CDR(args);
1619
 
1623
 
1620
    GSavePars(dd);
1624
    GSavePars(dd);
1621
 
1625
 
1622
    if (xpd == NA_INTEGER)
1626
    if (xpd == NA_INTEGER)
Line 1661... Line 1665...
1661
 
1665
 
1662
 
1666
 
1663
SEXP do_arrows(SEXP call, SEXP op, SEXP args, SEXP env)
1667
SEXP do_arrows(SEXP call, SEXP op, SEXP args, SEXP env)
1664
{
1668
{
1665
    /* arrows(x0, y0, x1, y1, length, angle, code, col, lty, lwd, xpd) */
1669
    /* arrows(x0, y0, x1, y1, length, angle, code, col, lty, lwd, xpd) */
1666
    SEXP sx0, sx1, sy0, sy1, col, lty, lwd;
1670
    SEXP sx0, sx1, sy0, sy1, sxpd, col, lty, lwd;
1667
    double *x0, *x1, *y0, *y1;
1671
    double *x0, *x1, *y0, *y1;
1668
    double xx0, yy0, xx1, yy1;
1672
    double xx0, yy0, xx1, yy1;
1669
    double hlength, angle;
1673
    double hlength, angle;
1670
    int code;
1674
    int code;
1671
    int nx0, nx1, ny0, ny1, i, n, ncol, nlty, nlwd, xpd;
1675
    int nx0, nx1, ny0, ny1, i, n, ncol, nlty, nlwd, xpd;
Line 1709... Line 1713...
1709
    nlwd = length(lwd);
1713
    nlwd = length(lwd);
1710
    if (nlwd == 0)
1714
    if (nlwd == 0)
1711
	errorcall(call, "'lwd' must be numeric of length >=1");
1715
	errorcall(call, "'lwd' must be numeric of length >=1");
1712
    args = CDR(args);
1716
    args = CDR(args);
1713
 
1717
 
1714
    xpd = asInteger(CAR(args));
1718
    sxpd = CAR(args);
-
 
1719
    if (sxpd != R_NilValue)
-
 
1720
	xpd = asInteger(sxpd);
-
 
1721
    else
-
 
1722
	xpd = dd->gp.xpd;
1715
    args = CDR(args);
1723
    args = CDR(args);
1716
 
1724
 
1717
    GSavePars(dd);
1725
    GSavePars(dd);
1718
 
1726
 
1719
    if (xpd == NA_INTEGER)
1727
    if (xpd == NA_INTEGER)
Line 2526... Line 2534...
2526
 
2534
 
2527
 
2535
 
2528
/*  abline(a, b, h, v, col, lty, lwd, ...)
2536
/*  abline(a, b, h, v, col, lty, lwd, ...)
2529
    draw lines in intercept/slope form.  */
2537
    draw lines in intercept/slope form.  */
2530
 
2538
 
-
 
2539
static void getxlimits(double *x, DevDesc *dd) {
-
 
2540
    /*
-
 
2541
     * xpd = 0 means clip to current plot region
-
 
2542
     * xpd = 1 means clip to current figure region
-
 
2543
     * xpd = 2 means clip to device region
-
 
2544
     */
-
 
2545
    switch (dd->gp.xpd) {
-
 
2546
    case 0:
-
 
2547
	x[0] = dd->gp.usr[0];
-
 
2548
	x[1] = dd->gp.usr[1];
-
 
2549
	break;
-
 
2550
    case 1:
-
 
2551
	x[0] = GConvertX(0, NFC, USER, dd);
-
 
2552
	x[1] = GConvertX(1, NFC, USER, dd);
-
 
2553
	break;
-
 
2554
    case 2:
-
 
2555
	x[0] = GConvertX(0, NDC, USER, dd);
-
 
2556
	x[1] = GConvertX(1, NDC, USER, dd);
-
 
2557
	break;
-
 
2558
    }
-
 
2559
}
-
 
2560
 
-
 
2561
static void getylimits(double *y, DevDesc *dd) {
-
 
2562
    switch (dd->gp.xpd) {
-
 
2563
    case 0:
-
 
2564
	y[0] = dd->gp.usr[2];
-
 
2565
	y[1] = dd->gp.usr[3];
-
 
2566
	break;
-
 
2567
    case 1:
-
 
2568
	y[0] = GConvertY(0, NFC, USER, dd);
-
 
2569
	y[1] = GConvertY(1, NFC, USER, dd);
-
 
2570
	break;
-
 
2571
    case 2:
-
 
2572
	y[0] = GConvertY(0, NDC, USER, dd);
-
 
2573
	y[1] = GConvertY(1, NDC, USER, dd);
-
 
2574
	break;
-
 
2575
    }
-
 
2576
}
-
 
2577
 
2531
SEXP do_abline(SEXP call, SEXP op, SEXP args, SEXP env)
2578
SEXP do_abline(SEXP call, SEXP op, SEXP args, SEXP env)
2532
{
2579
{
2533
    SEXP a, b, h, v, untf, col, lty, lwd;
2580
    SEXP a, b, h, v, untf, col, lty, lwd;
2534
    int i, ncol, nlines, nlty, nlwd;
2581
    int i, ncol, nlines, nlty, nlwd;
2535
    double aa, bb, x[2], y[2];
2582
    double aa, bb, x[2], y[2];
Line 2570... Line 2617...
2570
    PROTECT(lwd = FixupLwd(CAR(args), dd->gp.lwd));     args = CDR(args);
2617
    PROTECT(lwd = FixupLwd(CAR(args), dd->gp.lwd));     args = CDR(args);
2571
    nlwd = length(lwd);
2618
    nlwd = length(lwd);
2572
 
2619
 
2573
    GSavePars(dd);
2620
    GSavePars(dd);
2574
 
2621
 
-
 
2622
    ProcessInlinePars(args, dd); 
-
 
2623
 
2575
    nlines = 0;
2624
    nlines = 0;
2576
 
2625
 
2577
    if (a != R_NilValue) {
2626
    if (a != R_NilValue) {
2578
	if (b == R_NilValue) {
2627
	if (b == R_NilValue) {
2579
	    if (LENGTH(a) != 2)
2628
	    if (LENGTH(a) != 2)
Line 2592... Line 2641...
2592
	if (nlty && INTEGER(lty)[0] != NA_INTEGER)
2641
	if (nlty && INTEGER(lty)[0] != NA_INTEGER)
2593
	    dd->gp.lty = INTEGER(lty)[0];
2642
	    dd->gp.lty = INTEGER(lty)[0];
2594
	else
2643
	else
2595
	    dd->gp.lty = dd->dp.lty;
2644
	    dd->gp.lty = dd->dp.lty;
2596
	GMode(1, dd);
2645
	GMode(1, dd);
-
 
2646
	/* FIXME?
-
 
2647
	 * Seems like the logic here is just draw from xmin to xmax
-
 
2648
	 * and you're guaranteed to draw at least from ymin to ymax
-
 
2649
	 * This MAY cause a problem at some stage when the line being
-
 
2650
	 * drawn is VERY steep -- and the problem is worse now that
-
 
2651
	 * abline will potentially draw to the extents of the device
-
 
2652
	 * (when xpd=NA).  NOTE that R's internal clipping protects the
-
 
2653
	 * device drivers from stupidly large numbers, BUT there is 
-
 
2654
	 * still a risk that we could produce a number which is too
2597
	x[0] = dd->gp.usr[0];
2655
	 * big for the computer's brain.
-
 
2656
	 * Paul.
-
 
2657
	 */
2598
	x[1] = dd->gp.usr[1];
2658
	getxlimits(x, dd);
2599
	if (R_FINITE(dd->gp.lwd)) {
2659
	if (R_FINITE(dd->gp.lwd)) {
2600
	    if (LOGICAL(untf)[0] == 1 && (dd->gp.xlog || dd->gp.ylog)) {
2660
	    if (LOGICAL(untf)[0] == 1 && (dd->gp.xlog || dd->gp.ylog)) {
2601
		double xx[101], yy[101];
2661
		double xx[101], yy[101];
2602
		double xstep = (x[1] - x[0])/100;
2662
		double xstep = (x[1] - x[0])/100;
2603
		for (i = 0; i < 100; i++) {
2663
		for (i = 0; i < 100; i++) {
Line 2637... Line 2697...
2637
	    else
2697
	    else
2638
		dd->gp.lty = dd->dp.lty;
2698
		dd->gp.lty = dd->dp.lty;
2639
	    dd->gp.lwd = REAL(lwd)[nlines % nlwd];
2699
	    dd->gp.lwd = REAL(lwd)[nlines % nlwd];
2640
	    aa = REAL(h)[i];
2700
	    aa = REAL(h)[i];
2641
	    if (R_FINITE(aa) && R_FINITE(dd->gp.lwd)) {
2701
	    if (R_FINITE(aa) && R_FINITE(dd->gp.lwd)) {
2642
		x[0] = dd->gp.usr[0];
-
 
2643
		x[1] = dd->gp.usr[1];
2702
		getxlimits(x, dd);
2644
		y[0] = aa;
2703
		y[0] = aa;
2645
		y[1] = aa;
2704
		y[1] = aa;
2646
		GLine(x[0], y[0], x[1], y[1], USER, dd);
2705
		GLine(x[0], y[0], x[1], y[1], USER, dd);
2647
	    }
2706
	    }
2648
	    nlines++;
2707
	    nlines++;
Line 2658... Line 2717...
2658
	    else
2717
	    else
2659
		dd->gp.lty = dd->dp.lty;
2718
		dd->gp.lty = dd->dp.lty;
2660
	    dd->gp.lwd = REAL(lwd)[nlines % nlwd];
2719
	    dd->gp.lwd = REAL(lwd)[nlines % nlwd];
2661
	    aa = REAL(v)[i];
2720
	    aa = REAL(v)[i];
2662
	    if (R_FINITE(aa) && R_FINITE(dd->gp.lwd)) {
2721
	    if (R_FINITE(aa) && R_FINITE(dd->gp.lwd)) {
2663
		y[0] = dd->gp.usr[2];
-
 
2664
		y[1] = dd->gp.usr[3];
2722
		getylimits(y, dd);
2665
		x[0] = aa;
2723
		x[0] = aa;
2666
		x[1] = aa;
2724
		x[1] = aa;
2667
		GLine(x[0], y[0], x[1], y[1], USER, dd);
2725
		GLine(x[0], y[0], x[1], y[1], USER, dd);
2668
	    }
2726
	    }
2669
	    nlines++;
2727
	    nlines++;