Fix contour tool cannot draw only one pixel

The purpose of this fix is enable drawing of one pixel with contour
tool is active and we drag the cursor inside of the same
pixel (https://community.aseprite.org/t/3509).

Added 3 tests in polygon_tests.cpp to test polygon function when the
expected results is a simple pixel.
This commit is contained in:
Gaspar Capello 2019-07-10 23:10:18 -03:00 committed by David Capello
parent 04d547ce37
commit 33dd70f89d
2 changed files with 57 additions and 1 deletions

View File

@ -143,7 +143,13 @@ void algorithm::polygon(int vertices, const int* points, void* data, AlgoHLine p
verts[0].y,
(void*)&pts,
(AlgoPixel)&addPointsWithoutDuplicatingLastOne);
pts.pop_back();
// Consideration when we want to draw a simple pixel with contour tool
// dragging the cursor inside of a pixel (in this case pts contains
// just one element, which want to preserve).
if (pts.size() > 1)
// We remove the last point which is a duplicate point of
// the "pts" first element.
pts.pop_back();
}
else {
algo_line_continuous(verts[c].x,

View File

@ -32,6 +32,56 @@ void captureHscanSegment (int x1, int y, int x2, void* scanDataResults) {
// polygon() function TESTS:
// =========================
TEST(Polygon, SinglePoint1)
{
// P0
int points[2] = { 2 , 3
};
int n = 1;
ScanLineResult results;
doc::algorithm::polygon(n, &points[0], &results, captureHscanSegment);
EXPECT_EQ(results.scanLines.size(), 1);
if (results.scanLines.size() == 1) {
EXPECT_EQ(results.scanLines[0].x1, 2);
EXPECT_EQ(results.scanLines[0].x2, 2);
EXPECT_EQ(results.scanLines[0].y, 3);
}
}
TEST(Polygon, SinglePoint2)
{
// P0=P1
int points[4] = { 2 , 3 ,
2 , 3
};
int n = 2;
ScanLineResult results;
doc::algorithm::polygon(n, &points[0], &results, captureHscanSegment);
EXPECT_EQ(results.scanLines.size(), 1);
if (results.scanLines.size() == 1) {
EXPECT_EQ(results.scanLines[0].x1, 2);
EXPECT_EQ(results.scanLines[0].x2, 2);
EXPECT_EQ(results.scanLines[0].y, 3);
}
}
TEST(Polygon, SinglePoint3)
{
// P0=P1=P2
int points[6] = { 2 , 3 ,
2 , 3 , 2 , 3
};
int n = 3;
ScanLineResult results;
doc::algorithm::polygon(n, &points[0], &results, captureHscanSegment);
EXPECT_EQ(results.scanLines.size(), 1);
if (results.scanLines.size() == 1) {
EXPECT_EQ(results.scanLines[0].x1, 2);
EXPECT_EQ(results.scanLines[0].x2, 2);
EXPECT_EQ(results.scanLines[0].y, 3);
}
}
TEST(Polygon, HorizontalLine1Test)
{
// P0-----P1