#23 Incorrect fill for polygons partly outside viewport

closed
nobody
None
5
2005-04-26
2005-01-11
Arjen Markus
No

I have a problem with filling polygons that do not wholly
fit into the viewport. The program below illustrates this
(change #if 1 to #if 0 to change the scale and see the
correct polygon):

#include "plcdemos.h"

void
plfbox(PLFLT x0, PLFLT y0);

/*----------------------------------------------------
----------------------*\ * main
*
* Try and demonstrate that filling polygons that partly
fall outside
* the viewport fails.
\*----------------------------------------------------
----------------------*/

int
main(int argc, char *argv[])
{
int i;
char string[20];
PLFLT x0[10];
PLFLT y0[10];

/* Parse and process command line arguments */

(void) plParseOpts(&argc, argv, PL_PARSE_FULL);

/* Initialize plplot */

plinit();

pladv(0);
plvsta();
#if 1
plwind(0.0, 100.0, 0.0, 100.0);
#else
plwind(-500.0, 500.0, -500.0, 500.0);
#endif
plbox("bc", 1.0, 0, "bcnv", 10.0, 0);
plcol0(2);

x0[0] = 20 ; y0[0] = -20;
x0[1] = 30 ; y0[1] = 30;
x0[2] = 110 ; y0[2] = 1120;
/* x0[3] = 150 ; y0[3] = 70; */
x0[3] = 250 ; y0[3] = -270;
x0[4] = 20 ; y0[4] = -20;

plcol0(1);
plpsty(1);
plfill(5, x0, y0);
plcol0(2);
pllsty(1);
plline(5, x0, y0);

/* Don't forget to call plend() to finish off! */

plend();
exit(0);
}

Discussion

  • Arjen Markus
    Arjen Markus
    2005-01-12

    Logged In: YES
    user_id=400048

    Note that the problem does not occur when coordinate pair
    [3] is given the values 150, 70 as in the comment.

    Presumably some specific case is missing from the plfill()
    routine.

     
  • Arjen Markus
    Arjen Markus
    2005-01-18

    Logged In: YES
    user_id=400048

    I solved the problem: it turned out to be an integer overflow
    in the function circulation() in plline.c. It may very well be
    that this is manifest only on Windows, using the Visual C/C++
    compiler.
    The solution consists of computing the _signed_ area
    enclosed by the polygon, using floating-points instead of
    integers. This is hardly slower than using integers with current
    hardware and the main performance cost is the actual
    graphical operation anyway

     
  • Arjen Markus
    Arjen Markus
    2005-04-26

    Logged In: YES
    user_id=400048

    After discovering yet another case where the polygon was not
    filled correctly, I was able to really (?) solve this bug. I am
    closing the report.

     
  • Arjen Markus
    Arjen Markus
    2005-04-26

    • status: open --> closed