A Processing precision problem?

Hello,

This example may help:

size (500, 500);

float dia;

PVector center = new PVector(width/2, height/2);

// Try ones of these 4 at a time:

// 1 left + top
dia = 400;
smooth(3);  //default

// 2 ok
//dia = 400;
//noSmooth();

// 3 ok
//dia = 401; 
//smooth(3);  //default

// 4 right + bottom
//dia = 401; 
//noSmooth();

rectMode(CENTER);
ellipseMode(CENTER);

fill(#EEEEEE);
strokeWeight(1);
rect(center.x, center.y, dia, dia);

noStroke();
fill(#FFFFFF);
circle(center.x, center.y, dia);

stroke(0);
line(center.x-250, center.y, center.x+250, center.y);
line(center.x, center.y-250, center.x, center.y+250);

I have had these issues before and have to adjust to lining up to pixels sometimes.

You can also try another renderer with your code:
https://processing.org/reference/size_.html

See the references about smooth() and noSmooth():
https://processing.org/reference/noSmooth_.html
https://processing.org/reference/smooth_.html

This also seemed to work with your original code:
float radius = 200.5;

I do not have a definitive solution and was experimenting a bit.

I suspect it is related to smoothing and anti-aliasing.

:)

2 Likes