/* * knot0=this; * knot1=(Knot *)(knot0->next); * knot2=(Knot *)(knot1->next); * on0=knot0->on; on1=knot1->on; on2=knot2->on; * if ((!on0)&&(on1)) return false; * * if (icToNext) icToNext->From(true,false); * curve.type=eGeomUndef; * knotStartNext=knot1; * * if (on1) * { * if (on0) * { * curve.seg.From(knot0->x,knot0->y,knot1->x,knot1->y,false); * curve.type=eGeomSeg; * } * else * { * if (icToNext) icToNext->Connect(false); * } * } * else // 1 - off curve knot * { * curve.type=eGeomBez; * VecD cp0, cp1, cp2; * * if (on0) * { * cp0.From(knot0->x,knot0->y,false); * } * else * { * cp0.From(0.5*(knot0->x+knot1->x),0.5*(knot0->y+knot1->y)); * } * * cp1.From(knot1->x,knot1->y,false); * * if (on2) * { * knotStartNext=knot2; * cp2.From(knot2->x,knot2->y,false); * } * else * { * if (icToNext) icToNext->Tangent(true); * cp2.From(0.5*(knot1->x+knot2->x),0.5*(knot1->y+knot2->y)); * } * curve.bez.From(cp0,cp1,cp2); * } * * * if (getNextNonDegen) * { * CurveD curveAux; * Knot *knotCurAux, *knotNextAux; * if (!knotStartNext->GetCurve(curveAux, knotNextAux)) return false; * if (!curveAux.IsPnt()) return true; * icToNext->Tangent(false); * while (curveAux.IsPnt()) * { * knotCurAux=knotNextAux; * if (knotCurAux==knotStartNext) return false; // no non-degenerated curves... * if (!knotCurAux->GetCurve(curveAux, knotNextAux)) return false; * } * knotStartNext=knotCurAux; * } * return true; * } */ public Knot KnotNearest(VecD vecLocation) { double distMin = MConsts.Infinity; Knot knotNearest = null; foreach (Knot knot in this.knots) { double distCur = vecLocation.Dist(knot.Val); if (distCur < distMin) { distMin = distCur; knotNearest = knot; } } return(knotNearest); }
public Knot KnotNearest(VecD vecLocation) { double distMin = MConsts.Infinity; Knot knotNearest = null; foreach (Contour cont in this.conts) { Knot knotNearestCur = cont.KnotNearest(vecLocation); if (knotNearestCur != null) { double distCur = vecLocation.Dist(knotNearestCur.Val); if (distCur < distMin) { distMin = distCur; knotNearest = knotNearestCur; } } } return(knotNearest); }
/* knot0=this; knot1=(Knot *)(knot0->next); knot2=(Knot *)(knot1->next); on0=knot0->on; on1=knot1->on; on2=knot2->on; if ((!on0)&&(on1)) return false; if (icToNext) icToNext->From(true,false); curve.type=eGeomUndef; knotStartNext=knot1; if (on1) { if (on0) { curve.seg.From(knot0->x,knot0->y,knot1->x,knot1->y,false); curve.type=eGeomSeg; } else { if (icToNext) icToNext->Connect(false); } } else // 1 - off curve knot { curve.type=eGeomBez; VecD cp0, cp1, cp2; if (on0) { cp0.From(knot0->x,knot0->y,false); } else { cp0.From(0.5*(knot0->x+knot1->x),0.5*(knot0->y+knot1->y)); } cp1.From(knot1->x,knot1->y,false); if (on2) { knotStartNext=knot2; cp2.From(knot2->x,knot2->y,false); } else { if (icToNext) icToNext->Tangent(true); cp2.From(0.5*(knot1->x+knot2->x),0.5*(knot1->y+knot2->y)); } curve.bez.From(cp0,cp1,cp2); } if (getNextNonDegen) { CurveD curveAux; Knot *knotCurAux, *knotNextAux; if (!knotStartNext->GetCurve(curveAux, knotNextAux)) return false; if (!curveAux.IsPnt()) return true; icToNext->Tangent(false); while (curveAux.IsPnt()) { knotCurAux=knotNextAux; if (knotCurAux==knotStartNext) return false; // no non-degenerated curves... if (!knotCurAux->GetCurve(curveAux, knotNextAux)) return false; } knotStartNext=knotCurAux; } return true; } */ public Knot KnotNearest(VecD vecLocation) { double distMin=MConsts.Infinity; Knot knotNearest=null; foreach (Knot knot in this.knots) { double distCur=vecLocation.Dist(knot.Val); if (distCur<distMin) { distMin=distCur; knotNearest=knot; } } return knotNearest; }
public Knot KnotNearest(VecD vecLocation) { double distMin=MConsts.Infinity; Knot knotNearest=null; foreach (Contour cont in this.conts) { Knot knotNearestCur=cont.KnotNearest(vecLocation); if (knotNearestCur!=null) { double distCur=vecLocation.Dist(knotNearestCur.Val); if (distCur<distMin) { distMin=distCur; knotNearest=knotNearestCur; } } } return knotNearest; }
/* * INTERSECT: (LCurve, LCurve) * - both curves are supposed to be NON-DEGENERATED */ public static bool IntersectLL(LCurve lrsA, LCurve lrsB, out InfoInters inters) { inters = null; if ((lrsA.IsDegen) || (lrsB.IsDegen)) { throw new ExceptionGMath("Intersect", "IntersectLL(lrs,lrs)", null); } VecD a0 = lrsA.Start; VecD a1 = lrsA.End; VecD b0 = lrsB.Start; VecD b1 = lrsB.End; VecD dirA = lrsA.DirTang; VecD dirB = lrsB.DirTang; double det = dirA.Cross(dirB); // lrsA and lrsB are not parallel if (Math.Abs(det) > MConsts.EPS_DEC) { double lenA = (a1 - a0).Norm; double lenB = (b1 - b0).Norm; VecD diff = b0 - a0; Param parA = (diff.Cross(dirB)) / (det * lenA); Param parB = (diff.Cross(dirA)) / (det * lenB); if (lrsA.IsEvaluableStrict(parA) && lrsB.IsEvaluableStrict(parB)) { VecD pnt = 0.5 * (lrsA.Evaluate(parA) + lrsB.Evaluate(parB)); inters = new IntersD0(parA, parB, pnt, false); } return(true); } // lrsA and lrsB are parallel LineD lineB = new LineD(lrsB); Param paramBInvA0, paramBInvA1; VecD pntProjA0, pntProjA1; a0.Project(lineB, out paramBInvA0, out pntProjA0); a1.Project(lineB, out paramBInvA1, out pntProjA1); double distA0 = a0.Dist(pntProjA0); double distA1 = a1.Dist(pntProjA1); if ((distA0 < MConsts.EPS_DEC) || (distA1 < MConsts.EPS_DEC)) { // lrsA and lrsB are colinear Param.TypeParam typeA0 = lrsB.ParamClassify(paramBInvA0); Param.TypeParam typeA1 = lrsB.ParamClassify(paramBInvA1); int mult = (int)typeA0 * (int)typeA1; if (mult == 4) { return(true); } else if (mult == 1) { throw new ExceptionGMath("Intersect", "IntersectLL(lrs,lrs)", null); // lrsA is degenerated //return false; } else if (mult == 2) { if ((typeA0 == Param.TypeParam.Start) && (typeA1 == Param.TypeParam.Before)) { inters = new IntersD0(0, 0, a0, false); } if ((typeA0 == Param.TypeParam.Before) && (typeA1 == Param.TypeParam.Start)) { inters = new IntersD0(1, 0, a1, false); } if ((typeA0 == Param.TypeParam.End) && (typeA1 == Param.TypeParam.After)) { inters = new IntersD0(0, 1, a0, false); } if ((typeA0 == Param.TypeParam.After) && (typeA1 == Param.TypeParam.End)) { inters = new IntersD0(1, 1, a1, false); } return(true); } else if (mult <= 0) { return(Inters.RefineIntersLLD1(lrsA, lrsB, out inters)); } } return(true); }