return Standard_True;
}
- myTol = Tolerance;
+ Standard_Real aSqTol = Tolerance * Tolerance;
Standard_Integer LBs = Bs->NbPoles(), LCb = myCurve->NbPoles();
-
- // myCurve est elle fermee ?
- if (myCurve->Pole(LCb).Distance(myCurve->Pole(1)) < myTol){
- if(After){
- // Ajout Apres ?
- Standard_Real d1 = myCurve->Pole(LCb).Distance(Bs->Pole(1));
- Standard_Real d2 = myCurve->Pole(LCb).Distance(Bs->Pole(LBs));
- if (d2 < d1) {
- Bs->Reverse();
- d1 = d2;
- }
- if (d1 < myTol) {
- Add(myCurve, Bs, Standard_True);
- return Standard_True;
- }
- }
- else{
- // Ajout avant ?
- Standard_Real d1 = myCurve->Pole(1).Distance(Bs->Pole(1));
- Standard_Real d2 = myCurve->Pole(1).Distance(Bs->Pole(LBs));
- if (d1 < d2) {
- Bs->Reverse();
- d2 = d1;
- }
- if (d2 < myTol) {
- Add(Bs, myCurve, Standard_False);
- return Standard_True;
- }
- }
+
+ Standard_Boolean isBeforeReversed = myCurve->Pole(1).SquareDistance(Bs->Pole(1)) < aSqTol;
+ Standard_Boolean isBefore = (myCurve->Pole(1).SquareDistance(Bs->Pole(LBs)) < aSqTol) || isBeforeReversed;
+ Standard_Boolean isAfterReversed = myCurve->Pole(LCb).SquareDistance(Bs->Pole(LBs)) < aSqTol;
+ Standard_Boolean isAfter = (myCurve->Pole(LCb).SquareDistance(Bs->Pole(1)) < aSqTol) || isAfterReversed;
+
+ // myCurve and NewCurve together form a closed curve
+ if (isBefore && isAfter)
+ {
+ if (After) isBefore = Standard_False;
+ else isAfter = Standard_False;
}
- // Ajout Apres ?
- else {
- Standard_Real d1 = myCurve->Pole(LCb).Distance(Bs->Pole(1));
- Standard_Real d2 = myCurve->Pole(LCb).Distance(Bs->Pole(LBs));
- if (( d1 < myTol) || ( d2 < myTol)) {
- if (d2 < d1) {Bs->Reverse();}
- Add(myCurve, Bs, Standard_True);
- return Standard_True;
+ if (isAfter)
+ {
+ if (isAfterReversed)
+ {
+ Bs->Reverse();
}
- // Ajout avant ?
- else {
- d1 = myCurve->Pole(1).Distance(Bs->Pole(1));
- d2 = myCurve->Pole(1).Distance(Bs->Pole(LBs));
- if ( (d1 < myTol) || (d2 < myTol)) {
- if (d1 < d2) {Bs->Reverse();}
- Add(Bs, myCurve, Standard_False );
- return Standard_True;
- }
+ Add(myCurve, Bs, Standard_True);
+ return Standard_True;
+ }
+ else if (isBefore)
+ {
+ if (isBeforeReversed)
+ {
+ Bs->Reverse();
}
- }
+ Add(Bs, myCurve, Standard_False);
+ return Standard_True;
+ }
+
return Standard_False;
}
//! Tolerance is used to check continuity and decrease
//! Multiplicty at the common Knot
//! After is usefull if BasisCurve is a closed curve .
- Standard_EXPORT Standard_Boolean Add (const Handle(Geom2d_BoundedCurve)& NewCurve, const Standard_Real Tolerance, const Standard_Boolean After = Standard_False);
+ Standard_EXPORT Standard_Boolean Add (const Handle(Geom2d_BoundedCurve)& NewCurve, const Standard_Real Tolerance, const Standard_Boolean After = Standard_True);
Standard_EXPORT Handle(Geom2d_BSplineCurve) BSplineCurve() const;