static bool DoesIntersInterfere(const Point& pInt, const Kurve& k, double offset) { // check that intersections don't interfere with the original kurve Span sp; Point dummy; int kCheckVertex = 0; k.Get(kCheckVertex++, sp.p0, sp.pc); offset = fabs(offset) - geoff_geometry::TOLERANCE; while(kCheckVertex <= k.nSpans()) { sp.dir = k.Get(kCheckVertex++, sp.p1, sp.pc); sp.SetProperties(true); // check for interference if(Dist(sp, pInt, dummy) < offset) return true; sp.p0 = sp.p1; } return false; // intersection is ok }
static Kurve eliminateLoops(const Kurve& k , const Kurve& originalk, double offset, int& ret) { // a simple loop elimination routine based on first offset ideas in Peps // this needs extensive work for future // start point musn't disappear & only one valid offset is determined // // ret = 0 for ok // ret = 2 for impossible geometry Span sp0, sp1; Point pInt, pIntOther; Kurve ko; // eliminated output ko = Matrix(k); int kinVertex = 0; while(kinVertex <= k.nSpans()) { bool clipped = false ; // not in a clipped section (assumption with this simple method) sp0.dir = k.Get(kinVertex, sp0.p0, sp0.pc); sp0.ID = k.GetSpanID(kinVertex++); if (kinVertex == 1) { ko.Start(sp0.p0); // start point mustn't dissappear for this simple method ko.AddSpanID(sp0.ID); } if (kinVertex <= k.nSpans()) { // any more? int ksaveVertex = kinVertex ; sp0.dir = k.Get(kinVertex, sp0.p1, sp0.pc); // first span sp0.ID = k.GetSpanID(kinVertex++); sp0.SetProperties(true); int ksaveVertex1 = kinVertex; // mark position AA if (kinVertex <= k.nSpans()) { // get the next but one span sp1.dir = k.Get(kinVertex, sp1.p0, sp1.pc); sp1.ID = k.GetSpanID(kinVertex++); int ksaveVertex2 = kinVertex; // mark position BB int fwdCount = 0; while(kinVertex <= k.nSpans()) { sp1.dir = k.Get(kinVertex, sp1.p1, sp1.pc); // check span sp1.ID = k.GetSpanID(kinVertex++); sp1.SetProperties(true); double t[4]; int numint = sp0.Intof(sp1, pInt, pIntOther, t); // find span intersections if(numint && sp0.p0.Dist(pInt) < geoff_geometry::TOLERANCE ) numint=0; // check that intersection is not at the start of the check span if(numint ) { if(numint == 2) { // choose first intercept on sp0 Span spd = sp0; spd.p1 = pInt; spd.SetProperties(true); double dd = spd.length; spd.p1 = pIntOther; spd.SetProperties(true); if(dd > spd.length) pInt = pIntOther; numint = 1; } ksaveVertex = ksaveVertex1 ; clipped = true ; // in a clipped section if(DoesIntersInterfere(pInt, originalk, offset) == false) { sp0.p1 = pInt; // ok so truncate this span to the intersection clipped = false; // end of clipped section break; } // no valid intersection found so carry on } sp1.p0 = sp1.p1 ; // next ksaveVertex1 = ksaveVertex2 ; // pos AA = BB ksaveVertex2 = kinVertex; // mark if((kinVertex > k.nSpans() || fwdCount++ > 25) && clipped == false) break; } } if(clipped) { ret = 2; // still in a clipped section - error return ko; } ko.Add(sp0, false); kinVertex = ksaveVertex; } } ret = 0; return ko; // no more spans - seems ok }