public void ParamReverse(double valRev, int indCurve, int pozStart) { for (int poz = pozStart; poz < this.linters.Count; poz++) { InfoInters inters = linters[poz] as InfoInters; inters.ParamReverse(valRev, indCurve); } }
/* * REFINE INTERSECTION D1 */ public static bool RefineIntersBBD1(BCurve curveA, BCurve curveB, out InfoInters inters) { /* * ASSUMPTIONS: * - curveA & curveB are MAXIMALLY REDUCED * - intersection is KNOWN to have dimension D1 * - does not work in case of SI beziers * => OR: both curveA & curveB are SEGMENTS * OR: both curveA & curveB are BEZIER */ inters = null; InfoInters selfinters; if (curveA.IsSelfInters(out selfinters) || curveB.IsSelfInters(out selfinters)) { throw new ExceptionGMath("Intersect", "RefineIntersBBD1", null); //return false; } VecD a0 = curveA.Start; VecD a1 = curveA.End; Param paramBInvA0, paramBInvA1; bool isOn; if (!a0.InverseOn(curveB, out isOn, out paramBInvA0) || (!isOn)) { return(false); } if (!a1.InverseOn(curveB, out isOn, out paramBInvA1) || (!isOn)) { return(false); } paramBInvA0.Round(0, 1); paramBInvA1.Round(0, 1); bool areCoDirected = (paramBInvA1 >= paramBInvA0); if (!areCoDirected) { BCurve revB = curveB.Reversed as BCurve; if (!Inters.RefineIntersBBD1(curveA, revB, out inters)) { return(false); } if (inters != null) { inters.ParamReverse(1, 1); } return(true); } VecD b0 = curveB.Start; VecD b1 = curveB.End; Param paramAInvB0, paramAInvB1; if (!b0.InverseOn(curveA, out isOn, out paramAInvB0) || (!isOn)) { return(false); } if (!b1.InverseOn(curveA, out isOn, out paramAInvB1) || (!isOn)) { return(false); } paramAInvB0.Round(0, 1); paramAInvB1.Round(0, 1); Param paramInA = null, paramInB = null, paramOutA = null, paramOutB = null; VecD pntIn = null, pntOut = null; if (paramBInvA0 <= 0) // before or start { paramInA = paramAInvB0; paramInB = 0; pntIn = b0; } else if (paramBInvA0 < 1) // inner { paramInA = 0; paramInB = paramBInvA0; pntIn = a0; } if ((paramBInvA1 >= 0) && (paramBInvA1 <= 1)) // inner or end { paramOutA = 1; paramOutB = paramBInvA1; pntOut = a1; } else if (paramBInvA1 > 1) // after { paramOutA = paramAInvB1; paramOutB = 1; pntOut = b1; } if ((pntIn == null) || (pntOut == null)) { throw new ExceptionGMath("Intersect", "RefineIntersBBD1", null); //return false; } Curve curveInters = curveA.SubCurve(paramInA, paramOutA); inters = new IntersD1(paramInA, paramInB, paramOutA, paramOutB, curveInters, false); return(true); }
/* * REFINE INTERSECTION D1 */ public static bool RefineIntersBBD1(BCurve curveA, BCurve curveB, out InfoInters inters) { /* * ASSUMPTIONS: * - curveA & curveB are MAXIMALLY REDUCED * - intersection is KNOWN to have dimension D1 * - does not work in case of SI beziers * => OR: both curveA & curveB are SEGMENTS * OR: both curveA & curveB are BEZIER */ inters=null; InfoInters selfinters; if (curveA.IsSelfInters(out selfinters)||curveB.IsSelfInters(out selfinters)) { throw new ExceptionGMath("Intersect","RefineIntersBBD1",null); //return false; } VecD a0=curveA.Start; VecD a1=curveA.End; Param paramBInvA0, paramBInvA1; bool isOn; if (!a0.InverseOn(curveB, out isOn, out paramBInvA0)||(!isOn)) return false; if (!a1.InverseOn(curveB, out isOn, out paramBInvA1)||(!isOn)) return false; paramBInvA0.Round(0,1); paramBInvA1.Round(0,1); bool areCoDirected=(paramBInvA1>=paramBInvA0); if (!areCoDirected) { BCurve revB=curveB.Reversed as BCurve; if (!Inters.RefineIntersBBD1(curveA,revB,out inters)) return false; if (inters!=null) { inters.ParamReverse(1,1); } return true; } VecD b0=curveB.Start; VecD b1=curveB.End; Param paramAInvB0, paramAInvB1; if (!b0.InverseOn(curveA, out isOn, out paramAInvB0)||(!isOn)) return false; if (!b1.InverseOn(curveA, out isOn, out paramAInvB1)||(!isOn)) return false; paramAInvB0.Round(0,1); paramAInvB1.Round(0,1); Param paramInA=null, paramInB=null, paramOutA=null, paramOutB=null; VecD pntIn=null, pntOut=null; if (paramBInvA0<=0) // before or start { paramInA=paramAInvB0; paramInB=0; pntIn=b0; } else if (paramBInvA0<1) // inner { paramInA=0; paramInB=paramBInvA0; pntIn=a0; } if ((paramBInvA1>=0)&&(paramBInvA1<=1)) // inner or end { paramOutA=1; paramOutB=paramBInvA1; pntOut=a1; } else if (paramBInvA1>1) // after { paramOutA=paramAInvB1; paramOutB=1; pntOut=b1; } if ((pntIn==null)||(pntOut==null)) { throw new ExceptionGMath("Intersect","RefineIntersBBD1",null); //return false; } Curve curveInters=curveA.SubCurve(paramInA,paramOutA); inters=new IntersD1(paramInA,paramInB, paramOutA,paramOutB,curveInters,false); return true; }