From 0a27bbe2b518ea76414a122c5fe235b9f4267214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 5 May 2019 02:42:16 +0200 Subject: [PATCH] Expand tests --- s3l.h | 4 ++++ test.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/s3l.h b/s3l.h index ef4a0af..4e550c2 100644 --- a/s3l.h +++ b/s3l.h @@ -89,6 +89,10 @@ - Adjacent triangles don't have any overlapping pixels, nor gaps between. - Triangles of points that lie on a single line are NOT rasterized. - A single "long" triangle CAN be rasterized as non-continuous. + - Transforming (e.g. mirroring, rotating by 90 degrees etc.) a result of + rasterizing triangle A is NOT generally equal to applying the same + transformation to triangle A first and then rasterizing it. Even the number + of rasterized pixels is usually different. - If specifying a triangle with integer coordinates, then: - a Bottom-most corner (or side) of a triangle is never rasterized (because it is connected to a right side). diff --git a/test.c b/test.c index 8e9adde..3f45bc5 100644 --- a/test.c +++ b/test.c @@ -74,6 +74,14 @@ uint16_t testRasterization() printf("\n=== TESTING RASTERIZATION ===\n"); uint16_t numErrors = 0; + + uint8_t pixelsEmpty[TEST_BUFFER_W * TEST_BUFFER_H]; + memset(pixelsEmpty,0,TEST_BUFFER_W * TEST_BUFFER_H); + + numErrors += testTriangleRasterization(5,3, 3,3, 9,3, pixelsEmpty); + numErrors += testTriangleRasterization(9,4, 9,0, 9,9, pixelsEmpty); + numErrors += testTriangleRasterization(3,3, 6,6, 7,7, pixelsEmpty); + numErrors += testTriangleRasterization(5,5, 3,7, 9,1, pixelsEmpty); uint8_t pixels1[TEST_BUFFER_W * TEST_BUFFER_H] = { @@ -167,13 +175,51 @@ uint16_t testRasterization() numErrors += testTriangleRasterization(4,8, 4,2, 0,0, pixels4); - uint8_t pixelsEmpty[TEST_BUFFER_W * TEST_BUFFER_H]; - memset(pixelsEmpty,0,TEST_BUFFER_W * TEST_BUFFER_H); + uint8_t pixels5[TEST_BUFFER_W * TEST_BUFFER_H] = + { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0 + 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, // 1 + 0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0, // 2 + 0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0, // 3 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 4 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 5 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 6 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 7 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 8 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 9 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // A + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // B + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // C + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // D + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // E + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // F + }; - numErrors += testTriangleRasterization(5,3, 3,3, 9,3, pixelsEmpty); - numErrors += testTriangleRasterization(9,4, 9,0, 9,9, pixelsEmpty); - numErrors += testTriangleRasterization(3,3, 6,6, 7,7, pixelsEmpty); - numErrors += testTriangleRasterization(5,5, 3,7, 9,1, pixelsEmpty); + numErrors += testTriangleRasterization(6,2, 2,4, 0,0, pixels5); + + uint8_t pixels6[TEST_BUFFER_W * TEST_BUFFER_H] = + { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 0 + 0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0, // 1 + 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0, // 2 + 0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0, // 3 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 4 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 5 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 6 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 7 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 8 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 9 + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // A + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // B + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // C + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // D + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // E + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 // F + }; + + numErrors += testTriangleRasterization(0,2, 6,0, 4,4, pixels6); printf("total rasterization errors: %d\n",numErrors); }