Improved solid selection stability
authorhgn <hgodden00@gmail.com>
Fri, 8 Apr 2022 18:57:17 +0000 (19:57 +0100)
committerhgn <hgodden00@gmail.com>
Fri, 8 Apr 2022 18:57:17 +0000 (19:57 +0100)
src/convexer.c
src/cxr_math.h
src/solid.h [deleted file]

index adcaf6007a2ae626a9b8d94b9bd9e52ce4523673..5fac72984d2f489a9aefdc7632d39e8c0489871e 100644 (file)
@@ -59,7 +59,7 @@ typedef v3f                   m4x3f[4];
 typedef v3f                    boxf[2];
 
 #define CXR_EPSILON 0.001
-#define CXR_PLANE_SIMILARITY_MAX 0.999
+#define CXR_PLANE_SIMILARITY_MAX 0.998
 #define CXR_BIG_NUMBER 1e300
 #define CXR_INTERIOR_ANGLE_MAX 0.998
 #define CXR_API 
@@ -799,7 +799,7 @@ static struct cxr_mesh *cxr_pull_best_solid(
       for( int j=0; j<polya->loop_total; j++ )
       {
          struct cxr_loop *loop = cxr_ab_ptr(&mesh->loops, polya->loop_start+j);
-         if( plane_polarity( planeb, vertices[loop->index] ) > 0.000025 ||
+         if( plane_polarity( planeb, vertices[loop->index] ) > 0.001 ||
              v3_dot(polya->normal,polyb->normal) > CXR_PLANE_SIMILARITY_MAX )
          {
             edge_tagged[i] = 1;
@@ -912,8 +912,8 @@ IL_TAG_NEXT_VERT:;
          edge_tagged[i] = 1;
    }
 
-   /* Debug stuff -- 
-   for( int i=0; i<vertex_count; i++ )
+   
+   for( int i=0; i<vert_buffer->count; i++ )
       if( vertex_tagged[i] )
          cxr_debug_box( vertices[i], 0.03, (v4f){0.0,0.0,0.0,1.0});
 
@@ -926,7 +926,7 @@ IL_TAG_NEXT_VERT:;
       if( hot_edge[i] )
          cxr_debug_line( vertices[ edge->i0 ], vertices[ edge->i1 ], (v4f){0.0,1.0,1.0,1.0});
    }
-   */
+   
 
    // count regions
    int *faces_tagged = malloc(mesh->polys.count*sizeof(int));
@@ -942,6 +942,12 @@ IL_TAG_NEXT_VERT:;
    }
    *candidates = malloc( mesh->polys.count *sizeof(struct csolid) );
    int candidate_count = 0;
+   
+   struct tedge
+   {
+      int i0, i1;
+   } 
+   *edge_references = malloc( mesh->edges.count *sizeof(struct tedge) );
 
    for( int i=0; i<mesh->polys.count; i++ )
    {
@@ -975,11 +981,15 @@ IL_TAG_NEXT_VERT:;
             {
                if( !edge_tagged[loop->edge_index] )
                {
+                  // TODO(harry):
+                  // 
                   // Need to look ahead 1 step to make sure he does not want
                   // to add any more planes that are coplanar with some of 
                   // our existing group
                   //
-                  // TODO: is this unused due to hotedge improvements? leaving for safety...
+                  // This can sort out SOME invalid configs, but not all.
+                  // It would be nice to find a more robust clustering algorithm for this.
+                  //
 
                   struct cxr_polygon *poly_to_add = cxr_ab_ptr(&mesh->polys, loop->poly_right );
                   for( int l=0; l < poly_to_add->loop_total; l++ )
@@ -1004,8 +1014,6 @@ IL_TAG_NEXT_VERT:;
                      IL_SKIP_SIMILAR_PLANES:;
                   }
 
-                  // This plane passed all checks so we can add it to the current solid
-
                   solid[ solid_len ++ ] = loop->poly_right;
                   faces_tagged[ loop->poly_right ] = i;
                   changed = 1;
@@ -1019,6 +1027,25 @@ IL_TAG_NEXT_VERT:;
       if(changed) 
          goto IL_SEARCH_CONTINUE;
 
+      // The current method can create some invalid configurations
+      // filter those out that dont work and un-tag the faces
+      for( int j=0; j<solid_len-1; j++ )
+      {
+         for( int k=j+1; k<solid_len; k++ )
+         {
+            struct cxr_polygon *polyj = cxr_ab_ptr(&mesh->polys, solid[j]),
+                               *polyk = cxr_ab_ptr(&mesh->polys, solid[k]);
+            
+            if( v3_dot( polyj->normal, polyk->normal ) > CXR_PLANE_SIMILARITY_MAX )
+            {
+               for( int l=0; l<solid_len; l++ )
+                  faces_tagged[ solid[l] ] = -1;
+
+               goto IL_CANCEL_SOLID;
+            }
+         }
+      }
+
       // Add entry
       struct csolid *csolid = &candidates[candidate_count ++];
       csolid->start = solid_buffer_len;
@@ -1035,8 +1062,12 @@ IL_TAG_NEXT_VERT:;
       v3_divs( csolid->center, solid_len, csolid->center );
 
       solid_buffer_len += solid_len;
+
+      IL_CANCEL_SOLID:;
    }
 
+   free( edge_references );
+
    // Create all candidates who have one or less non-manifolds edges
    //   Loop each candidate, determine the manifold, and pick the best one
 
@@ -1269,13 +1300,6 @@ IL_TAG_NEXT_VERT:;
 
          exist_face->loop_total = -1;
       }
-
-      // Split manifold up by unique planes if it has more than 1
-      // otherwise, just use that face
-      //
-      // TODO: Need to build new manifold in sections, stably
-      //       currently there is an unsupported case where the manifold splits
-      //       are on located on an implicit face, causing 1-length manifolds.
       
       int new_polys = 0;
       int pullmesh_new_start = pullmesh->polys.count;
@@ -1301,7 +1325,7 @@ IL_TAG_NEXT_VERT:;
          // When it is even, it appears that internal implicit geometry is required, so we
          // need to fold the loops we create. Its really weird, but for some reason works on 
          // the geometry rules we've defined.
-         //   TODO: Find a well defined rule here.
+         //   TODO(harry): Find a well defined rule here.
 
          int collapse_used_segments = (u32)fewest_manifold_splits & 0x1? 0: 1;
 
@@ -1755,9 +1779,6 @@ CXR_API struct cxr_input_mesh *cxr_decompose(struct cxr_input_mesh *src)
    struct cxr_auto_buffer solids;
    cxr_ab_init( &solids, sizeof(struct cxr_mesh *), 2 );
 
-   // TODO: Preprocessor stages
-   //  - Split mesh up into islands before doing anything here
-   //  - Snap vertices to grid (0.25u) ?
    while(1)
    {
       struct cxr_mesh *res = cxr_pull_best_solid( main_mesh, &abverts, 0, &error );
@@ -1896,9 +1917,10 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme
       v3_add( poly->normal, avg_normal, avg_normal );
    }
    v3_divs( avg_normal, mesh->polys.count, avg_normal );
-   v3_normalize( avg_normal );   // TODO: This can be zero length. Should add a safety check
+   v3_normalize( avg_normal );   // TODO(harry): This can be zero length. Should add a safety check
                                  // normalize function that checks for small length before
                                  // carrying out, otherwise we get inf/nan values...
+
    int n_cardinal = cxr_cardinal( avg_normal, -1 );
 
    // Approximately matching the area of the result brush faces to the actual area
@@ -1983,6 +2005,9 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme
       }
    }
    
