static void printElement (element_t* elementPtr) { long numCoordinate = elementPtr->numCoordinate; coordinate_t* coordinates = elementPtr->coordinates; long i; printf("%li: ", elementPtr->numCoordinate); for (i = 0; i < numCoordinate; i++) { printf("(%.2lf, %.2lf) ", coordinates[i].x, coordinates[i].y); } printf("| (%.2lf, %.2lf)", elementPtr->circumCenter.x, elementPtr->circumCenter.y); printf(" | isBad = %li", (long)element_isBad(elementPtr)); puts(""); }
/* ============================================================================= * TMretriangulate * -- Returns net amount of elements added to mesh * ============================================================================= */ long TMretriangulate (TM_ARGDECL element_t* elementPtr, region_t* regionPtr, mesh_t* meshPtr, MAP_T* edgeMapPtr) { vector_t* badVectorPtr = regionPtr->badVectorPtr; /* private */ list_t* beforeListPtr = regionPtr->beforeListPtr; /* private */ list_t* borderListPtr = regionPtr->borderListPtr; /* private */ list_iter_t it; long numDelta = 0L; assert(edgeMapPtr); coordinate_t centerCoordinate = element_getNewPoint(elementPtr); /* * Remove the old triangles */ TMLIST_ITER_RESET(&it, beforeListPtr); while (TMLIST_ITER_HASNEXT(&it, beforeListPtr)) { element_t* beforeElementPtr = (element_t*)TMLIST_ITER_NEXT(&it, beforeListPtr); TMMESH_REMOVE(meshPtr, beforeElementPtr); } numDelta -= PLIST_GETSIZE(beforeListPtr); /* * If segment is encroached, split it in half */ if (element_getNumEdge(elementPtr) == 1) { coordinate_t coordinates[2]; edge_t* edgePtr = element_getEdge(elementPtr, 0); coordinates[0] = centerCoordinate; coordinates[1] = *(coordinate_t*)(edgePtr->firstPtr); element_t* aElementPtr = TMELEMENT_ALLOC(coordinates, 2); assert(aElementPtr); TMMESH_INSERT(meshPtr, aElementPtr, edgeMapPtr); coordinates[1] = *(coordinate_t*)(edgePtr->secondPtr); element_t* bElementPtr = TMELEMENT_ALLOC(coordinates, 2); assert(bElementPtr); TMMESH_INSERT(meshPtr, bElementPtr, edgeMapPtr); bool_t status; status = TMMESH_REMOVEBOUNDARY(meshPtr, element_getEdge(elementPtr, 0)); assert(status); status = TMMESH_INSERTBOUNDARY(meshPtr, element_getEdge(aElementPtr, 0)); assert(status); status = TMMESH_INSERTBOUNDARY(meshPtr, element_getEdge(bElementPtr, 0)); assert(status); numDelta += 2; } /* * Insert the new triangles. These are contructed using the new * point and the two points from the border segment. */ list_iter_reset(&it, borderListPtr); while (list_iter_hasNext(&it, borderListPtr)) { element_t* afterElementPtr; coordinate_t coordinates[3]; edge_t* borderEdgePtr = (edge_t*)list_iter_next(&it, borderListPtr); assert(borderEdgePtr); coordinates[0] = centerCoordinate; coordinates[1] = *(coordinate_t*)(borderEdgePtr->firstPtr); coordinates[2] = *(coordinate_t*)(borderEdgePtr->secondPtr); afterElementPtr = TMELEMENT_ALLOC(coordinates, 3); assert(afterElementPtr); TMMESH_INSERT(meshPtr, afterElementPtr, edgeMapPtr); if (element_isBad(afterElementPtr)) { TMaddToBadVector(TM_ARG badVectorPtr, afterElementPtr); } } numDelta += PLIST_GETSIZE(borderListPtr); return numDelta; }