[Bf-blender-cvs] [11a8e54] gtest-testing: Add topology check to polyfill
Campbell Barton
noreply at git.blender.org
Wed May 21 18:44:48 CEST 2014
Commit: 11a8e54cdd62fa48759112be185904935f44978c
Author: Campbell Barton
Date: Thu May 22 02:39:30 2014 +1000
https://developer.blender.org/rB11a8e54cdd62fa48759112be185904935f44978c
Add topology check to polyfill
===================================================================
M source/tests/blenlib_tests/polyfill2d_test.cc
===================================================================
diff --git a/source/tests/blenlib_tests/polyfill2d_test.cc b/source/tests/blenlib_tests/polyfill2d_test.cc
index cf210e69..8faaf04 100644
--- a/source/tests/blenlib_tests/polyfill2d_test.cc
+++ b/source/tests/blenlib_tests/polyfill2d_test.cc
@@ -3,18 +3,13 @@
extern "C" {
#include "BLI_polyfill2d.h"
#include "BLI_math.h"
+#include "BLI_edgehash.h"
#include "MEM_guardedalloc.h"
}
/* -------------------------------------------------------------------- */
/* tests */
-/*
- * TODO:
- * - check all edges along the polygon have one face user, all others 2.
- * - all indicies are used in a triangle least once.
- */
-
#define TRI_ERROR_VALUE (unsigned int)-1
static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri_tot)
@@ -55,6 +50,46 @@ static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri
MEM_freeN(tot_used); \
} (void)0
+#define TEST_POLYFILL_TOPOLOGY(poly, poly_tot, tri, tri_tot) \
+{ \
+ EdgeHash *edgehash = BLI_edgehash_new(__func__); \
+ EdgeHashIterator *ehi; \
+ unsigned int i; \
+ for (i = 0; i < tri_tot; i++) { \
+ unsigned int j; \
+ for (j = 0; j < 3; j++) { \
+ const unsigned int v1 = tri[i][j]; \
+ const unsigned int v2 = tri[i][(j + 1) % 3]; \
+ void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); \
+ if (p) { \
+ *p = (void *)((intptr_t)*p + (intptr_t)1); \
+ } \
+ else { \
+ BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1); \
+ } \
+ } \
+ } \
+ EXPECT_EQ(poly_tot + (poly_tot - 3), BLI_edgehash_size(edgehash)); \
+ \
+ for (i = 0; i < poly_tot; i++) { \
+ const unsigned int v1 = i; \
+ const unsigned int v2 = (i + 1) % poly_tot; \
+ void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); \
+ EXPECT_EQ(1, (void *)p != NULL); \
+ EXPECT_EQ(1, (intptr_t)*p); \
+ } \
+ \
+ for (ehi = BLI_edgehashIterator_new(edgehash), i = 0; \
+ BLI_edgehashIterator_isDone(ehi) == false; \
+ BLI_edgehashIterator_step(ehi), i++) \
+ { \
+ void **p = BLI_edgehashIterator_getValue_p(ehi); \
+ EXPECT_EQ(true, ELEM((intptr_t)*p, 1, 2)); \
+ } \
+ \
+ BLI_edgehash_free(edgehash, NULL); \
+} (void)0
+
/**
* Check all faces are flipped the same way
*/
@@ -99,6 +134,7 @@ static void test_valid_polyfill_prepare(unsigned int tris[][3], unsigned int tri
BLI_polyfill_calc(poly, poly_tot, tris); \
\
TEST_POLYFILL_SIMPLE(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
+ TEST_POLYFILL_TOPOLOGY(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
if (!is_degenerate) { \
TEST_POLYFILL_WINDING(poly, ARRAY_SIZE(poly), tris, ARRAY_SIZE(tris)); \
\
More information about the Bf-blender-cvs
mailing list