+   // TODO(harry): This currently only supports power 2 displacements
+   //              its quite straightforward to upgrade it.
+   //
    int dispedge[16];
    v2f corner_uvs[4];
    int dispedge_count;
@@ -2172,7 +2197,7 @@ static void cxr_write_disp(struct cxr_mesh *mesh, struct cxr_input_mesh *inputme
             // Create brush vertices based on UV map
             
             // Create V reference based on first displacement.
-            // TODO: This is not the moststable selection method!
+            // TODO(harry): This is not the moststable selection method!
             //       faces can come in any order, so the first disp will of course
             //       always vary. Additionaly the triangle can be oriented differently.
             //
@@ -2513,6 +2538,44 @@ IL_DISP_ERROR_COUNT:
    free( vertinfo );
 }
 
+static int cxr_solid_checkerr(struct cxr_mesh *mesh, struct cxr_auto_buffer *abverts )
+{
+   int err_count = 0;
+
+   for( int i=0; i<mesh->polys.count; i++ )
+   {
+      int plane_err = 0;
+
+      struct cxr_polygon *poly = cxr_ab_ptr(&mesh->polys,i);
+      v4f plane;
+
+      normal_to_plane( poly->normal, poly->center, plane );
+      
+      for( int j=0; j<poly->loop_total; j++ )
+      {
+         struct cxr_loop *loop = cxr_ab_ptr(&mesh->loops, poly->loop_start+j);
+         double *vert = cxr_ab_ptr(abverts,loop->index);
+
+         if( fabs(plane_polarity(plane,vert)) > 0.0025 )
+         {
+            err_count ++;
+            plane_err ++;
+
+            v3f ref;
+            plane_project_point( plane, vert, ref );
+
+            cxr_debug_line( ref, vert, colour_error );
+            cxr_debug_box( vert, 0.1, colour_error );
+         }
+      }
+
+      if( plane_err )
+         cxr_debug_poly( mesh, poly, cxr_ab_ptr(abverts,0), colour_error );
+   }
+   
+   return err_count;
+}
+
 CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *output)
 {
    // Split mesh into islands
@@ -2520,20 +2583,17 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *
    struct cxr_mesh *main_mesh = cxr_to_internal_format(src, &abverts);
 
    u32 error = 0x00;
+   int invalid_count = 0;
 
    struct solidinf
    {
       struct cxr_mesh *pmesh;
-      int is_displacement;
+      int is_displacement, invalid;
    };
 
    struct cxr_auto_buffer solids;
    cxr_ab_init( &solids, sizeof(struct solidinf), 2 );
 
-   // TODO: Preprocessor stages
-   //  - Split mesh up into islands before doing anything here    (DONE)
-   //  - Snap vertices to grid (0.25u)                            ?
-   
    // Preprocessor 1: Island seperation
    //  ---------------
 
@@ -2548,7 +2608,7 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *
    }
    cxr_ab_push( &solids, &(struct solidinf){main_mesh,0} );
    
