We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › strange results from point.contains(x, y);
Page Index Toggle Pages: 1
strange results from point.contains(x, y); (Read 450 times)
strange results from point.contains(x, y);
Aug 19th, 2008, 10:59am
 
Not strictly a processing problem, as far as I can tell, but can anyone account for the inaccuracies this snippet produces?

point.contains() would seem to be the obvious culprit.

Thanks,
Quote:


Polygon p1;

void setup() {
 size(400, 400);

 p1 = new Polygon();
 p1.addPoint(0, 0);
 p1.addPoint(width, height);
 p1.addPoint(0, height);
}

void draw() {
 loadPixels();
 for(int j=0; j<height; j++) {
   for(int i=0; i<width; i++) {

     if(p1.contains(i, j)) {
       pixels[(j*width)+i] = color(0, 255, 0);
     }
     else {
       pixels[(j*width)+i] = color(255, 0, 0);
     }
   }
 }
 updatePixels();
}


Re: strange results from point.contains(x, y);
Reply #1 - Aug 19th, 2008, 2:44pm
 
Looks like a floating point rounding issue.
Funnily, if you use size(399, 399), the frontier is smooth...
Page Index Toggle Pages: 1