Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
rect() with stroke outline renders 1px wider and taller in P2D #2065
I may see an explanation,
Think of where is really the coordinate (x,y) :
First, let's assume it's in the center of the pixel. So the drawing from x to x+3 will fill the pixels x, x+1, x+2, x+3, because there's only 3 pixels between the center of x and x+3.
Second, think as the coordinates are in the upper left corner of the pixel. So that drawing from x to x+3 will fill x, x+1, x+2 (and not the x+3 because this coordinate is on the left edge).
Anyway it seems the renderer uses these 2 different centers in your example.
If the stroke weight is 1 px, 0.5 px would overlap the edge of the rect and 0.5 px would lay outside of the rect (so total width/height of the rectangle increases by 0.5 + 0.5 = 1 px). We move the stroke 0.5 px down and to the right to align in with pixel grid (otherwise it would be in two pixel columns/rows and would be blurred by antialiasing). We do this to make both strokes and shapes appear sharp in P2D.