[Bf-blender-cvs] [1501329] gtest-testing: Initial polyfill2d test, mostly just to get the data + template in place.

Campbell Barton noreply at git.blender.org
Mon May 19 17:48:00 CEST 2014


Commit: 1501329b592f8030bff0a06673eb170efa2a262b
Author: Campbell Barton
Date:   Tue May 20 01:46:47 2014 +1000
https://developer.blender.org/rB1501329b592f8030bff0a06673eb170efa2a262b

Initial polyfill2d test, mostly just to get the data + template in place.

data from libgdx

===================================================================

M	source/tests/blenlib_tests/CMakeLists.txt
A	source/tests/blenlib_tests/polyfill2d_test.cc

===================================================================

diff --git a/source/tests/blenlib_tests/CMakeLists.txt b/source/tests/blenlib_tests/CMakeLists.txt
index e2b226b..e23f064 100644
--- a/source/tests/blenlib_tests/CMakeLists.txt
+++ b/source/tests/blenlib_tests/CMakeLists.txt
@@ -31,4 +31,5 @@ include_directories(${INC})
 
 BLENDER_TEST(mathutils_color "bf_blenlib")
 BLENDER_TEST(mathutils_geom "bf_blenlib")
+BLENDER_TEST(polyfill2d "bf_blenlib")
 BLENDER_TEST(path_util "bf_blenlib;extern_wcwidth;${ZLIB_LIBRARIES}")
