static void AddSentinel( TESStesselator *tess, TESSreal smin, TESSreal smax, TESSreal t ) /* * We add two sentinel edges above and below all other edges, * to avoid special cases at the top and bottom. */ { TESShalfEdge *e; ActiveRegion *reg = (ActiveRegion *)bucketAlloc( tess->regionPool ); if (reg == NULL) longjmp(tess->env,1); e = tessMeshMakeEdge( tess->mesh ); if (e == NULL) longjmp(tess->env,1); e->Org->s = smax; e->Org->t = t; e->Dst->s = smin; e->Dst->t = t; tess->event = e->Dst; /* initialize it */ reg->eUp = e; reg->windingNumber = 0; reg->inside = FALSE; reg->fixUpperEdge = FALSE; reg->sentinel = TRUE; reg->dirty = FALSE; reg->nodeUp = dictInsert( tess->dict, reg ); if (reg->nodeUp == NULL) longjmp(tess->env,1); }
void tessAddContour( TESStesselator *tess, int size, const void* vertices, int stride, int numVertices ) { const unsigned char *src = (const unsigned char*)vertices; TESShalfEdge *e; int i; if ( tess->mesh == NULL ) tess->mesh = tessMeshNewMesh( &tess->alloc ); if ( tess->mesh == NULL ) { tess->outOfMemory = 1; return; } if ( size < 2 ) size = 2; if ( size > 3 ) size = 3; e = NULL; for( i = 0; i < numVertices; ++i ) { const TESSreal* coords = (const TESSreal*)src; src += stride; if( e == NULL ) { /* Make a self-loop (one vertex, one edge). */ e = tessMeshMakeEdge( tess->mesh ); if ( e == NULL ) { tess->outOfMemory = 1; return; } if ( !tessMeshSplice( tess->mesh, e, e->Sym ) ) { tess->outOfMemory = 1; return; } } else { /* Create a new vertex and edge which immediately follow e * in the ordering around the left face. */ if ( tessMeshSplitEdge( tess->mesh, e ) == NULL ) { tess->outOfMemory = 1; return; } e = e->Lnext; } /* The new vertex is now e->Org. */ e->Org->coords[0] = coords[0]; e->Org->coords[1] = coords[1]; if ( size > 2 ) e->Org->coords[2] = coords[2]; else e->Org->coords[2] = 0; /* Store the insertion number so that the vertex can be later recognized. */ e->Org->idx = tess->vertexIndexCounter++; /* The winding of an edge says how the winding number changes as we * cross from the edge''s right face to its left face. We add the * vertices in such an order that a CCW contour will add +1 to * the winding number of the region inside the contour. */ e->winding = 1; e->Sym->winding = -1; } }