0

First of all I am aware of this post here: Pixel behaviour of FillRectangle and DrawRectangle. But it does not fully address my issue.

Let's start with a square of length 3 created as follows:

RectF rc(0, 0, 3, 3);

If I fill this rectangle using Graphics::FillRectangle() then I get a square of 3 x 3 pixels as seen in the image below with the 2 little white squares:

enter image description here

If I then try to draw a border around these squares using Graphics::DrawRectangle(), and supplying exactly the same rect I used when I filled them, I get a border which covers 4 x 4 pixels thereby visually extending the squares by a pixel on the right and bottom:

enter image description here

I am led to understand this is because FillRectangle() doesn't draw the right or bottom edge. I can't find any documentation on why it behaves this way.

If I then bring Graphics::SetClip() into the equation, and set the clipping region to the same rect I have used in the previous 2 tests I get the following:

enter image description here

So, now the clipping region seems to ignore the right and bottom edges the same way that FillRectangle() does which seems silly given how DrawRectangle() works.

Can someone help me understand how all of this inconsistency should be interpreted?

1 Answers1

2

FillRectangle and SetClip ignore the right and bottom edges because that's the definition of a rectangle in Windows; it's two open ranges where the start points are included but the end points are not. That means you can easily define an empty rectangle where top=bottom or left=right. It also means if the top of one rectangle is the bottom of another, the two will meet perfectly with no overlap.

DrawRectangle is different, because it's defining a polygon with 4 sides and drawing those sides.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622