diff --git a/source/tests/blenlib_tests/polyfill2d_test.cc b/source/tests/blenlib_tests/polyfill2d_test.cc
new file mode 100644
index 0000000..d95652d
--- /dev/null
+++ b/source/tests/blenlib_tests/polyfill2d_test.cc
@@ -0,0 +1,259 @@
+#include "testing/testing.h"
+
+extern "C" {
+#include "BLI_polyfill2d.h"
+#include "BLI_math.h"
+}
+
+/* -------------------------------------------------------------------- */
+/* tests */
+
+/*
+ * TODO:
+ * - check faces are flipped the same way.
+ * - check all edges along the polygon have one face user, all others 2.
+ * - all indicies are used in a triangle least once.
+ * - the area of the triangles combine adds up to the area of the polygon (with some error margin)...
+ *   ... note, this needs to be skipped for intentionally self-overlapping tests.
+ */
+
+#define TRI_ERROR_VALUE (unsigned int)-1
+
+static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri_tot)
+{
+	unsigned int i;
+	for (i = 0; i < tri_tot; i++) {
+		unsigned int j;
+		for (j = 0; j < 3; j++) {
+			tris[i][j] = TRI_ERROR_VALUE;
+		}
+	}
+}
+
+#define TEST_VALID_POLYFILL(tri, tri_tot) \
+	{ \
+		unsigned int i; \
+		for (i = 0; i < tri_tot; i++) { \
+			unsigned int j; \
+			for (j = 0; j < 3; j++) { \
+				EXPECT_NE(TRI_ERROR_VALUE, tri[i][j]); \
+			} \
+			EXPECT_NE(tri[i][0], tri[i][1]); \
+			EXPECT_NE(tri[i][1], tri[i][2]); \
+			EXPECT_NE(tri[i][2], tri[i][0]); \
+		} \
+	} (void)0
+
+#define TEST_POLYFILL_TEMPLATE_STATIC(poly) \
+{ \
+	unsigned int tris[POLY_TRI_COUNT(ARRAY_SIZE(poly))][3]; \
+	const unsigned int poly_tot = ARRAY_SIZE(poly); \
+	test_valid_polyfill_prepare(tris, ARRAY_SIZE(tris)); \
+	\
+	BLI_polyfill_calc(poly, poly_tot, tris); \
+	\
+	TEST_VALID_POLYFILL(tris, ARRAY_SIZE(tris)); \
+} (void)0
+
+
+#define POLY_TRI_COUNT(len) ((len) - 2)
+/* BLI_cleanup_path */
+TEST(pathutils, PolyFill2D_Empty)
+{
+	BLI_polyfill_calc(NULL, 0, NULL);
+}
+
+// @Override
+// public void create () {
+// // An empty "polygon"
+// testCases.add(new TestCase(new float[] {}, true));
+//
+// // A point
+// testCases.add(new TestCase(new float[] {0, 0}, true));
+//
+// // A line segment
+// testCases.add(new TestCase(new float[] {0, 0, 1, 1}, true));
+
+/* A counterclockwise triangle */
+TEST(pathutils, PolyFill2D_TriangleCCW)
+{
+	float poly[][2] = {{0, 0}, {0, 1}, {1, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* A counterclockwise square */
+TEST(pathutils, PolyFill2D_SquareCCW)
+{
+	float poly[][2] = {{0, 0}, {0, 1}, {1, 1}, {1, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* A clockwise square */
+TEST(pathutils, PolyFill2D_SquareCW)
+{
+	float poly[][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Starfleet insigna */
+TEST(pathutils, PolyFill2D_Starfleet)
+{
+	float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Starfleet insigna with repeated point */
+TEST(pathutils, PolyFill2D_StarfleetDegenerate)
+{
+	float poly[][2] = {{0, 0}, {0.6f, 0.4f}, {0.6f, 0.4f}, {1, 0}, {0.5f, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Three collinear points */
+TEST(pathutils, PolyFill2D_3Colinear)
+{
+	float poly[][2] = {{0, 0}, {1, 0}, {2, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Four collinear points */
+TEST(pathutils, PolyFill2D_4Colinear)
+{
+	float poly[][2] = {{0, 0}, {1, 0}, {2, 0}, {3, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Non-consecutive collinear points */
+TEST(pathutils, PolyFill2D_UnorderedColinear)
+{
+	float poly[][2] = {{0, 0}, {1, 1}, {2, 0}, {3, 1}, {4, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Plus shape */
+TEST(pathutils, PolyFill2D_PlusShape)
+{
+	float poly[][2] = {
+	    {1, 0}, {2, 0}, {2, 1}, {3, 1}, {3, 2}, {2, 2}, {2, 3}, {1, 3}, {1, 2}, {0, 2}, {0, 1}, {1, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Star shape */
+TEST(pathutils, PolyFill2D_StarShape)
+{
+	float poly[][2] = {
+	    {4, 0}, {5, 3}, {8, 4}, {5, 5}, {4, 8}, {3, 5}, {0, 4}, {3, 3},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* U shape */
+TEST(pathutils, PolyFill2D_UShape)
+{
+	float poly[][2] = {
+	    {1, 0}, {2, 0}, {3, 1}, {3, 3}, {2, 3}, {2, 1}, {1, 1}, {1, 3}, {0, 3}, {0, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Spiral */
+TEST(pathutils, PolyFill2D_Spiral)
+{
+	float poly[][2] = {
+	    {1, 0}, {4, 0}, {5, 1}, {5, 4}, {4, 5}, {1, 5}, {0, 4}, {0, 3},
+	    {1, 2}, {2, 2}, {3, 3}, {1, 3}, {1, 4}, {4, 4}, {4, 1}, {0, 1},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Test case from http:# www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml */
+TEST(pathutils, PolyFill2D_TestFlipCode)
+{
+	float poly[][2] = {
+	    {0, 6}, {0, 0}, {3, 0}, {4, 1}, {6, 1}, {8, 0}, {12, 0}, {13, 2},
+	    {8, 2}, {8, 4}, {11, 4}, {11, 6}, {6, 6}, {4, 3}, {2, 6},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Self-intersection */
+TEST(pathutils, PolyFill2D_SelfIntersect)
+{
+	float poly[][2] = {{0, 0}, {1, 1}, {2, -1}, {3, 1}, {4, 0},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Self-touching */
+TEST(pathutils, PolyFill2D_SelfTouch)
+{
+	float poly[][2] = {
+	    {0, 0}, {4, 0}, {4, 4}, {2, 4}, {2, 3}, {3, 3}, {3, 1}, {1, 1}, {1, 3}, {2, 3}, {2, 4}, {0, 4},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Self-overlapping */
+TEST(pathutils, PolyFill2D_SelfOverlap)
+{
+	float poly[][2] = {
+	    {0, 0}, {4, 0}, {4, 4}, {1, 4}, {1, 3}, {3, 3}, {3, 1}, {1, 1}, {1, 3}, {3, 3}, {3, 4}, {0, 4},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Test case from http:# www.davdata.nl/math/polygons.html */
+TEST(pathutils, PolyFill2D_TestDavData)
+{
+	float poly[][2] = {
+	    {190, 480}, {140, 180}, {310, 100}, {330, 390}, {290, 390}, {280, 260}, {220, 260}, {220, 430}, {370, 430},
+	    {350, 30}, {50, 30}, {160, 560}, {730, 510}, {710, 20}, {410, 30}, {470, 440}, {640, 410}, {630, 140},
+	    {590, 140}, {580, 360}, {510, 370}, {510, 60}, {650, 70}, {660, 450}, {190, 480},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Issue 815, http:# code.google.com/p/libgdx/issues/detail?id=815 */
+TEST(pathutils, PolyFill2D_TestIssue815)
+{
+	float poly[][2] = {
+	    {-2.0f, 0.0f}, {-2.0f, 0.5f}, {0.0f, 1.0f}, {0.5f, 2.875f},
+	    {1.0f, 0.5f}, {1.5f, 1.0f}, {2.0f, 1.0f}, {2.0f, 0.0f},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Issue 207, comment #1, http:# code.google.com/p/libgdx/issues/detail?id=207#c1 */
+TEST(pathutils, PolyFill2D_TestIssue207_1)
+{
+	float poly[][2] = {
+	    {72.42465f, 197.07095f}, {78.485535f, 189.92776f}, {86.12059f, 180.92929f}, {99.68253f, 164.94557f},
+	    {105.24325f, 165.79604f}, {107.21862f, 166.09814f}, {112.41958f, 162.78253f}, {113.73238f, 161.94562f},
+	    {123.29477f, 167.93805f}, {126.70667f, 170.07617f}, {73.22717f, 199.51062f},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Issue 207, comment #11, http:# code.google.com/p/libgdx/issues/detail?id=207#c11 */
+/* Also on issue 1081, http:# code.google.com/p/libgdx/issues/detail?id=1081 */
+TEST(pathutils, PolyFill2D_TestIssue207_11)
+{
+	float poly[][2] = {
+	    {2400.0f, 480.0f}, {2400.0f, 176.0f}, {1920.0f, 480.0f}, {1920.0459f, 484.22314f},
+	    {1920.1797f, 487.91016f}, {1920.3955f, 491.0874f}, {1920.6875f, 493.78125f}, {1921.0498f, 496.01807f},
+	    {1921.4766f, 497.82422f}, {1921.9619f, 499.22607f}, {1922.5f, 500.25f}, {1923.085f, 500.92236f},
+	    {1923.7109f, 501.26953f}, {1924.3721f, 501.31787f}, {1925.0625f, 501.09375f}, {1925.7764f, 500.62354f},
+	    {1926.5078f, 499.9336f}, {1927.251f, 499.0503f}, {1928.0f, 498.0f}, {1928.749f, 496.80908f},
+	    {1929.4922f, 495.5039f}, {1930.2236f, 494.11084f}, {1930.9375f, 492.65625f}, {1931.6279f, 491.1665f},
+	    {1932.2891f, 489.66797f}, {1932.915f, 488.187f}, {1933.5f, 486.75f}, {1934.0381f, 485.3833f},
+	    {1934.5234f, 484.11328f}, {1934.9502f, 482.9663f}, {1935.3125f, 481.96875f}, {1935.6045f, 481.14697f},
+	    {1935.8203f, 480.52734f}, {1935.9541f, 480.13623f}, {1936.0f, 480.0f},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Issue 1407, http:# code.google.com/p/libgdx/issues/detail?id=1407 */
+TEST(pathutils, PolyFill2D_TestIssue1407)
+{
+	float poly[][2] = {
+	    {3.914329f, 1.9008259f}, {4.414321f, 1.903619f}, {4.8973203f, 1.9063174f}, {5.4979978f, 1.9096732f},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}
+
+/* Issue 1407, http:# code.google.com/p/libgdx/issues/detail?id=1407, */
+/* with an additional point to show what is happening. */
+TEST(pathutils, PolyFill2D_TestIssue1407_pt)
+{
+	float poly[][2] = {
+	    {3.914329f, 1.9008259f}, {4.414321f, 1.903619f}, {4.8973203f, 1.9063174f}, {5.4979978f, 1.9096732f}, {4, 4},};
+	TEST_POLYFILL_TEMPLATE_STATIC(poly);
+}




More information about the Bf-blender-cvs mailing list