-   // Preprocessor 2: Displacement break-out
+   // Preprocessor 2: Displacement break-out and error checking
    //  ---------------
    for( int i=0; i<solids.count; i++ )
    {
@@ -2568,6 +2628,12 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *
          }
       }
       
+      if( cxr_solid_checkerr( pinf->pmesh, &abverts ) )
+      {
+         pinf->invalid = 1;
+         invalid_count ++;
+      }
+
       continue;
       IL_SOLID_IS_DISPLACEMENT:;
       
@@ -2583,7 +2649,7 @@ CXR_API i32 cxr_convert_mesh_to_vmf(struct cxr_input_mesh *src, struct cxr_vdf *
    {
       struct solidinf pinf = *(struct solidinf *)cxr_ab_ptr(&solids, i);
 
-      if( pinf.is_displacement )
+      if( pinf.is_displacement || pinf.invalid )
          continue;
 
       while(1)
index d03d8862cd68eeb241a0c5bf51709dd05f8fbee6..17c9902b390e3539a8a46af711f4d601727288a8 100644 (file)
@@ -576,3 +576,12 @@ CXR_INLINE double plane_polarity( double p[4], double a[3] )
        -(p[0]*p[3] * p[0] + p[1]*p[3] * p[1] + p[2]*p[3] * p[2])
        ;
 }
+
+CXR_INLINE void plane_project_point( v4f plane, v3f a, v3f d )
+{
+   v3f ref, delta;
+   v3_muls( plane, plane[3], ref );
+
+   v3_sub( a, ref, delta );
+   v3_muladds( a, plane, -v3_dot(delta,plane), d );
+}
diff --git a/src/solid.h b/src/solid.h
deleted file mode 100644 (file)
index f8a0f89..0000000
+++ /dev/null
@@ -1,772 +0,0 @@
-v3f test_verts[] = {
-   { 11.185741, 0.535051, -2.047508 },
-   { 27.185741, 0.535051, -2.047508 },
-   { 11.185741, 16.535051, -2.047508 },
-   { 27.185741, 16.535051, -2.047508 },
-   { 11.185741, 13.335052, -2.047508 },
-   { 11.185741, 10.135052, -2.047508 },
-   { 11.185741, 6.935051, -2.047508 },
-   { 11.185741, 3.735051, -2.047508 },
-   { 26.086811, 3.735051, -2.047508 },
-   { 27.185741, 6.935051, -2.047508 },
-   { 27.185741, 10.135052, -2.047508 },
-   { 27.185741, 13.335052, -2.047508 },
-   { 14.385741, 0.535051, -2.047508 },
-   { 17.585741, 0.535051, -2.047508 },
-   { 20.785742, 0.535051, -2.047508 },
-   { 20.785742, 16.535051, -2.047508 },
-   { 17.585741, 16.535051, -2.047508 },
-   { 14.385741, 16.535051, -2.047508 },
-   { 20.785742, 3.108177, -2.047508 },
-   { 17.585741, 3.735051, -2.047508 },
-   { 14.385741, 3.735051, -2.047508 },
-   { 20.785742, 6.935051, -2.047508 },
-   { 17.585741, 6.935051, -2.047508 },
-   { 14.385741, 6.935051, -2.047508 },
-   { 20.785742, 10.135052, -2.047508 },
-   { 17.585741, 10.135052, -2.047508 },
-   { 14.385741, 10.135052, -2.047508 },
-   { 20.785742, 13.335052, -2.047508 },
-   { 17.585741, 13.335052, -2.047508 },
-   { 14.385741, 13.335052, -2.047508 },
-   { 11.185741, 13.335052, 1.606183 },
-   { 27.185741, 6.935051, 0.909645 },
-   { 20.785742, 0.535051, 0.909645 },
-   { 11.185741, 16.535051, -0.552386 },
-   { 11.185741, 3.735051, 0.909645 },
-   { 27.185741, 0.535051, 0.909645 },
-   { 27.185741, 13.335052, 1.606183 },
-   { 20.785742, 16.535051, -0.552386 },
-   { 11.185741, 10.135052, 0.909645 },
-   { 17.585741, 0.535051, 0.909645 },
-   { 27.185741, 10.135052, 0.909645 },
-   { 17.585741, 16.535051, -0.552386 },
-   { 14.385741, 16.535051, -0.552386 },
-   { 27.185741, 16.535051, -0.552386 },
-   { 11.185741, 6.935051, 0.909645 },
-   { 26.086811, 3.735051, 0.909645 },
-   { 11.185741, 0.535051, 0.909645 },
-   { 14.385741, 0.535051, 0.909645 },
-   { 27.185741, 13.335052, 6.787578 },
-   { 27.185741, 16.535051, 6.787578 },
-   { 14.385741, 0.535051, 6.787578 },
-   { 14.385741, 3.735051, 6.787578 },
-   { 17.585741, 13.335052, 6.787578 },
-   { 17.585741, 16.535051, 6.787578 },
-   { 20.785742, 16.535051, 6.787578 },
-   { 11.185741, 16.535051, 6.787578 },
-   { 11.185741, 13.335052, 6.787578 },
-   { 11.185741, 3.735051, 6.787578 },
-   { 17.585741, 0.535051, 6.787578 },
-   { 20.785742, 0.535051, 6.787578 },
-   { 20.785742, 13.335052, 6.787578 },
-   { 20.785742, 3.108177, 6.787578 },
-   { 11.185741, 0.535051, 6.787578 },
-   { 14.385741, 6.935051, 6.787578 },
-   { 14.385741, 10.135052, 6.787578 },
-   { 17.585741, 6.935051, 6.787578 },
-   { 17.585741, 10.135052, 6.787578 },
-   { 14.385741, 16.535051, 6.787578 },
-   { 26.086811, 3.735051, 6.787578 },
-   { 27.185741, 6.935051, 6.787578 },
-   { 11.185741, 10.135052, 6.787578 },
-   { 27.185741, 10.135052, 6.787578 },
-   { 11.185741, 6.935051, 6.787578 },
-   { 20.785742, 10.135052, 6.787578 },
-   { 20.785742, 6.935051, 6.787578 },
-   { 17.585741, 3.735051, 6.787578 },
-   { 14.385741, 13.335052, 6.787578 },
-   { 27.185741, 0.535051, 6.787578 },
-   { 11.185741, 16.535051, 3.438894 },
-   { 27.185741, 0.535051, 3.438894 },
-   { 11.185741, 10.135052, 3.438894 },
-   { 17.585741, 16.535051, 3.438894 },
-   { 14.385741, 16.535051, 3.438894 },
-   { 27.185741, 16.535051, 3.438894 },
-   { 14.385741, 0.535051, 3.438894 },
-   { 11.185741, 13.335052, 3.438894 },
-   { 27.185741, 6.935051, 3.438894 },
-   { 20.785742, 0.535051, 3.438894 },
-   { 11.185741, 3.735051, 3.438894 },
-   { 27.185741, 13.335052, 3.438894 },
-   { 20.785742, 16.535051, 3.438894 },
-   { 17.585741, 0.535051, 3.438894 },
-   { 27.185741, 10.135052, 3.438894 },
-   { 11.185741, 6.935051, 3.438894 },
-   { 26.086811, 3.735051, 3.438894 },
-   { 11.185741, 0.535051, 3.438894 },
-};
-struct cxr_input_loop test_loops[] = {
-   {50, 142},
-   {58, 128},
-   {75, 127},
-   {51, 104},
-   {65, 125},
-   {74, 126},
-   {73, 141},
-   {66, 114},
-   {73, 124},
-   {71, 120},
-   {48, 132},
-   {60, 133},
-   {70, 118},
-   {64, 131},
-   {76, 146},
-   {56, 119},
-   {24, 17},
-   {27, 39},
-   {11, 4},
-   {10, 48},
-   {13, 58},
-   {39, 101},
-   {47, 84},
-   {12, 11},
-   {81, 171},
-   {90, 74},
-   {37, 89},
-   {41, 155},
-   {52, 122},
-   {60, 110},
-   {54, 106},
-   {53, 105},
-   {91, 165},
-   {58, 142},
-   {50, 66},
-   {84, 182},
-   {4, 49},
-   {30, 94},
-   {33, 70},
-   {2, 18},
-   {59, 136},
-   {77, 137},
-   {68, 147},
-   {61, 111},
-   {29, 23},
-   {17, 41},
-   {16, 16},
-   {28, 3},
-   {28, 16},
-   {16, 15},
-   {15, 1},
-   {27, 29},
-   {1, 72},
-   {35, 92},
-   {32, 51},
-   {14, 43},
-   {31, 50},
-   {9, 14},
-   {10, 59},
-   {40, 87},
-   {33, 152},
-   {78, 179},
-   {82, 156},
-   {42, 86},
-   {11, 55},
-   {36, 98},
-   {40, 59},
-   {10, 4},
-   {57, 108},
-   {51, 129},
-   {63, 150},
-   {72, 149},
-   {21, 9},
-   {24, 48},
-   {10, 14},
-   {9, 13},
-   {14, 7},
-   {18, 34},
-   {8, 44},
-   {1, 43},
-   {4, 18},
-   {2, 21},
-   {17, 23},
-   {29, 2},
-   {1, 44},
-   {8, 64},
-   {45, 85},
-   {35, 72},
-   {17, 79},
-   {42, 90},
-   {41, 78},
-   {16, 41},
-   {54, 117},
-   {49, 62},
-   {83, 176},
-   {90, 164},
-   {62, 169},
-   {95, 187},
-   {84, 66},
-   {50, 139},
-   {46, 83},
-   {95, 180},
-   {88, 71},
-   {34, 99},
-   {82, 173},
-   {81, 155},
-   {41, 90},
-   {42, 156},
-   {8, 12},
-   {9, 50},
-   {31, 96},
-   {45, 64},
-   {23, 25},
-   {26, 33},
-   {25, 31},
-   {22, 46},
-   {67, 115},
-   {53, 60},
-   {81, 173},
-   {82, 61},
-   {7, 53},
-   {34, 102},
-   {44, 63},
-   {6, 0},
-   {41, 89},
-   {37, 56},
-   {15, 15},
-   {16, 78},
-   {79, 185},
-   {87, 69},
-   {32, 92},
-   {35, 153},
-   {6, 42},
-   {5, 20},
-   {26, 25},
-   {23, 28},
-   {89, 186},
-   {92, 77},
-   {40, 98},
-   {36, 73},
-   {95, 169},
-   {62, 112},
-   {57, 162},
-   {88, 180},
-   {69, 116},
-   {68, 168},
-   {94, 184},
-   {86, 160},
-   {34, 71},
-   {88, 181},
-   {93, 81},
-   {44, 102},
-   {0, 6},
-   {7, 5},
-   {20, 22},
-   {12, 32},
-   {62, 139},
-   {50, 104},
-   {51, 108},
-   {57, 112},
-   {88, 162},
-   {57, 149},
-   {72, 167},
-   {93, 181},
-   {18, 8},
-   {21, 13},
-   {9, 12},
-   {8, 34},
-   {47, 95},
-   {46, 65},
-   {0, 32},
-   {12, 84},
-   {77, 136},
-   {59, 161},
-   {87, 185},
-   {79, 54},
-   {90, 176},
-   {83, 157},
-   {43, 88},
-   {37, 74},
-   {53, 106},
-   {54, 164},
-   {90, 171},
-   {81, 60},
-   {76, 138},
-   {52, 105},
-   {53, 115},
-   {67, 144},
-   {30, 67},
-   {85, 172},
-   {78, 152},
-   {33, 94},
-   {75, 130},
-   {61, 134},
-   {74, 125},
-   {65, 151},
-   {94, 175},
-   {79, 153},
-   {35, 85},
-   {45, 82},
-   {63, 140},
-   {65, 114},
-   {66, 145},
-   {64, 113},
-   {95, 83},
-   {46, 95},
-   {47, 158},
-   {84, 187},
-   {78, 52},
-   {55, 143},
-   {67, 61},
-   {82, 179},
-   {70, 119},
-   {56, 159},
-   {85, 183},
-   {80, 57},
-   {39, 76},
-   {91, 182},
-   {84, 158},
-   {47, 101},
-   {64, 145},
-   {66, 148},
-   {52, 138},
-   {76, 131},
-   {80, 183},
-   {85, 67},
-   {30, 97},
-   {38, 154},
-   {15, 56},
-   {37, 88},
-   {43, 80},
-   {3, 19},
-   {89, 170},
-   {83, 62},
-   {49, 103},
-   {48, 163},
-   {0, 65},
-   {46, 99},
-   {34, 53},
-   {7, 6},
-   {5, 75},
-   {38, 97},
-   {30, 49},
-   {4, 10},
-   {68, 137},
-   {77, 54},
-   {79, 175},
-   {94, 168},
-   {19, 40},
-   {22, 36},
-   {21, 8},
-   {18, 24},
-   {14, 51},
-   {32, 93},
-   {39, 58},
-   {13, 45},
-   {66, 141},
-   {73, 133},
-   {60, 122},
-   {52, 148},
-   {32, 69},
-   {87, 174},
-   {91, 76},
-   {39, 93},
-   {61, 147},
-   {68, 116},
-   {69, 135},
-   {74, 134},
-   {38, 91},
-   {44, 81},
-   {93, 178},
-   {80, 154},
-   {48, 120},
-   {71, 166},
-   {92, 186},
-   {89, 163},
-   {12, 22},
-   {20, 27},
-   {19, 37},
-   {13, 11},
-   {20, 47},
-   {23, 46},
-   {22, 40},
-   {19, 27},
-   {5, 42},
-   {6, 63},
-   {44, 91},
-   {38, 75},
-   {87, 161},
-   {59, 109},
-   {58, 165},
-   {91, 174},
-   {22, 31},
-   {25, 38},
-   {24, 9},
-   {21, 36},
-   {13, 37},
-   {19, 24},
-   {18, 7},
-   {14, 45},
-   {86, 184},
-   {94, 82},
-   {45, 96},
-   {31, 68},
-   {5, 10},
-   {4, 2},
-   {29, 35},
-   {26, 20},
-   {11, 26},
-   {3, 80},
-   {43, 100},
-   {36, 55},
-   {2, 70},
-   {33, 86},
-   {42, 79},
-   {17, 21},
-   {7, 0},
-   {6, 28},
-   {23, 47},
-   {20, 5},
-   {36, 100},
-   {43, 157},
-   {83, 170},
-   {89, 73},
-   {26, 35},
-   {29, 3},
-   {28, 30},
-   {25, 33},
-   {58, 109},
-   {59, 111},
-   {61, 130},
-   {75, 128},
-   {92, 177},
-   {86, 68},
-   {31, 87},
-   {40, 77},
-   {80, 178},
-   {93, 167},
-   {72, 121},
-   {70, 57},
-   {25, 30},
-   {28, 29},
-   {27, 17},
-   {24, 38},
-   {60, 132},
-   {48, 103},
-   {49, 117},
-   {54, 110},
-   {51, 127},
-   {75, 151},
-   {65, 140},
-   {63, 129},
-   {74, 135},
-   {69, 123},
-   {71, 124},
-   {73, 126},
-   {72, 150},
-   {63, 113},
-   {64, 118},
-   {70, 121},
-   {85, 159},
-   {56, 107},
-   {55, 52},
-   {78, 172},
-   {71, 123},
-   {69, 160},
-   {86, 177},
-   {92, 166},
-   {27, 1},
-   {15, 19},
-   {3, 26},
-   {11, 39},
-   {56, 146},
-   {76, 144},
-   {67, 143},
-   {55, 107},
-};
-struct cxr_polygon test_polys[] = {
-   {0, 4, {0.000000, 0.000000, 1.000000}, {15.985741, 2.135051, 6.787578}},
-   {4, 4, {0.000000, 0.000000, 1.000000}, {19.185741, 8.535051, 6.787578}},
-   {8, 4, {0.000000, 0.000000, 1.000000}, {23.985743, 11.735052, 6.787578}},
-   {12, 4, {0.000000, 0.000000, 1.000000}, {12.785742, 11.735052, 6.787578}},
-   {16, 4, {-0.000000, 0.000000, -1.000000}, {23.985741, 11.735052, -2.047508}},
-   {20, 4, {0.000000, -1.000000, 0.000000}, {15.985742, 0.535051, -0.568931}},
-   {24, 4, {0.000000, 1.000000, 0.000000}, {19.185741, 16.535051, 1.443254}},
-   {28, 4, {0.000000, 0.000000, 1.000000}, {19.185741, 14.935051, 6.787578}},
-   {32, 4, {0.000000, -1.000000, 0.000000}, {15.985742, 0.535051, 5.113236}},
-   {36, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 14.935051, -0.760305}},
-   {40, 4, {0.000000, 0.000000, 1.000000}, {23.711008, 1.978333, 6.787578}},
-   {44, 4, {-0.000000, 0.000000, -1.000000}, {15.985741, 14.935051, -2.047508}},
-   {48, 4, {-0.000000, 0.000000, -1.000000}, {19.185741, 14.935051, -2.047508}},
-   {52, 4, {0.000000, -1.000000, 0.000000}, {23.985743, 0.535051, -0.568931}},
-   {56, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 8.535051, -0.568931}},
-   {60, 4, {0.000000, 1.000000, 0.000000}, {12.785742, 16.535051, 1.443254}},
-   {64, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 11.735051, -0.394797}},
-   {68, 4, {0.000000, 0.000000, 1.000000}, {12.785742, 5.335051, 6.787578}},
-   {72, 4, {-0.000000, 0.000000, -1.000000}, {23.985741, 8.535051, -2.047508}},
-   {76, 4, {-0.000000, 0.000000, -1.000000}, {23.711010, 1.978333, -2.047508}},
-   {80, 4, {-0.000000, 0.000000, -1.000000}, {12.785742, 14.935051, -2.047508}},
-   {84, 4, {0.945784, 0.324797, 0.000000}, {26.636276, 2.135051, -0.568931}},
-   {88, 4, {0.000000, 1.000000, 0.000000}, {15.985741, 16.535051, -1.299947}},
-   {92, 4, {0.000000, 1.000000, 0.000000}, {23.985743, 16.535051, 5.113236}},
-   {96, 4, {0.000000, -1.000000, 0.000000}, {12.785742, 0.535051, 5.113235}},
-   {100, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 2.135051, 2.174269}},
-   {104, 4, {0.000000, 1.000000, 0.000000}, {15.985741, 16.535051, 1.443254}},
-   {108, 4, {0.945784, -0.324797, 0.000000}, {26.636276, 5.335051, -0.568931}},
-   {112, 4, {-0.000000, 0.000000, -1.000000}, {15.985741, 8.535051, -2.047508}},
-   {116, 4, {0.000000, 1.000000, 0.000000}, {15.985741, 16.535051, 5.113236}},
-   {120, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 5.335051, -0.568931}},
-   {124, 4, {0.000000, 1.000000, 0.000000}, {19.185741, 16.535051, -1.299947}},
-   {128, 4, {0.000000, -1.000000, 0.000000}, {23.985741, 0.535051, 2.174269}},
-   {132, 4, {-0.000000, 0.000000, -1.000000}, {12.785742, 8.535051, -2.047508}},
-   {136, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 11.735052, 2.348404}},
-   {140, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 2.135051, 5.113236}},
-   {144, 4, {0.945784, -0.324797, 0.000000}, {26.636276, 5.335051, 5.113236}},
-   {148, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 5.335051, 2.174269}},
-   {152, 4, {-0.000000, 0.000000, -1.000000}, {12.785742, 2.135051, -2.047508}},
-   {156, 4, {0.000000, 0.000000, 1.000000}, {12.785742, 2.135051, 6.787578}},
-   {160, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 5.335051, 5.113236}},
-   {164, 4, {-0.000000, 0.000000, -1.000000}, {23.711010, 5.178332, -2.047508}},
-   {168, 4, {0.000000, -1.000000, 0.000000}, {12.785742, 0.535051, -0.568931}},
-   {172, 4, {0.000000, -1.000000, 0.000000}, {23.985741, 0.535051, 5.113236}},
-   {176, 4, {0.000000, 1.000000, 0.000000}, {23.985743, 16.535051, 1.443254}},
-   {180, 4, {0.000000, 1.000000, 0.000000}, {19.185741, 16.535051, 5.113236}},
-   {184, 4, {0.000000, 0.000000, 1.000000}, {15.985741, 14.935051, 6.787578}},
-   {188, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 14.935051, 1.982896}},
-   {192, 4, {0.000000, 0.000000, 1.000000}, {19.185741, 5.178332, 6.787578}},
-   {196, 4, {0.945784, 0.324797, 0.000000}, {26.636276, 2.135051, 2.174269}},
-   {200, 4, {0.000000, 0.000000, 1.000000}, {15.985741, 8.535051, 6.787578}},
-   {204, 4, {0.000000, -1.000000, 0.000000}, {12.785742, 0.535051, 2.174269}},
-   {208, 4, {0.000000, 1.000000, 0.000000}, {12.785742, 16.535051, 5.113236}},
-   {212, 4, {-1.000000, 0.000000, 0.000000}, {11.185741, 11.735052, 5.113236}},
-   {216, 4, {0.000000, -1.000000, 0.000000}, {15.985742, 0.535051, 2.174269}},
-   {220, 4, {0.000000, 0.000000, 1.000000}, {15.985741, 11.735052, 6.787578}},
-   {224, 4, {-1.000000, 0.000000, 0.000000}, {11.185741, 11.735052, 2.348404}},
-   {228, 4, {0.000000, 1.000000, 0.000000}, {23.985741, 16.535051, -1.299947}},
-   {232, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 14.935051, 5.113235}},
-   {236, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 2.135051, -0.568931}},
-   {240, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 11.735052, -0.394797}},
-   {244, 4, {0.945784, 0.324797, 0.000000}, {26.636276, 2.135051, 5.113236}},
-   {248, 4, {-0.000000, 0.000000, -1.000000}, {19.185741, 5.178332, -2.047508}},
-   {252, 4, {0.000000, -1.000000, 0.000000}, {19.185741, 0.535051, -0.568931}},
-   {256, 4, {0.000000, 0.000000, 1.000000}, {19.185741, 11.735052, 6.787578}},
-   {260, 4, {0.000000, -1.000000, 0.000000}, {19.185741, 0.535051, 2.174269}},
-   {264, 4, {0.000000, 0.000000, 1.000000}, {23.711008, 5.178332, 6.787578}},
-   {268, 4, {-1.000000, 0.000000, 0.000000}, {11.185741, 8.535051, 2.174269}},
-   {272, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 11.735052, 5.113236}},
-   {276, 4, {-0.000000, 0.000000, -1.000000}, {15.985741, 2.135051, -2.047508}},
-   {280, 4, {-0.000000, 0.000000, -1.000000}, {15.985741, 5.335051, -2.047508}},
-   {284, 4, {-1.000000, 0.000000, 0.000000}, {11.185741, 8.535051, -0.568931}},
-   {288, 4, {0.000000, -1.000000, 0.000000}, {19.185741, 0.535051, 5.113236}},
-   {292, 4, {-0.000000, 0.000000, -1.000000}, {19.185741, 8.535051, -2.047508}},
-   {296, 4, {-0.000000, 0.000000, -1.000000}, {19.185741, 1.978333, -2.047508}},
-   {300, 4, {0.945784, -0.324797, 0.000000}, {26.636276, 5.335051, 2.174269}},
-   {304, 4, {-0.000000, 0.000000, -1.000000}, {12.785742, 11.735052, -2.047508}},
-   {308, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 14.935051, -0.760305}},
-   {312, 4, {0.000000, 1.000000, 0.000000}, {12.785742, 16.535051, -1.299947}},
-   {316, 4, {-0.000000, 0.000000, -1.000000}, {12.785742, 5.335051, -2.047508}},
-   {320, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 14.935051, 1.982896}},
-   {324, 4, {-0.000000, 0.000000, -1.000000}, {15.985741, 11.735052, -2.047508}},
-   {328, 4, {0.000000, 0.000000, 1.000000}, {19.185741, 1.978333, 6.787578}},
-   {332, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 8.535051, 2.174269}},
-   {336, 4, {-1.000000, 0.000000, 0.000000}, {11.185741, 8.535051, 5.113235}},
-   {340, 4, {-0.000000, 0.000000, -1.000000}, {19.185741, 11.735052, -2.047508}},
-   {344, 4, {0.000000, 0.000000, 1.000000}, {23.985743, 14.935051, 6.787578}},
-   {348, 4, {0.000000, 0.000000, 1.000000}, {15.985741, 5.335051, 6.787578}},
-   {352, 4, {0.000000, 0.000000, 1.000000}, {23.985743, 8.535051, 6.787578}},
-   {356, 4, {0.000000, 0.000000, 1.000000}, {12.785742, 8.535051, 6.787578}},
-   {360, 4, {-1.000000, -0.000000, 0.000000}, {11.185741, 14.935051, 5.113236}},
-   {364, 4, {1.000000, 0.000000, 0.000000}, {27.185741, 8.535051, 5.113236}},
-   {368, 4, {-0.000000, 0.000000, -1.000000}, {23.985741, 14.935051, -2.047508}},
-   {372, 4, {0.000000, 0.000000, 1.000000}, {12.785742, 14.935051, 6.787578}},
-};
-struct cxr_edge test_edges[] = {
-   {6, 7},
-   {27, 15},
-   {29, 4},
-   {28, 29},
-   {10, 11},
-   {20, 7},
-   {7, 0},
-   {14, 18},
-   {18, 21},
-   {21, 24},
-   {4, 5},
-   {12, 13},
-   {8, 9},
-   {9, 21},
-   {9, 10},
-   {15, 16},
-   {28, 16},
-   {24, 27},
-   {2, 4},
-   {3, 15},
-   {26, 5},
-   {17, 2},
-   {12, 20},
-   {29, 17},
-   {18, 19},
-   {23, 26},
-   {11, 3},
-   {19, 20},
-   {23, 6},
-   {27, 28},
-   {25, 28},
-   {22, 25},
-   {0, 12},
-   {25, 26},
-   {8, 18},
-   {26, 29},
-   {21, 22},
-   {13, 19},
-   {24, 25},
-   {11, 27},
-   {19, 22},
-   {16, 17},
-   {5, 6},
-   {14, 1},
-   {1, 8},
-   {13, 14},
-   {22, 23},
-   {20, 23},
-   {10, 24},
-   {30, 4},
-   {31, 9},
-   {32, 14},
-   {78, 55},
-   {34, 7},
-   {79, 77},
-   {36, 11},
-   {37, 15},
-   {80, 70},
-   {39, 13},
-   {40, 10},
-   {81, 53},
-   {82, 67},
-   {83, 49},
-   {44, 6},
-   {45, 8},
-   {46, 0},
-   {84, 50},
-   {85, 30},
-   {86, 31},
-   {87, 32},
-   {2, 33},
-   {88, 34},
-   {1, 35},
-   {89, 36},
-   {90, 37},
-   {5, 38},
-   {91, 39},
-   {92, 40},
-   {16, 41},
-   {17, 42},
-   {3, 43},
-   {93, 44},
-   {94, 45},
-   {95, 46},
-   {12, 47},
-   {45, 35},
-   {33, 42},
-   {31, 40},
-   {37, 43},
-   {37, 41},
-   {42, 41},
-   {44, 38},
-   {35, 32},
-   {32, 39},
-   {30, 33},
-   {46, 47},
-   {31, 45},
-   {38, 30},
-   {36, 40},
-   {46, 34},
-   {43, 36},
-   {39, 47},
-   {34, 44},
-   {48, 49},
-   {50, 51},
-   {52, 53},
-   {54, 53},
-   {55, 56},
-   {51, 57},
-   {58, 59},
-   {60, 54},
-   {59, 61},
-   {57, 62},
-   {63, 64},
-   {65, 66},
-   {53, 67},
-   {68, 69},
-   {49, 54},
-   {64, 70},
-   {56, 70},
-   {71, 48},
-   {70, 72},
-   {60, 52},
-   {69, 71},
-   {71, 73},
-   {74, 65},
-   {74, 73},
-   {75, 51},
-   {58, 75},
-   {51, 63},
-   {61, 75},
-   {64, 76},
-   {48, 60},
-   {73, 60},
-   {61, 74},
-   {69, 74},
-   {59, 77},
-   {77, 68},
-   {52, 76},
-   {62, 50},
-   {65, 63},
-   {73, 66},
-   {50, 58},
-   {67, 55},
-   {76, 67},
-   {66, 64},
-   {76, 56},
-   {68, 61},
-   {66, 52},
-   {72, 57},
-   {63, 72},
-   {75, 65},
-   {33, 78},
-   {35, 79},
-   {38, 80},
-   {41, 81},
-   {42, 82},
-   {43, 83},
-   {47, 84},
-   {56, 85},
-   {69, 86},
-   {59, 87},
-   {57, 88},
-   {48, 89},
-   {54, 90},
-   {58, 91},
-   {71, 92},
-   {72, 93},
-   {68, 94},
-   {62, 95},
-   {83, 89},
-   {90, 81},
-   {85, 78},
-   {81, 82},
-   {87, 91},
-   {79, 94},
-   {83, 90},
-   {86, 92},
-   {93, 80},
-   {78, 82},
-   {95, 88},
-   {88, 93},
-   {91, 84},
-   {85, 80},
-   {94, 86},
-   {87, 79},
-   {92, 89},
-   {95, 84},
-};
-struct cxr_input_mesh test_mesh = {
-   .vertices = test_verts,
-   .loops = test_loops,
-   .edges = test_edges,
-   .polys = test_polys,
-   .poly_count=94,
-   .vertex_count=96,
-   .edge_count=188,
-   .loop_count=376
-};