void Linearization::linearization() { std::list<int>*X; int edgeCount = 0; while (undirectedGraph->getTotalEdgeCount() >= 1) { int randomNode = getRandomNonZeroDegreeNodeId(); appendToList(L, kValues, randomNode); while (true) { X = lastK(L); int v = mostWeightFrom(X); if (v == -1) { // -1 means no node has edge with set X break; } int oldDegree = undirectedGraph->degreeOfNode(v); removeAllEdgesBetween(v, X); edgeCount = edgeCount + (oldDegree - undirectedGraph->degreeOfNode(v)); appendToList(L, kValues, v); if ((L.size() % 1000) == 0) { if ((edgeCount / (2.0 * 1000 * k)) < dt && k != 1) { k = (int) (k * rf); } edgeCount = 0; } } } }
listPo replaceListEl(heapPo H, listPo list, integer px, termPo vl) { if (px >= listSize(list)) return appendToList(H, list, vl); else if (px < 0) return prependToList(H, list, vl); else { basePo base = C_BASE(list->base); int root = gcAddRoot(H, (ptrPo) (&base)); gcAddRoot(H, (ptrPo) (&list)); gcAddRoot(H, (ptrPo) (&vl)); integer delta = base->length / 8; basePo nb = copyBase(H, base, list->start, list->length, delta); nb->els[nb->min + px] = vl; gcAddRoot(H, (ptrPo) &nb); listPo slice = (listPo) newSlice(H, nb, nb->min, list->length); assert(saneList(H, slice)); gcReleaseRoot(H, root); releaseHeapLock(H); return slice; } }
static void dividePointsBetweenNewFacets ( zhull_t * const zh, const list_t assoc, const list_t new_facets) { index_t i,j; facet_t *f; list_t point_inside_facet_list=emptyList(); float d; entry_t e; for (i=0; i<getLength(assoc); i++) { e=getEntry(assoc,i); int idx = entry_getIndex(&e); for (j=0; j<getLength(new_facets); j++) { f=getFacetByIndex(new_facets,j); d=distancePointPlane(getPoint(zh->pts,idx), f->plane); if (d>=TOL_OUTSIDEPOINT) { break; } else if (d>=TOL_INSIDEPOINT) { appendToList(&point_inside_facet_list,entry_makePointer(f)); } } if (d>=TOL_OUTSIDEPOINT) { appendToList(&(f->outsideset), e); if (notInList(entry_makePointer(f),zh->facets_with_outsidepoints)) { appendToList(&(zh->facets_with_outsidepoints),entry_makePointer(f)); } if (f->maxdistance<d) { f->maxdistance=d; f->farthest_outside_point=idx; } } else { if (getLength(point_inside_facet_list)>0) { for (j=0; j<getLength(point_inside_facet_list); j++) { f=getFacetByIndex(point_inside_facet_list,j); if (notInList(e,f->insideset)) { appendToList(&(f->insideset),e); } } appendListToList(&(zh->facets_with_insidepoints),point_inside_facet_list); uniquefyListEntries(&(zh->facets_with_insidepoints)); } } } freeList(&point_inside_facet_list); }
void testReverseList() { cout << endl; cout << "Test reverseList():" << endl; cout << "===================" << endl; char a[] = "a"; char b[] = "b"; char c[] = "c"; char d[] = "d"; char e[] = "e"; char f[] = "f"; char g[] = "g"; Node<char*> head; head.data = a; head.next = nullptr; appendToList(&head, &b[0]); appendToList(&head, &c[0]); appendToList(&head, &d[0]); appendToList(&head, &e[0]); appendToList(&head, &f[0]); appendToList(&head, &g[0]); printList(&head); Node<char*>* rev = reverseList(&head); printList(rev); Node<char*>* orig = reverseList(rev); printList(orig); }
static void makePyramidFacetsToHorizon(zhull_t *zh, index_t point_index, list_t horizon_fcts, list_t horizon_fcts_edges, list_t other_horizon_edges, list_t avail_points) { list_t new_facets = appendNewFacets(zh, getLength(horizon_fcts_edges)); // printf("making new pyramid of %d facets\n",getLength(horizon_fcts_edges)); initNewFacets(zh,point_index,new_facets,horizon_fcts,horizon_fcts_edges, other_horizon_edges); appendToList(&(zh->used_pts),entry_makeIndex(point_index)); /* printf("available points: "); printList(avail_points); printf("new facets : "); printList(new_facets);*/ dividePointsBetweenNewFacets(zh, avail_points, new_facets); freeList(&new_facets); }
listPo insertListEl(heapPo H, listPo list, integer px, termPo vl) { basePo base = C_BASE(list->base); if (px <= 0) return prependToList(H, list, vl); else if (px >= listSize(list)) return appendToList(H, list, vl); else { int root = gcAddRoot(H, (ptrPo) (&base)); gcAddRoot(H, (ptrPo) (&list)); gcAddRoot(H, (ptrPo) (&vl)); integer delta = base->length / 8; integer newLen = base->length + delta + 1; basePo nb = (basePo) allocateObject(H, baseClass, BaseCellCount(newLen)); integer ocount = list->length; assert(ocount >= 0); integer extra = newLen - ocount; nb->min = extra / 2 - 1; nb->max = nb->min + ocount + 1; nb->length = newLen; for (integer ix = 0; ix < px; ix++) { nb->els[nb->min + ix] = base->els[base->min + ix]; } nb->els[nb->min + px] = vl; for (integer ix = px; ix < ocount; ix++) { nb->els[nb->min + ix + 1] = base->els[base->min + ix]; } gcAddRoot(H, (ptrPo) (&nb)); listPo slice = (listPo) newSlice(H, nb, nb->min, ocount + 1); gcReleaseRoot(H, root); releaseHeapLock(H); assert(saneList(H, slice)); return slice; } }
static void appendExteriorPoints(zhull_t *zh) { index_t i; vector_t center = initVector(0.0f,0.0f,0.0f); list_t facet_delete_list=emptyList(); facet_t *f; center=averageListedPoints(zh->pts,zh->used_pts); printf("central point\n"); printVector(center); printf("\n"); for (i=0; i<getLength(zh->facets); i++) { f=getFacetByIndex(zh->facets,i); printf("distance of plane %lu, d=%5.2f\n",(unsigned long)i, distancePointPlane(center,f->plane)); if (distancePointPlane(center,f->plane)>-0.5f) { appendToList(&facet_delete_list,entry_makePointer(f)); } } printList(facet_delete_list); removeFacetByPointerList(zh,facet_delete_list); freeList(&facet_delete_list); }
XeTeXFontMgr::NameCollection* XeTeXFontMgr_FC::readNames(FcPattern* pat) { NameCollection* names = new NameCollection; char* pathname; if (FcPatternGetString(pat, FC_FILE, 0, (FcChar8**)&pathname) != FcResultMatch) return names; int index; if (FcPatternGetInteger(pat, FC_INDEX, 0, &index) != FcResultMatch) return names; FT_Face face; if (FT_New_Face(gFreeTypeLibrary, pathname, index, &face) != 0) return names; const char* name = FT_Get_Postscript_Name(face); if (name == NULL) return names; names->psName = name; // for sfnt containers, we'll read the name table ourselves, not rely on Fontconfig if (FT_IS_SFNT(face)) { std::list<std::string> familyNames; std::list<std::string> subFamilyNames; FT_SfntName nameRec; for (index = 0; index < FT_Get_Sfnt_Name_Count(face); ++index) { char* utf8name = NULL; if (FT_Get_Sfnt_Name(face, index, &nameRec) != 0) continue; switch (nameRec.name_id) { case kFontFullName: case kFontFamilyName: case kFontStyleName: case kPreferredFamilyName: case kPreferredSubfamilyName: { bool preferredName = false; if (nameRec.platform_id == TT_PLATFORM_MACINTOSH && nameRec.encoding_id == TT_MAC_ID_ROMAN && nameRec.language_id == 0) { utf8name = convertToUtf8(macRomanConv, nameRec.string, nameRec.string_len); preferredName = true; } else if ((nameRec.platform_id == TT_PLATFORM_APPLE_UNICODE) || (nameRec.platform_id == TT_PLATFORM_MICROSOFT)) utf8name = convertToUtf8(utf16beConv, nameRec.string, nameRec.string_len); if (utf8name != NULL) { std::list<std::string>* nameList = NULL; switch (nameRec.name_id) { case kFontFullName: nameList = &names->fullNames; break; case kFontFamilyName: nameList = &names->familyNames; break; case kFontStyleName: nameList = &names->styleNames; break; case kPreferredFamilyName: nameList = &familyNames; break; case kPreferredSubfamilyName: nameList = &subFamilyNames; break; } if (preferredName) prependToList(nameList, utf8name); else appendToList(nameList, utf8name); } } break; } } if (familyNames.size() > 0) names->familyNames = familyNames; if (subFamilyNames.size() > 0) names->styleNames = subFamilyNames; } else { index = 0; while (FcPatternGetString(pat, FC_FULLNAME, index++, (FcChar8**)&name) == FcResultMatch) appendToList(&names->fullNames, name); index = 0; while (FcPatternGetString(pat, FC_FAMILY, index++, (FcChar8**)&name) == FcResultMatch) appendToList(&names->familyNames, name); index = 0; while (FcPatternGetString(pat, FC_STYLE, index++, (FcChar8**)&name) == FcResultMatch) appendToList(&names->styleNames, name); if (names->fullNames.size() == 0) { std::string fullName(names->familyNames.front()); if (names->styleNames.size() > 0) { fullName += " "; fullName += names->styleNames.front(); } names->fullNames.push_back(fullName); } } FT_Done_Face(face); return names; }
/* Implementation of the TimeSubject interface. */ void attach(const TimeObserver* observer) { assert(0 == isNotifying); assert(NULL != observer); appendToList(observer); }
static void removeVisibleFacetsGetHorizonAndAvailablePoints( zhull_t * const zh, index_t point_index, facet_t *f, list_t *horizon_fcts, list_t *horizon_fcts_edges, list_t *other_horizon_edges, list_t *avail_points) { index_t j,k; facet_t *n; float d; list_t visible_fcts = emptyList(); list_t fcts_to_visit = emptyList(); list_t fcts_visited = emptyList(); // list_t list_for_printing = emptyList(); *avail_points = emptyList(); *horizon_fcts = emptyList(); *horizon_fcts_edges = emptyList(); *other_horizon_edges = emptyList(); d=distancePointPlane(getPoint(zh->pts,point_index),f->plane); // printf("distance %5.2f\n",d); appendToList(&fcts_to_visit,entry_makePointer(f)); if (d>=TOL_OUTSIDEPOINT) { while (getLength(fcts_to_visit)>0) { // visiting only visible facets // horizon: edges to invisible or coincident neighbors f=getFacetByIndex(fcts_to_visit,0); appendToList(&visible_fcts,entry_makePointer(f)); appendListToList(avail_points, f->outsideset); for (j=0; j<getLength(f->neighbors); j++) { n=getFacetByIndex(f->neighbors,j); d=distancePointPlane(getPoint(zh->pts,point_index),n->plane); if (d>=TOL_OUTSIDEPOINT) { // visit visible neighbors appendToList(&fcts_to_visit,entry_makePointer(n)); } else { // horizon: coincident or invisible neighbors k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)), n->corners); appendToList(horizon_fcts,entry_makePointer(n)); appendToList(horizon_fcts_edges,entry_makeIndex(k)); appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts))); } } removeValueFromList(&fcts_to_visit,entry_makePointer(f)); appendToList(&fcts_visited,entry_makePointer(f)); removeValueListFromList(&fcts_to_visit,fcts_visited); } // printf("removing facets\n"); // list_for_printing=findValueListInList(visible_fcts,zh->facets); // printList(list_for_printing); // freeList(&list_for_printing); removeFacetByPointerList(zh,visible_fcts); freeList(&visible_fcts); freeList(&fcts_to_visit); freeList(&fcts_visited); sortHorizonEdges(horizon_fcts, horizon_fcts_edges, other_horizon_edges); //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges); } else if (d>=TOL_INSIDEPOINT) { // all coincident surfaces shall be removed // horizon might not be defined by facets while (getLength(fcts_to_visit)>0) { f=getFacetByIndex(fcts_to_visit,0); appendToList(&visible_fcts,entry_makePointer(f)); appendListToList(avail_points, f->outsideset); appendListToList(avail_points, f->insideset); for (j=0; j<getLength(f->neighbors); j++) { n=getFacetByIndex(f->neighbors,j); d=distancePointPlane(getPoint(zh->pts,point_index),n->plane); if (d>=TOL_INSIDEPOINT) { // coincident facet if (notInList(entry_makePointer(n),visible_fcts)) { appendToList(&fcts_to_visit,entry_makePointer(n)); } if ((innerProduct(f->plane.normal,n->plane.normal)< -1.0f+TOL_DEGENERATE)&& (distancePointLineOnPlane(getPoint(zh->pts,point_index), getLine(zh,f,j), f->plane)<TOL_INSIDEPOINT)) { // coincident facets with opposite surface orientation // yield an edge to keep despite all facets will be removed // as soon as edge is invisible to point appendToList(horizon_fcts,entry_makePointer(0)); appendToList(other_horizon_edges, getEntry(f->corners,j)); appendToList(horizon_fcts_edges, getEntry(f->corners,(j+1)%getLength(f->corners))); } } else { // invisible facet forms horizon that persists k=findValueInList(getEntry(f->corners,(j+1)%getLength(f->corners)), n->corners); appendToList(horizon_fcts,entry_makePointer(n)); appendToList(horizon_fcts_edges,entry_makeIndex(k)); appendToList(other_horizon_edges,entry_makeIndex(getNumPoints(zh->pts))); } } removeValueFromList(&fcts_to_visit,entry_makePointer(f)); appendToList(&fcts_visited,entry_makePointer(f)); removeValueListFromList(&fcts_to_visit,fcts_visited); } // printf("removing facets\n"); // list_for_printing=findValueListInList(visible_fcts,zh->facets); // printList(list_for_printing); // freeList(&list_for_printing); removeFacetByPointerList(zh,visible_fcts); sortHorizonEdges(horizon_fcts, horizon_fcts_edges,other_horizon_edges); //printHorizonEdges(horizon_fcts,horizon_fcts_edges,other_horizon_edges); freeList(&visible_fcts); freeList(&fcts_to_visit); freeList(&fcts_visited); } }