Add unit test for ellipse boundary pixels

Add test verifying that the ellipse is drawn in the expected way, even
if this is not really intuitive because it can overflow its bounding
rectangle.

Closes #24620.
This commit is contained in:
Bill Su
2024-08-11 22:19:12 +02:00
committed by Vadim Zeitlin
parent fafcab97ce
commit 78bc9f24f3
+113
View File
@@ -170,6 +170,7 @@ TEST_CASE("BitmapTestCase::ToImage", "[bitmap][image][convertto]")
}
}
// rectangle transparent pen test
for ( int size = 4 ; size != 0 ; --size )
{
INFO("Red square size: " << size)
@@ -215,6 +216,118 @@ TEST_CASE("BitmapTestCase::ToImage", "[bitmap][image][convertto]")
}
}
}
/* ellipse boundary test: on wxMSW, ellipse goes outside
rect on right and bottom */
{
wxBitmap bmp2 = bmp;
// verify bmp starts yellow
{
wxNativePixelData dataBmp(bmp2);
wxNativePixelData::Iterator rowStartBmp(dataBmp);
for ( int y = 0; y < bmp2.GetHeight(); ++y )
{
wxNativePixelData::Iterator iBmp = rowStartBmp;
for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp )
{
wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue());
CHECK_EQUAL_COLOUR_RGB(bmpc, (*wxYELLOW));
}
rowStartBmp.OffsetY(dataBmp, 1);
}
}
// change rectangle to red
wxRect rect(wxPoint(3, 3), wxSize(10, 5));
{
wxMemoryDC dc(bmp2);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle(rect);
}
// verify bitmap is still yellow, except rectangle is red
{
wxNativePixelData dataBmp(bmp2);
wxNativePixelData::Iterator rowStartBmp(dataBmp);
for ( int y = 0; y < bmp2.GetHeight(); ++y )
{
wxNativePixelData::Iterator iBmp = rowStartBmp;
for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp )
{
wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue());
CHECK_EQUAL_COLOUR_RGB(bmpc, (rect.Contains(x, y) ? *wxRED : *wxYELLOW));
}
rowStartBmp.OffsetY(dataBmp, 1);
}
}
// draw ellipse with rectangle bottomright moved in 1 (diagonal) pixel
{
wxMemoryDC dc(bmp2);
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
wxRect rect2(rect.GetTopLeft(), wxSize(rect.GetWidth() - 1, rect.GetHeight() - 1));
dc.DrawEllipse(rect2);
}
// verify bitmap is still yellow, except rectangle is red
{
wxNativePixelData dataBmp(bmp2);
wxNativePixelData::Iterator rowStartBmp(dataBmp);
for ( int y = 0; y < bmp2.GetHeight(); ++y )
{
wxNativePixelData::Iterator iBmp = rowStartBmp;
for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp )
{
wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue());
CHECK_EQUAL_COLOUR_RGB(bmpc, (rect.Contains(x, y) ? *wxRED : *wxYELLOW));
}
rowStartBmp.OffsetY(dataBmp, 1);
}
}
// draw ellipse with full rectangle
{
wxMemoryDC dc(bmp2);
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawEllipse(rect);
}
// verify that ellipse exceeded rect on bottom and right
{
bool pastBottom = false;
bool pastRight = false;
wxNativePixelData dataBmp(bmp2);
wxNativePixelData::Iterator rowStartBmp(dataBmp);
for ( int y = 0; y < bmp2.GetHeight(); ++y )
{
wxNativePixelData::Iterator iBmp = rowStartBmp;
for ( int x = 0; x < bmp2.GetWidth(); ++x, ++iBmp )
{
wxColour bmpc(iBmp.Red(), iBmp.Green(), iBmp.Blue());
if (bmpc != (rect.Contains(x, y) ? *wxRED : *wxYELLOW))
{
INFO("x,y: " << x << ", " << y);
if (y == rect.GetBottom() + 1)
{
pastBottom = true;
}
if (x == rect.GetRight() + 1)
{
pastRight = true;
}
}
CHECK((bmpc == (rect.Contains(x, y) ? *wxRED : *wxYELLOW) ||
y == rect.GetBottom() + 1 ||
x == rect.GetRight() + 1));
}
rowStartBmp.OffsetY(dataBmp, 1);
}
CHECK((pastBottom && pastRight));
}
}
}
SECTION("RGB bitmap with mask")