Blender  V3.3
Macros | Functions
BLI_polyfill_2d_test.cc File Reference
#include "testing/testing.h"
#include "MEM_guardedalloc.h"
#include "BLI_array_utils.h"
#include "BLI_edgehash.h"
#include "BLI_math.h"
#include "BLI_polyfill_2d.h"
#include "BLI_utildefines.h"
#include "BLI_heap.h"
#include "BLI_memarena.h"
#include "BLI_polyfill_2d_beautify.h"

Go to the source code of this file.

Macros

#define USE_COMBINATIONS_ALL
 
#define USE_BEAUTIFY
 
#define TRI_ERROR_VALUE   (unsigned int)-1
 
#define TEST_POLYFILL_TEMPLATE_STATIC(poly, is_degenerate)
 
#define POLY_TRI_COUNT(len)   ((len)-2)
 

Functions

static void polyfill_to_obj (const char *id, const float poly[][2], const unsigned int poly_num, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_valid_polyfill_prepare (unsigned int tris[][3], unsigned int tris_num)
 
static void test_polyfill_simple (const float[][2], const unsigned int poly_num, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_topology (const float[][2], const unsigned int poly_num, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_winding (const float poly[][2], const unsigned int, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_area (const float poly[][2], const unsigned int poly_num, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_template_check (const char *id, bool is_degenerate, const float poly[][2], const unsigned int poly_num, const unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_template (const char *id, bool is_degenerate, const float poly[][2], const unsigned int poly_num, unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_template_flip_sign (const char *id, bool is_degenerate, const float poly[][2], const unsigned int poly_num, unsigned int tris[][3], const unsigned int tris_num)
 
static void test_polyfill_template_main (const char *id, bool is_degenerate, const float poly[][2], const unsigned int poly_num, unsigned int tris[][3], const unsigned int tris_num)
 
 TEST (polyfill2d, TriangleCCW)
 
 TEST (polyfill2d, SquareCCW)
 
 TEST (polyfill2d, SquareCW)
 
 TEST (polyfill2d, Starfleet)
 
 TEST (polyfill2d, StarfleetDegenerate)
 
 TEST (polyfill2d, 3Colinear)
 
 TEST (polyfill2d, 4Colinear)
 
 TEST (polyfill2d, UnorderedColinear)
 
 TEST (polyfill2d, PlusShape)
 
 TEST (polyfill2d, StarShape)
 
 TEST (polyfill2d, UShape)
 
 TEST (polyfill2d, Spiral)
 
 TEST (polyfill2d, TestFlipCode)
 
 TEST (polyfill2d, SelfIntersect)
 
 TEST (polyfill2d, SelfTouch)
 
 TEST (polyfill2d, SelfOverlap)
 
 TEST (polyfill2d, TestDavData)
 
 TEST (polyfill2d, Issue815)
 
 TEST (polyfill2d, Issue207_1)
 
 TEST (polyfill2d, Issue207_11)
 
 TEST (polyfill2d, Issue1407)
 
 TEST (polyfill2d, Issue1407_pt)
 
 TEST (polyfill2d, IssueT40777_colinear)
 
 TEST (polyfill2d, IssueT41986_axis_align)
 
 TEST (polyfill2d, IssueT52834_axis_align_co_linear)
 
 TEST (polyfill2d, IssueT67109_axis_align_co_linear_a)
 
 TEST (polyfill2d, IssueT67109_axis_align_co_linear_b)
 
 TEST (polyfill2d, IssueT67109_axis_align_co_linear_c)
 

Macro Definition Documentation

◆ POLY_TRI_COUNT

#define POLY_TRI_COUNT (   len)    ((len)-2)

Script to generate the data below:

# This example assumes we have a mesh object in edit-mode
import bpy
import bmesh
obj = bpy.context.edit_object
me = obj.data
bm = bmesh.from_edit_mesh(me)
def clean_float(num):
if int(num) == num:
return str(int(num))
prec = 1
while True:
text = f"{num:.{prec}f}"
if float(text) == num:
return text
prec += 1
for f in bm.faces:
if f.select:
print(f"\t// data for face: {f.index}")
print("\tconst float poly[][2] = {", end="")
coords = [[clean_float(num) for num in l.vert.co[0:2]] for l in f.loops]
print("\t ", end="")
for i, (x, y) in enumerate(coords):
if (i % 2) == 0:
print("\n\t ", end="")
print(f"{{{x}, {y}}}", end=",")
print("\n\t};")
typedef float(TangentPoint)[2]
#define str(s)

Definition at line 377 of file BLI_polyfill_2d_test.cc.

◆ TEST_POLYFILL_TEMPLATE_STATIC

#define TEST_POLYFILL_TEMPLATE_STATIC (   poly,
  is_degenerate 
)
Value:
{ \
unsigned int tris[POLY_TRI_COUNT(ARRAY_SIZE(poly))][3]; \
const unsigned int poly_num = ARRAY_SIZE(poly); \
const unsigned int tris_num = ARRAY_SIZE(tris); \
const char *id = typeid(*this).name(); \
test_polyfill_template_main(id, is_degenerate, poly, poly_num, tris, tris_num); \
} \
(void)0
#define POLY_TRI_COUNT(len)
static void test_polyfill_template_main(const char *id, bool is_degenerate, const float poly[][2], const unsigned int poly_num, unsigned int tris[][3], const unsigned int tris_num)
#define ARRAY_SIZE(arr)
SyclQueue void void size_t num_bytes void

Definition at line 282 of file BLI_polyfill_2d_test.cc.

◆ TRI_ERROR_VALUE

#define TRI_ERROR_VALUE   (unsigned int)-1

Definition at line 39 of file BLI_polyfill_2d_test.cc.

◆ USE_BEAUTIFY

#define USE_BEAUTIFY

Definition at line 10 of file BLI_polyfill_2d_test.cc.

◆ USE_COMBINATIONS_ALL

#define USE_COMBINATIONS_ALL

Definition at line 9 of file BLI_polyfill_2d_test.cc.

Function Documentation

◆ polyfill_to_obj()

static void polyfill_to_obj ( const char *  id,
const float  poly[][2],
const unsigned int  poly_num,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

Definition at line 325 of file BLI_polyfill_2d_test.cc.

References void.

Referenced by test_polyfill_template_check().

◆ TEST() [1/28]

TEST ( polyfill2d  ,
3Colinear   
)

Definition at line 415 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [2/28]

TEST ( polyfill2d  ,
4Colinear   
)

Definition at line 422 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [3/28]

TEST ( polyfill2d  ,
Issue1407   
)

Definition at line 632 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [4/28]

TEST ( polyfill2d  ,
Issue1407_pt   
)

Definition at line 645 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [5/28]

TEST ( polyfill2d  ,
Issue207_1   
)

Definition at line 593 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [6/28]

TEST ( polyfill2d  ,
Issue207_11   
)

Definition at line 613 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [7/28]

TEST ( polyfill2d  ,
Issue815   
)

Definition at line 577 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [8/28]

TEST ( polyfill2d  ,
IssueT40777_colinear   
)

Definition at line 658 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [9/28]

TEST ( polyfill2d  ,
IssueT41986_axis_align   
)

Definition at line 669 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [10/28]

TEST ( polyfill2d  ,
IssueT52834_axis_align_co_linear   
)

Definition at line 684 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [11/28]

TEST ( polyfill2d  ,
IssueT67109_axis_align_co_linear_a   
)

Definition at line 700 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [12/28]

TEST ( polyfill2d  ,
IssueT67109_axis_align_co_linear_b   
)

Definition at line 718 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [13/28]

TEST ( polyfill2d  ,
IssueT67109_axis_align_co_linear_c   
)

Definition at line 736 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [14/28]

TEST ( polyfill2d  ,
PlusShape   
)

Definition at line 436 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [15/28]

TEST ( polyfill2d  ,
SelfIntersect   
)

Definition at line 518 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [16/28]

TEST ( polyfill2d  ,
SelfOverlap   
)

Definition at line 545 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [17/28]

TEST ( polyfill2d  ,
SelfTouch   
)

Definition at line 525 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [18/28]

TEST ( polyfill2d  ,
Spiral   
)

Definition at line 471 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [19/28]

TEST ( polyfill2d  ,
SquareCCW   
)

Definition at line 387 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [20/28]

TEST ( polyfill2d  ,
SquareCW   
)

Definition at line 394 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [21/28]

TEST ( polyfill2d  ,
Starfleet   
)

Definition at line 401 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [22/28]

TEST ( polyfill2d  ,
StarfleetDegenerate   
)

Definition at line 408 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [23/28]

TEST ( polyfill2d  ,
StarShape   
)

Definition at line 456 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [24/28]

TEST ( polyfill2d  ,
TestDavData   
)

Definition at line 565 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [25/28]

TEST ( polyfill2d  ,
TestFlipCode   
)

Definition at line 495 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [26/28]

TEST ( polyfill2d  ,
TriangleCCW   
)

Definition at line 380 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [27/28]

TEST ( polyfill2d  ,
UnorderedColinear   
)

Definition at line 429 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ TEST() [28/28]

TEST ( polyfill2d  ,
UShape   
)

Definition at line 463 of file BLI_polyfill_2d_test.cc.

References TEST_POLYFILL_TEMPLATE_STATIC.

◆ test_polyfill_area()

static void test_polyfill_area ( const float  poly[][2],
const unsigned int  poly_num,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

Check the accumulated triangle area is close to the original area.

Definition at line 146 of file BLI_polyfill_2d_test.cc.

References area_poly_v2(), area_tri_v2(), and eps.

Referenced by test_polyfill_template_check().

◆ test_polyfill_simple()

static void test_polyfill_simple ( const float  [][2],
const unsigned int  poly_num,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

Basic check for face index values:

  • no duplicates.
  • all tris set.
  • all verts used at least once.

Definition at line 59 of file BLI_polyfill_2d_test.cc.

References MEM_callocN, MEM_freeN, and TRI_ERROR_VALUE.

Referenced by test_polyfill_template_check().

◆ test_polyfill_template()

static void test_polyfill_template ( const char *  id,
bool  is_degenerate,
const float  poly[][2],
const unsigned int  poly_num,
unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

◆ test_polyfill_template_check()

static void test_polyfill_template_check ( const char *  id,
bool  is_degenerate,
const float  poly[][2],
const unsigned int  poly_num,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

◆ test_polyfill_template_flip_sign()

static void test_polyfill_template_flip_sign ( const char *  id,
bool  is_degenerate,
const float  poly[][2],
const unsigned int  poly_num,
unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

Definition at line 213 of file BLI_polyfill_2d_test.cc.

References float(), id, MEM_freeN, MEM_mallocN, and test_polyfill_template().

Referenced by test_polyfill_template_main().

◆ test_polyfill_template_main()

static void test_polyfill_template_main ( const char *  id,
bool  is_degenerate,
const float  poly[][2],
const unsigned int  poly_num,
unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

◆ test_polyfill_topology()

static void test_polyfill_topology ( const float  [][2],
const unsigned int  poly_num,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

◆ test_polyfill_winding()

static void test_polyfill_winding ( const float  poly[][2],
const unsigned int  ,
const unsigned int  tris[][3],
const unsigned int  tris_num 
)
static

Check all faces are flipped the same way

Definition at line 127 of file BLI_polyfill_2d_test.cc.

References count, cross_tri_v2(), ELEM, and fabsf.

Referenced by test_polyfill_template_check().

◆ test_valid_polyfill_prepare()

static void test_valid_polyfill_prepare ( unsigned int  tris[][3],
unsigned int  tris_num 
)
static

Definition at line 41 of file BLI_polyfill_2d_test.cc.

References TRI_ERROR_VALUE.

Referenced by test_polyfill_template().