# rect() with stroke outline renders 1px wider and taller in P2D #2065

Closed
opened this Issue Sep 5, 2013 · 2 comments

Projects
None yet
4 participants
Contributor

### martinleopold commented Sep 5, 2013

 This is the output of multiple rect(x,y,3,3) calls rendered with default P2D. Black pixels are placed 1px apart to provide a reference. Fill is green, stroke is red. It seems that the stroke is overlayed starting at the top left corner but extending one extra pixel down and to the right. If this is intended, I wonder what's the reasoning behind it?
Contributor

### boubpopsyteam commented Sep 5, 2013

 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.

Contributor

### JakubValtar commented Aug 4, 2015

 Hi! 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.

Closed