1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <ChFi2d_FilletAlgo.hxx>
16 #include <GeomProjLib.hxx>
17 #include <BRep_Tool.hxx>
18 #include <Precision.hxx>
22 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
23 #include <GeomAPI_ProjectPointOnCurve.hxx>
24 #include <Geom2dAPI_InterCurveCurve.hxx>
27 #include <TopoDS_Iterator.hxx>
28 #include <TColStd_ListIteratorOfListOfReal.hxx>
30 #include <gp_Circ.hxx>
31 #include <Geom_Circle.hxx>
32 #include <Geom2d_Line.hxx>
34 #include <BRepBuilderAPI_MakeEdge.hxx>
35 #include <BRepAdaptor_Curve.hxx>
37 ChFi2d_FilletAlgo::ChFi2d_FilletAlgo()
43 myStartSide (Standard_False),
44 myEdgesExchnged(Standard_False),
45 myDegreeOfRecursion(0)
49 ChFi2d_FilletAlgo::ChFi2d_FilletAlgo(const TopoDS_Wire& theWire, const gp_Pln& thePlane)
55 myStartSide (Standard_False),
56 myEdgesExchnged(Standard_False),
57 myDegreeOfRecursion(0)
59 Init(theWire, thePlane);
62 ChFi2d_FilletAlgo::ChFi2d_FilletAlgo(const TopoDS_Edge& theEdge1,
63 const TopoDS_Edge& theEdge2,
64 const gp_Pln& thePlane)
72 myStartSide (Standard_False),
73 myEdgesExchnged(Standard_False),
74 myDegreeOfRecursion(0)
76 Init(theEdge1, theEdge2, thePlane);
79 void ChFi2d_FilletAlgo::Init(const TopoDS_Wire& theWire, const gp_Pln& thePlane)
81 TopoDS_Edge theEdge1, theEdge2;
82 TopoDS_Iterator itr(theWire);
83 for (; itr.More(); itr.Next())
85 if (theEdge1.IsNull())
86 theEdge1 = TopoDS::Edge(itr.Value());
87 else if (theEdge2.IsNull())
88 theEdge2 = TopoDS::Edge(itr.Value());
92 if (theEdge1.IsNull() || theEdge2.IsNull())
93 throw Standard_ConstructionError("The fillet algorithms expects a wire consisting of two edges.");
94 Init(theEdge1, theEdge2, thePlane);
97 void ChFi2d_FilletAlgo::Init(const TopoDS_Edge& theEdge1,
98 const TopoDS_Edge& theEdge2,
99 const gp_Pln& thePlane)
101 myPlane = new Geom_Plane(thePlane);
103 myEdgesExchnged = Standard_False;
105 BRepAdaptor_Curve aBAC1(theEdge1);
106 BRepAdaptor_Curve aBAC2(theEdge2);
107 if (aBAC1.GetType() < aBAC2.GetType())
108 { // first curve must be more complicated
111 myEdgesExchnged = Standard_True;
119 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(myEdge1, myStart1, myEnd1);
120 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(myEdge2, myStart2, myEnd2);
122 myCurve1 = GeomProjLib::Curve2d(aCurve1, myStart1, myEnd1, myPlane);
123 myCurve2 = GeomProjLib::Curve2d(aCurve2, myStart2, myEnd2, myPlane);
125 while (myCurve1->IsPeriodic() && myStart1 >= myEnd1)
126 myEnd1 += myCurve1->Period();
127 while (myCurve2->IsPeriodic() && myStart2 >= myEnd2)
128 myEnd2 += myCurve2->Period();
130 if (aBAC1.GetType() == aBAC2.GetType())
132 if (myEnd2 - myStart2 < myEnd1 - myStart1)
133 { // first curve must be parametrically shorter
134 TopoDS_Edge anEdge = myEdge1;
137 Handle(Geom2d_Curve) aCurve = myCurve1;
140 Standard_Real a = myStart1;
146 myEdgesExchnged = Standard_True;
151 //! This function returns true if linear segment from start point of the
152 //! fillet arc to the end point is intersected by the first or second
153 //! curve: in this case fillet is invalid.
154 static Standard_Boolean IsRadiusIntersected(const Handle(Geom2d_Curve)& theCurve, const Standard_Real theCurveMin, const double theCurveMax,
155 const gp_Pnt2d theStart, const gp_Pnt2d theEnd, const Standard_Boolean theStartConnected)
157 //Check the given start and end if they are identical. If yes
159 if (theStart.SquareDistance(theEnd) < Precision::SquareConfusion())
161 return Standard_False;
163 Handle(Geom2d_Line) line = new Geom2d_Line(theStart, gp_Dir2d(gp_Vec2d(theStart, theEnd)));
164 Geom2dAPI_InterCurveCurve anInter(theCurve, line, Precision::Confusion());
167 for(a = anInter.NbPoints(); a > 0; a--)
169 aPoint = anInter.Point(a);
170 Geom2dAPI_ProjectPointOnCurve aProjInt(aPoint, theCurve, theCurveMin, theCurveMax);
171 if (aProjInt.NbPoints() < 1 || aProjInt.LowerDistanceParameter() > Precision::Confusion())
172 continue; // point is not on edge
174 if (aPoint.Distance(theStart) < Precision::Confusion())
176 if (!theStartConnected)
177 return Standard_True;
179 if (aPoint.Distance(theEnd) < Precision::Confusion())
180 return Standard_True;
181 if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), Precision::Angular()))
182 return Standard_True;
184 Handle(Geom2d_Curve) aCurve = theCurve;
185 for(a = anInter.NbSegments(); a > 0; a--)
187 //anInter.Segment(a, aCurve); //not implemented (bug in OCC)
188 aPoint = aCurve->Value(aCurve->FirstParameter());
190 Geom2dAPI_ProjectPointOnCurve aProjInt(aPoint, theCurve, theCurveMin, theCurveMax);
191 if (aProjInt.NbPoints() && aProjInt.LowerDistanceParameter() < Precision::Confusion())
192 { // point is on edge
193 if (aPoint.Distance(theStart) < Precision::Confusion())
194 if (!theStartConnected)
195 return Standard_True;
196 if (aPoint.Distance(theEnd) < Precision::Confusion())
197 return Standard_True;
198 if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), Precision::Angular()))
199 return Standard_True;
201 aPoint = aCurve->Value(aCurve->LastParameter());
203 aProjInt.Init(aPoint, theCurve, theCurveMin, theCurveMax);
204 if (aProjInt.NbPoints() && aProjInt.LowerDistanceParameter() < Precision::Confusion())
205 { // point is on edge
206 if (aPoint.Distance(theStart) < Precision::Confusion())
207 if (!theStartConnected)
208 return Standard_True;
209 if (aPoint.Distance(theEnd) < Precision::Confusion())
210 return Standard_True;
211 if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), Precision::Angular()))
212 return Standard_True;
215 return Standard_False;
218 void ChFi2d_FilletAlgo::FillPoint(FilletPoint* thePoint, const Standard_Real theLimit)
221 // on the intersection point
222 Standard_Boolean aValid = Standard_False;
223 Standard_Real aStep = Precision::Confusion();
224 gp_Pnt2d aCenter, aPoint; // center of fillet and point on curve1
225 Standard_Real aParam = thePoint->getParam();
226 if (theLimit < aParam) aStep = -aStep;
227 for(aValid = Standard_False; !aValid; aParam += aStep)
229 if ((aParam - aStep - theLimit) * (aParam - theLimit) <= 0)
230 break; // limit was exceeded
233 myCurve1->D1(aParam, aPoint, aVec);
234 if (aVec.SquareMagnitude() < Precision::Confusion())
237 gp_Vec2d aPerp(((myStartSide)?-1:1) * aVec.Y(), ((myStartSide)?1:-1) * aVec.X());
239 aPerp.Multiply(myRadius);
240 aCenter = aPoint.Translated(aPerp);
243 Geom2dAPI_ProjectPointOnCurve aProjInt(aPoint, myCurve2, myStart2, myEnd2);
244 if (aProjInt.NbPoints() == 0 || aPoint.Distance(aProjInt.NearestPoint()) > Precision::Confusion())
246 aValid = Standard_True;
252 thePoint->setParam(aParam);
253 thePoint->setCenter(aCenter);
254 aValid = !IsRadiusIntersected(myCurve2, myStart2, myEnd2, aPoint, aCenter, Standard_True);
257 Geom2dAPI_ProjectPointOnCurve aProj(aCenter, myCurve2);
258 int a, aNB = aProj.NbPoints();
259 for(a = aNB; a > 0; a--)
261 if (aPoint.SquareDistance(aProj.Point(a)) < Precision::Confusion())
264 Standard_Boolean aValid2 = aValid;
266 aValid2 = !IsRadiusIntersected(myCurve1, myStart1, myEnd1, aCenter, aProj.Point(a), Standard_False);
268 // checking the right parameter
269 Standard_Real aParamProj = aProj.Parameter(a);
270 while(myCurve2->IsPeriodic() && aParamProj < myStart2)
271 aParamProj += myCurve2->Period();
273 const Standard_Real d = aProj.Distance(a);
274 thePoint->appendValue(d * d - myRadius * myRadius, (aParamProj >= myStart2 && aParamProj <= myEnd2 && aValid2));
275 if (Abs(d - myRadius) < Precision::Confusion())
276 thePoint->setParam2(aParamProj);
280 void ChFi2d_FilletAlgo::FillDiff(FilletPoint* thePoint, Standard_Real theDiffStep, Standard_Boolean theFront)
282 Standard_Real aDelta = theFront?(theDiffStep):(-theDiffStep);
283 FilletPoint* aDiff = new FilletPoint(thePoint->getParam() + aDelta);
284 FillPoint(aDiff, aDelta * 999.);
285 if (!thePoint->calculateDiff(aDiff))
287 aDiff->setParam(thePoint->getParam() - aDelta);
288 FillPoint(aDiff, - aDelta * 999);
289 thePoint->calculateDiff(aDiff);
294 // returns true, if at least one result was found
295 Standard_Boolean ChFi2d_FilletAlgo::Perform(const Standard_Real theRadius)
297 myDegreeOfRecursion = 0;
298 myResultParams.Clear();
299 myResultOrientation.Clear();
301 Standard_Real aNBSteps;
302 Geom2dAdaptor_Curve aGAC(myCurve1);
303 switch (aGAC.GetType())
311 case GeomAbs_Ellipse:
314 case GeomAbs_BSplineCurve:
315 aNBSteps = 2 + aGAC.Degree() * aGAC.NbPoles();
317 default: // unknown: maximum
320 //cout<<"aNBSteps = "<<aNBSteps<<endl;
322 myRadius = theRadius;
323 Standard_Real aParam, aStep, aDStep;
324 aStep = (myEnd1 - myStart1) / aNBSteps;
325 aDStep = 1.e-4 * aStep;
328 for(aCycle = 2, myStartSide = Standard_False; aCycle; myStartSide = !myStartSide, aCycle--)
330 FilletPoint *aLeft = NULL, *aRight;
332 for(aParam = myStart1 + aStep; aParam < myEnd1 || Abs(myEnd1 - aParam) < Precision::Confusion(); aParam += aStep)
336 aLeft = new FilletPoint(aParam - aStep);
337 FillPoint(aLeft, aParam);
338 FillDiff(aLeft, aDStep, Standard_True);
341 aRight = new FilletPoint(aParam);
342 FillPoint(aRight, aParam - aStep);
343 FillDiff(aRight, aDStep, Standard_False);
345 aLeft->FilterPoints(aRight);
346 PerformNewton(aLeft, aRight);
354 return !myResultParams.IsEmpty();
357 Standard_Boolean ChFi2d_FilletAlgo::ProcessPoint(FilletPoint* theLeft, FilletPoint* theRight, Standard_Real theParameter)
359 if (theParameter >= theLeft->getParam() && theParameter < theRight->getParam())
361 Standard_Real aDX = (theRight->getParam() - theLeft->getParam());
362 if (theParameter - theLeft->getParam() < aDX/100.0)
364 theParameter = theLeft->getParam() + aDX/100.0;
366 if (theRight->getParam() - theParameter < aDX/100.0)
368 theParameter = theRight->getParam() - aDX/100.0;
371 // Protection on infinite loops.
372 myDegreeOfRecursion++;
373 Standard_Real diffx = 0.001 * aDX;
374 if (myDegreeOfRecursion > 100)
377 if (myDegreeOfRecursion > 1000)
380 if (myDegreeOfRecursion > 3000)
382 return Standard_True;
387 FilletPoint* aPoint1 = theLeft->Copy();
388 FilletPoint* aPoint2 = new FilletPoint(theParameter);
389 FillPoint(aPoint2, aPoint1->getParam());
390 FillDiff(aPoint2, diffx, Standard_True);
392 aPoint1->FilterPoints(aPoint2);
393 PerformNewton(aPoint1, aPoint2);
394 aPoint2->FilterPoints(theRight);
395 PerformNewton(aPoint2, theRight);
399 return Standard_True;
402 return Standard_False;
405 void ChFi2d_FilletAlgo::PerformNewton(FilletPoint* theLeft, FilletPoint* theRight)
408 // check the left: if this is solution store it and remove it from the list of researching points of theLeft
409 a = theLeft->hasSolution(myRadius);
412 if (theLeft->isValid(a))
414 myResultParams.Append(theLeft->getParam());
415 myResultOrientation.Append(myStartSide);
420 Standard_Real aDX = theRight->getParam() - theLeft->getParam();
421 if (aDX < 1.e-6 * Precision::Confusion())
423 a = theRight->hasSolution(myRadius);
424 if (a && theRight->isValid(a))
426 myResultParams.Append(theRight->getParam());
427 myResultOrientation.Append(myStartSide);
431 for(a = 1; a <= theLeft->getNBValues(); a++)
433 int aNear = theLeft->getNear(a);
435 Standard_Real aA = (theRight->getDiff(aNear) - theLeft->getDiff(a)) / aDX;
436 Standard_Real aB = theLeft->getDiff(a) - aA * theLeft->getParam();
437 Standard_Real aC = theLeft->getValue(a) - theLeft->getDiff(a) * theLeft->getParam() + aA * theLeft->getParam() * theLeft->getParam() / 2.0;
438 Standard_Real aDet = aB * aB - 2.0 * aA * aC;
440 if (Abs(aA) < Precision::Confusion())
443 if (Abs(aB) > 10e-20)
445 Standard_Real aX0 = - aC / aB; // use extremum
446 if (aX0 > theLeft->getParam() && aX0 < theRight->getParam())
447 ProcessPoint(theLeft, theRight, aX0);
451 ProcessPoint(theLeft, theRight, theLeft->getParam() + aDX / 2.0); // linear division otherwise
456 if (Abs(aB) > Abs(aDet * 1000000.))
457 { // possible floating point operations accurancy errors
459 ProcessPoint(theLeft, theRight, theLeft->getParam() + aDX / 2.0); // linear division otherwise
466 Standard_Boolean aRes = ProcessPoint(theLeft, theRight, (- aB + aDet) / aA);
468 aRes = ProcessPoint(theLeft, theRight, (- aB - aDet) / aA);
470 ProcessPoint(theLeft, theRight, theLeft->getParam() + aDX / 2.0); // linear division otherwise
475 Standard_Real aX0 = - aB / aA; // use extremum
476 if (aX0 > theLeft->getParam() && aX0 < theRight->getParam())
477 ProcessPoint(theLeft, theRight, aX0);
479 ProcessPoint(theLeft, theRight, theLeft->getParam() + aDX / 2.0); // linear division otherwise
486 // returns number of possible solutions.
487 int ChFi2d_FilletAlgo::NbResults(const gp_Pnt& thePoint)
489 Standard_Real aX, aY;
490 gp_Pnt2d aTargetPoint2d;
491 ElSLib::PlaneParameters(myPlane->Pln().Position(), thePoint, aX, aY);
492 aTargetPoint2d.SetCoord(aX, aY);
494 //iterate through all possible solutions.
496 TColStd_ListIteratorOfListOfReal anIter(myResultParams);
497 for(; anIter.More(); anIter.Next(), i++)
499 myStartSide = (myResultOrientation.Value(i)) ? Standard_True : Standard_False;
500 FilletPoint *aPoint = new FilletPoint(anIter.Value());
501 FillPoint(aPoint, anIter.Value() + 1.);
502 if (aPoint->hasSolution(myRadius))
510 // returns result (fillet edge, modified edge1, modified edge2), neares to the given point <thePoint>
511 TopoDS_Edge ChFi2d_FilletAlgo::Result(const gp_Pnt& thePoint, TopoDS_Edge& theEdge1, TopoDS_Edge& theEdge2, const int iSolution)
514 gp_Pnt2d aTargetPoint2d;
515 Standard_Real aX, aY;
516 ElSLib::PlaneParameters(myPlane->Pln().Position(), thePoint, aX, aY);
517 aTargetPoint2d.SetCoord(aX, aY);
519 // choose the nearest circle
520 Standard_Real aDistance = 0.0, aP;
521 FilletPoint *aNearest;
523 TColStd_ListIteratorOfListOfReal anIter(myResultParams);
524 for(aNearest = NULL, a = 1; anIter.More(); anIter.Next(), a++)
526 myStartSide = (myResultOrientation.Value(a))?Standard_True:Standard_False;
527 FilletPoint *aPoint = new FilletPoint(anIter.Value());
528 FillPoint(aPoint, anIter.Value() + 1.);
529 if (!aPoint->hasSolution(myRadius))
537 aP = Abs(aPoint->getCenter().Distance(aTargetPoint2d) - myRadius);
539 else if (iSolution == iSol)
543 if (!aNearest || aP < aDistance)
552 if (iSolution == iSol)
560 // create circle edge
561 gp_Pnt aCenter = ElSLib::PlaneValue(aNearest->getCenter().X(), aNearest->getCenter().Y(), myPlane->Pln().Position());
562 Handle(Geom_Circle) aCircle = new Geom_Circle(gp_Ax2(aCenter, myPlane->Pln().Axis().Direction()), myRadius);
563 gp_Pnt2d aPoint2d1, aPoint2d2;
564 myCurve1->D0(aNearest->getParam(), aPoint2d1);
565 myCurve2->D0(aNearest->getParam2(), aPoint2d2);
566 gp_Pnt aPoint1 = ElSLib::PlaneValue(aPoint2d1.X(), aPoint2d1.Y(), myPlane->Pln().Position());
567 gp_Pnt aPoint2 = ElSLib::PlaneValue(aPoint2d2.X(), aPoint2d2.Y(), myPlane->Pln().Position());
569 GeomAPI_ProjectPointOnCurve aProj(thePoint, aCircle);
570 Standard_Real aTargetParam = aProj.LowerDistanceParameter();
571 gp_Pnt aPointOnCircle = aProj.NearestPoint();
573 // There is a bug in Open CASCADE in calculation of nearest point to a circle near the parameter 0.0
574 // Therefore I check this extrema point manually:
575 gp_Pnt p0 = ElCLib::Value(0.0, aCircle->Circ());
576 if (p0.Distance(thePoint) < aPointOnCircle.Distance(thePoint))
582 aProj.Perform(aPoint1);
583 Standard_Real aParam1 = aProj.LowerDistanceParameter();
584 aProj.Perform(aPoint2);
585 Standard_Real aParam2 = aProj.LowerDistanceParameter();
586 Standard_Boolean aIsOut = ((aParam1 < aTargetParam && aParam2 < aTargetParam) || (aParam1 > aTargetParam && aParam2 > aTargetParam));
587 if (aParam1 > aParam2)
589 BRepBuilderAPI_MakeEdge aBuilder(aCircle->Circ(), aIsOut ? aParam2 : aParam1, aIsOut? aParam1 : aParam2);
590 aResult = aBuilder.Edge();
593 Standard_Real aStart, anEnd;
594 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(myEdge1, aStart, anEnd);
596 aCurve->D1(aNearest->getParam(), aPoint1, aDir);
599 aCircle->D1(aParam1, aPoint1, aCircleDir);
601 if ((aCircleDir.Angle(aDir) > M_PI / 2.0) ^ aIsOut)
602 aStart = aNearest->getParam();
604 anEnd = aNearest->getParam();
606 //Check the case when start and end are identical. This happens
607 //when the edge decreases to size 0. Old ww5 allows such
608 //cases. So we are again bug compatible
609 if (fabs(aStart - anEnd) < Precision::Confusion())
610 anEnd = aStart + Precision::Confusion();
612 BRepBuilderAPI_MakeEdge aDivider1(aCurve, aStart, anEnd);
614 theEdge2 = aDivider1.Edge();
616 theEdge1 = aDivider1.Edge();
618 aCurve = BRep_Tool::Curve(myEdge2, aStart, anEnd);
619 aCurve->D1(aNearest->getParam2(), aPoint2, aDir);
621 aCircle->D1(aParam2, aPoint2, aCircleDir);
623 if ((aCircleDir.Angle(aDir) > M_PI / 2.0) ^ (!aIsOut))
624 aStart = aNearest->getParam2();
626 anEnd = aNearest->getParam2();
628 //Check the case when start and end are identical. This happens
629 //when the edge decreases to size 0. Old ww5 allows such
630 //cases. So we are again bug compatible
631 if (fabs(aStart - anEnd) < Precision::Confusion())
632 anEnd = aStart + Precision::Confusion();
633 BRepBuilderAPI_MakeEdge aDivider2(aCurve, aStart, anEnd);
635 theEdge1 = aDivider2.Edge();
637 theEdge2 = aDivider2.Edge();
643 FilletPoint::FilletPoint(const Standard_Real theParam)
644 : myParam (theParam),
649 void FilletPoint::appendValue(Standard_Real theValue, Standard_Boolean theValid)
652 for(a = 1; a <= myV.Length(); a++)
654 if (theValue < myV.Value(a))
656 myV.InsertBefore(a, theValue);
657 myValid.InsertBefore(a, theValid);
661 myV.Append(theValue);
662 myValid.Append(theValid);
665 Standard_Boolean FilletPoint::calculateDiff(FilletPoint* thePoint)
668 Standard_Boolean aDiffsSet = (myD.Length() != 0);
669 Standard_Real aDX = thePoint->getParam() - myParam, aDY = 0.0;
670 if (thePoint->myV.Length() == myV.Length())
671 { // absolutely the same points
672 for(a = 1; a <= myV.Length(); a++)
674 aDY = thePoint->myV.Value(a) - myV.Value(a);
676 myD.SetValue(a, aDY / aDX);
678 myD.Append(aDY / aDX);
680 return Standard_True;
682 // between the diffeerent points searching for nearest analogs
684 for(a = 1; a <= myV.Length(); a++)
686 for(b = 1; b <= thePoint->myV.Length(); b++)
688 if (b == 1 || Abs(thePoint->myV.Value(b) - myV.Value(a)) < Abs(aDY))
689 aDY = thePoint->myV.Value(b) - myV.Value(a);
693 if (Abs(aDY / aDX) < Abs(myD.Value(a)))
694 myD.SetValue(a, aDY / aDX);
698 myD.Append(aDY / aDX);
702 return Standard_False;
705 void FilletPoint::FilterPoints(FilletPoint* thePoint)
707 Standard_Integer a, b;
708 TColStd_SequenceOfReal aDiffs;
709 Standard_Real aY, aY2, aDX = thePoint->getParam() - myParam;
710 for(a = 1; a <= myV.Length(); a++)
712 // searching for near point from thePoint
713 Standard_Integer aNear = 0;
714 Standard_Real aDiff = aDX * 10000.;
715 aY = myV.Value(a) + myD.Value(a) * aDX;
716 for(b = 1; b <= thePoint->myV.Length(); b++)
718 // calculate hypothesis value of the Y2 with the constant first and second derivative
719 aY2 = aY + aDX * (thePoint->myD.Value(b) - myD.Value(a)) / 2.0;
720 if (aNear == 0 || Abs(aY2 - thePoint->myV.Value(b)) < Abs(aDiff))
723 aDiff = aY2 - thePoint->myV.Value(b);
729 if (myV.Value(a) * thePoint->myV.Value(aNear) > 0)
730 {// the same sign at the same sides of the interval
731 if (myV.Value(a) * myD.Value(a) > 0)
733 if (Abs(myD.Value(a)) > Precision::Confusion())
738 if (Abs(myV.Value(a)) > Abs(thePoint->myV.Value(aNear)))
739 if (thePoint->myV.Value(aNear) * thePoint->myD.Value(aNear) < 0 && Abs(thePoint->myD.Value(aNear)) > Precision::Confusion())
749 if (myV.Value(a) * thePoint->myV.Value(aNear) > 0)
751 if ((myV.Value(a) + myD.Value(a) * aDX) * myV.Value(a) > Precision::Confusion() &&
752 (thePoint->myV.Value(aNear) + thePoint->myD.Value(aNear) * aDX) * thePoint->myV.Value(aNear) > Precision::Confusion())
761 if (Abs(aDiff / aDX) > 1.e+7)
768 { // there is no near: remove it from the list
776 Standard_Boolean aFound = Standard_False;
777 for(b = 1; b <= myNear.Length(); b++)
779 if (myNear.Value(b) == aNear)
781 if (Abs(aDiffs.Value(b)) < Abs(aDiff))
782 { // return this 'near'
783 aFound = Standard_True;
791 { // remove the old 'near'
804 myNear.Append(aNear);
805 aDiffs.Append(aDiff);
811 FilletPoint* FilletPoint::Copy()
813 FilletPoint* aCopy = new FilletPoint(myParam);
815 for(a = 1; a <= myV.Length(); a++)
817 aCopy->myV.Append(myV.Value(a));
818 aCopy->myD.Append(myD.Value(a));
819 aCopy->myValid.Append(myValid.Value(a));
824 int FilletPoint::hasSolution(const Standard_Real theRadius)
827 for(a = 1; a <= myV.Length(); a++)
829 if (Abs(sqrt(Abs(Abs(myV.Value(a)) + theRadius * theRadius)) - theRadius) < Precision::Confusion())
835 void FilletPoint::remove(int theIndex)
837 myV.Remove(theIndex);
838 myD.Remove(theIndex);
839 myValid.Remove(theIndex);
840 myNear.Remove(theIndex);