1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : GEOMImpl_Fillet1d.cxx
23 #include "GEOMImpl_Fillet1d.hxx"
25 #include <BRep_Tool.hxx>
26 #include <BRepAdaptor_Curve.hxx>
27 #include <BRepBuilderAPI_MakeEdge.hxx>
30 #include <gp_Circ.hxx>
31 #include <Geom2d_Line.hxx>
32 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
33 #include <Geom2dAPI_InterCurveCurve.hxx>
34 #include <GeomAPI_ProjectPointOnCurve.hxx>
35 #include <GeomProjLib.hxx>
36 #include <Geom_Circle.hxx>
37 #include <Precision.hxx>
38 #include <TColStd_ListIteratorOfListOfReal.hxx>
39 #include <IntRes2d_IntersectionSegment.hxx>
42 #include <Standard_NotImplemented.hxx>
46 * This function returns Standard_True if it is possible to divide edge, i.e.
47 * if one parameter either start or end one is inside the edge. This function
48 * is used in the method GEOMImpl_Fillet1d::Result.
50 * \param theEdge the edge
51 * \param theStart the start parameter
52 * \param theEnd the end parameter
53 * \return Standard_True if it is possible to split edge;
54 * Standard_False otherwise.
56 static Standard_Boolean IsDivideEdge(const TopoDS_Edge &theEdge,
57 const Standard_Real theStart,
58 const Standard_Real theEnd)
62 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, aFirst, aLast);
63 gp_Pnt aPStart = aCurve->Value(theStart);
64 gp_Pnt aPEnd = aCurve->Value(theEnd);
65 TopoDS_Vertex aVFirst = TopExp::FirstVertex(theEdge);
66 TopoDS_Vertex aVLast = TopExp::LastVertex(theEdge);
67 Standard_Real aTolFirst = BRep_Tool::Tolerance(aVFirst);
68 Standard_Real aTolLast = BRep_Tool::Tolerance(aVLast);
69 Standard_Real aTolConf = Precision::Confusion();
70 gp_Pnt aPFirst = BRep_Tool::Pnt(aVFirst);
71 gp_Pnt aPLast = BRep_Tool::Pnt(aVLast);
72 Standard_Real aDistSF = aPStart.Distance(aPFirst);
73 Standard_Real aDistSL = aPStart.Distance(aPLast);
74 Standard_Real aDistEF = aPEnd.Distance(aPFirst);
75 Standard_Real aDistEL = aPEnd.Distance(aPLast);
76 Standard_Boolean isSplit = Standard_True;
78 if (aDistSF <= aTolFirst + aTolConf ||
79 aDistSL <= aTolLast + aTolConf) {
80 if (aDistEF <= aTolFirst + aTolConf ||
81 aDistEL <= aTolLast + aTolConf) {
83 isSplit = Standard_False;
84 // in this case the original edge is thrown, and distance (gap) from new arc end
85 // to a vertex of original wire can reach (aVertexTolerance + Precision::Confusion()).
86 // Resulting wire is fixed (Mantis issue 0023411) in GEOMImpl_Fillet1dDriver::MakeFillet()
94 * class GEOMImpl_Fillet1d
97 //=======================================================================
98 //function : Constructor
100 //=======================================================================
101 GEOMImpl_Fillet1d::GEOMImpl_Fillet1d(const TopoDS_Edge& theEdge1,
102 const TopoDS_Edge& theEdge2,
103 const gp_Pln& thePlane)
104 : myEdgesExchnged( Standard_False )
106 myPlane = new Geom_Plane(thePlane);
108 BRepAdaptor_Curve aBAC1(theEdge1);
109 BRepAdaptor_Curve aBAC2(theEdge2);
110 if (aBAC1.GetType() < aBAC2.GetType())
111 { // first curve must be more complicated
114 myEdgesExchnged = Standard_True;
122 Handle(Geom_Curve) aCurve1 = BRep_Tool::Curve(myEdge1, myStart1, myEnd1);
123 Handle(Geom_Curve) aCurve2 = BRep_Tool::Curve(myEdge2, myStart2, myEnd2);
125 myCurve1 = GeomProjLib::Curve2d(aCurve1, myStart1, myEnd1, myPlane);
126 myCurve2 = GeomProjLib::Curve2d(aCurve2, myStart2, myEnd2, myPlane);
128 while (myCurve1->IsPeriodic() && myStart1 >= myEnd1)
129 myEnd1 += myCurve1->Period();
130 while (myCurve2->IsPeriodic() && myStart2 >= myEnd2)
131 myEnd2 += myCurve2->Period();
133 if (aBAC1.GetType() == aBAC2.GetType())
135 if (myEnd2 - myStart2 < myEnd1 - myStart1)
136 { // first curve must be parametrically shorter
137 TopoDS_Edge anEdge = myEdge1;
140 Handle(Geom2d_Curve) aCurve = myCurve1;
143 Standard_Real a = myStart1;
149 myEdgesExchnged = Standard_True;
154 //=======================================================================
155 //function : isRadiusIntersected
156 //purpose : local function
157 //=======================================================================
158 static Standard_Boolean isRadiusIntersected(const Handle(Geom2d_Curve)& theCurve,
159 const gp_Pnt2d theStart,
160 const gp_Pnt2d theEnd,
161 const Standard_Boolean theStartConnected)
163 const Standard_Real aTol = Precision::Confusion();
164 const Standard_Real anAngTol = Precision::Angular();
165 Handle(Geom2d_Line) aRadiusLine = new Geom2d_Line (theStart, gp_Dir2d(gp_Vec2d(theStart, theEnd)));
166 Geom2dAPI_InterCurveCurve anInter (theCurve, aRadiusLine, aTol);
169 for(a = anInter.NbPoints(); a > 0; a--)
171 aPoint = anInter.Point(a);
172 if ( aPoint.Distance(theStart) < aTol && !theStartConnected )
173 return Standard_True;
174 if (aPoint.Distance(theEnd) < aTol * 200)
175 return Standard_True;
176 if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), anAngTol))
177 return Standard_True;
179 Handle(Geom2d_Curve) aCurve;
180 for(a = anInter.NbSegments(); a > 0; a--)
182 // Porting to DEV version of OCCT 10.02.2017 BEGIN
183 Standard_NotImplemented::Raise("The treatment of tangential intersection is not implemented");
184 // Porting to DEV version of OCCT 10.02.2017 END
186 return Standard_False;
190 //=======================================================================
191 //function : fillPoint
193 //=======================================================================
194 void GEOMImpl_Fillet1d::fillPoint(GEOMImpl_Fillet1dPoint* thePoint)
198 const Standard_Real aTol = Precision::Confusion();
199 myCurve1->D1(thePoint->GetParam(), aPoint, aVec);
200 if (aVec.SquareMagnitude() < aTol)
203 gp_Vec2d aPerp(((myStartSide)?-1:1) * aVec.Y(), ((myStartSide)?1:-1) * aVec.X());
205 aPerp.Multiply(myRadius);
206 gp_Pnt2d aCenter = aPoint.Translated(aPerp);
207 thePoint->SetCenter(aCenter);
209 // on the intersection point
210 Standard_Boolean aValid = Standard_True;
211 Geom2dAPI_ProjectPointOnCurve aProjInt(aPoint, myCurve2);
212 if (aProjInt.NbPoints() && aPoint.Distance(aProjInt.NearestPoint()) < aTol)
213 aValid = Standard_False;
215 aValid = !isRadiusIntersected(myCurve2, aPoint, aCenter, Standard_True);
217 Geom2dAPI_ProjectPointOnCurve aProj(aCenter, myCurve2);
218 Standard_Integer a, aNB = aProj.NbPoints();
219 for(a = aNB; a > 0; a--)
221 if (aPoint.Distance(aProj.Point(a)) < aTol)
224 Standard_Boolean aValid2 = aValid;
226 aValid2 = !isRadiusIntersected(myCurve1, aCenter, aProj.Point(a), Standard_False);
228 // checking the right parameter
229 Standard_Real aParam = aProj.Parameter(a);
230 while(myCurve2->IsPeriodic() && aParam < myStart2)
231 aParam += myCurve2->Period();
233 thePoint->AddValue(aProj.Distance(a) * aProj.Distance(a) - myRadius * myRadius,
234 (aParam >= myStart2 && aParam <= myEnd2 && aValid2));
235 if (fabs(fabs(aProj.Distance(a)) - myRadius) < aTol)
236 thePoint->SetParam2(aParam);
240 //=======================================================================
241 //function : fillDiff
243 //=======================================================================
244 void GEOMImpl_Fillet1d::fillDiff(GEOMImpl_Fillet1dPoint* thePoint, Standard_Real theDiffStep, Standard_Boolean theFront)
246 GEOMImpl_Fillet1dPoint* aDiff =
247 new GEOMImpl_Fillet1dPoint(thePoint->GetParam() + (theFront?(theDiffStep):(-theDiffStep)));
249 if (!thePoint->ComputeDifference(aDiff))
251 aDiff->SetParam(thePoint->GetParam() + (theFront?(-theDiffStep):(theDiffStep)));
253 thePoint->ComputeDifference(aDiff);
258 //=======================================================================
261 //=======================================================================
262 Standard_Boolean GEOMImpl_Fillet1d::Perform(const Standard_Real theRadius)
264 myDegreeOfRecursion = 0;
265 myResultParams.Clear();
266 myResultOrientation.Clear();
268 Standard_Integer aNBSteps = 100;
269 Geom2dAdaptor_Curve aGAC(myCurve1);
270 switch (aGAC.GetType())
278 case GeomAbs_Ellipse:
281 case GeomAbs_BezierCurve:
282 case GeomAbs_BSplineCurve:
283 aNBSteps = 2 + aGAC.Degree() * aGAC.NbPoles();
285 default: // unknown: maximum
289 myRadius = theRadius;
291 // Compute the intervals.
292 const Standard_Real aTol = Precision::Confusion();
293 Geom2dAPI_InterCurveCurve anAPIInter(myCurve1, myCurve2, aTol);
294 const Geom2dInt_GInter &anInter = anAPIInter.Intersector();
295 Standard_Integer aNb = anInter.NbPoints();
297 TColStd_ListOfReal aParams;
298 TColStd_ListIteratorOfListOfReal anIter;
300 // Treat intersection points.
301 for(i = 1; i <= aNb; i++) {
302 const IntRes2d_IntersectionPoint &aPoint = anInter.Point(i);
303 Standard_Real aParam = aPoint.ParamOnFirst();
305 // Adjust parameter on periodic curve.
306 if (myCurve1->IsPeriodic()) {
307 aParam = ElCLib::InPeriod
308 (aParam, myStart1, myStart1 + myCurve1->Period());
311 if (aParam > myStart1 + aTol && aParam < myEnd1 - aTol) {
312 // Add the point in the list in increasing order.
313 for(anIter.Initialize(aParams); anIter.More(); anIter.Next()) {
314 if (anIter.Value() > aParam) {
315 aParams.InsertBefore(aParam, anIter);
320 if (!anIter.More()) {
321 aParams.Append(aParam);
326 // Treat intersection segments.
327 aNb = anInter.NbSegments();
329 for(i = 1; i <= aNb; i++) {
330 const IntRes2d_IntersectionSegment &aSegment = anInter.Segment(i);
332 if (aSegment.HasFirstPoint() && aSegment.HasLastPoint()) {
333 Standard_Real aParam1 = aSegment.FirstPoint().ParamOnFirst();
334 Standard_Real aParam2 = aSegment.LastPoint().ParamOnFirst();
336 // Adjust parameters on periodic curve.
337 if (myCurve1->IsPeriodic()) {
338 ElCLib::AdjustPeriodic(myStart1, myStart1 + myCurve1->Period(),
339 aTol, aParam1, aParam2);
342 if (aParam1 > myStart1 + aTol && aParam1 < myEnd1 - aTol &&
343 aParam2 > myStart1 + aTol && aParam2 < myEnd1 - aTol) {
344 // Add the point in the list in increasing order.
345 const Standard_Real aParam = 0.5*(aParam1 + aParam2);
347 for(anIter.Initialize(aParams); anIter.More(); anIter.Next()) {
348 if (anIter.Value() > aParam) {
349 aParams.InsertBefore(aParam, anIter);
354 if (!anIter.More()) {
355 aParams.Append(aParam);
361 // Add start and end parameters to the list.
362 aParams.Prepend(myStart1);
363 aParams.Append(myEnd1);
364 anIter.Initialize(aParams);
366 // Perform each interval.
367 Standard_Real aStart = anIter.Value();
369 for (anIter.Next(); anIter.More(); anIter.Next()) {
370 const Standard_Real anEnd = anIter.Value();
372 // Perform the interval.
373 performInterval(aStart, anEnd, aNBSteps);
377 if (myResultParams.Extent())
378 return Standard_True;
380 return Standard_False;
383 //=======================================================================
384 //function : performInterval
386 //=======================================================================
387 void GEOMImpl_Fillet1d::performInterval(const Standard_Real theStart,
388 const Standard_Real theEnd,
389 const Standard_Integer theNBSteps)
391 Standard_Real aParam, aStep, aDStep;
392 aStep = (theEnd - theStart) / theNBSteps;
393 aDStep = aStep/1000.;
395 Standard_Integer aCycle;
396 for(aCycle = 2, myStartSide = Standard_False; aCycle; myStartSide = !myStartSide, aCycle--)
398 GEOMImpl_Fillet1dPoint *aLeft = NULL, *aRight = NULL;
400 for(aParam = theStart + aStep; aParam < theEnd || fabs(theEnd - aParam) < Precision::Confusion(); aParam += aStep)
404 aLeft = new GEOMImpl_Fillet1dPoint(aParam - aStep);
406 fillDiff(aLeft, aDStep, Standard_True);
409 aRight = new GEOMImpl_Fillet1dPoint(aParam);
411 fillDiff(aRight, aDStep, Standard_False);
413 aLeft->FilterPoints(aRight);
414 performNewton(aLeft, aRight);
423 //=======================================================================
424 //function : processPoint
426 //=======================================================================
427 Standard_Boolean GEOMImpl_Fillet1d::processPoint(GEOMImpl_Fillet1dPoint* theLeft,
428 GEOMImpl_Fillet1dPoint* theRight,
429 Standard_Real theParameter)
431 if (theParameter >= theLeft->GetParam() && theParameter < theRight->GetParam())
433 Standard_Real aDX = theRight->GetParam() - theLeft->GetParam();
434 if (theParameter - theLeft->GetParam() < aDX / 100.)
436 theParameter = theLeft->GetParam() + aDX / 100.;
438 if (theRight->GetParam() - theParameter < aDX / 100.)
440 theParameter = theRight->GetParam() - aDX / 100.;
443 // Protection on infinite loop.
444 myDegreeOfRecursion++;
445 Standard_Real diffx = 0.001 * aDX;
446 if (myDegreeOfRecursion > 1000)
449 if (myDegreeOfRecursion > 10000)
452 if (myDegreeOfRecursion > 100000)
454 return Standard_True;
459 GEOMImpl_Fillet1dPoint* aPoint1 = theLeft->Copy();
460 GEOMImpl_Fillet1dPoint* aPoint2 = new GEOMImpl_Fillet1dPoint(theParameter);
462 fillDiff(aPoint2, diffx, Standard_True);
464 aPoint1->FilterPoints(aPoint2);
465 performNewton(aPoint1, aPoint2);
466 aPoint2->FilterPoints(theRight);
467 performNewton(aPoint2, theRight);
471 return Standard_True;
474 return Standard_False;
477 //=======================================================================
478 //function : performNewton
480 //=======================================================================
481 void GEOMImpl_Fillet1d::performNewton(GEOMImpl_Fillet1dPoint* theLeft,
482 GEOMImpl_Fillet1dPoint* theRight)
485 // check the left: if this is solution store it and remove it from the list of researching points of theLeft
486 a = theLeft->HasSolution(myRadius);
489 if (theLeft->IsValid(a))
491 myResultParams.Append(theLeft->GetParam());
492 myResultOrientation.Append(myStartSide);
497 Standard_Real aDX = theRight->GetParam() - theLeft->GetParam();
498 if ( aDX < Precision::Confusion() / 1000000.)
500 a = theRight->HasSolution(myRadius);
502 if (theRight->IsValid(a))
504 myResultParams.Append(theRight->GetParam());
505 myResultOrientation.Append(myStartSide);
510 for(a = 1; a <= theLeft->GetNBValues(); a++)
512 Standard_Integer aNear = theLeft->GetNear(a);
514 Standard_Real aA = (theRight->GetDiff(aNear) - theLeft->GetDiff(a)) / aDX;
515 Standard_Real aB = theLeft->GetDiff(a) - aA * theLeft->GetParam();
516 Standard_Real aC = theLeft->GetValue(a) - theLeft->GetDiff(a) * theLeft->GetParam() +
517 aA * theLeft->GetParam() * theLeft->GetParam() / 2.0;
518 Standard_Real aDet = aB * aB - 2.0 * aA * aC;
520 if ( fabs(aDet) < gp::Resolution() )
523 if (fabs(aA) < Precision::Confusion())
525 if (fabs(aB) > 10e-20)
527 Standard_Real aX0 = - aC / aB; // use extremum
528 if (aX0 > theLeft->GetParam() && aX0 < theRight->GetParam())
529 processPoint(theLeft, theRight, aX0);
533 processPoint(theLeft, theRight, theLeft->GetParam() + aDX / 2.0); // linear division otherwise
538 if (fabs(aB) > fabs(aDet * 1000000.))
539 { // possible floating point operations accuracy errors
540 processPoint(theLeft, theRight, theLeft->GetParam() + aDX / 2.0); // linear division otherwise
547 Standard_Boolean aRes = processPoint(theLeft, theRight, (- aB + aDet) / aA);
549 aRes = processPoint(theLeft, theRight, (- aB - aDet) / aA);
551 processPoint(theLeft, theRight, theLeft->GetParam() + aDX / 2.0); // linear division otherwise
555 Standard_Real aX0 = - aB / aA; // use extremum
556 if (aX0 > theLeft->GetParam() && aX0 < theRight->GetParam())
557 processPoint(theLeft, theRight, aX0);
559 processPoint(theLeft, theRight, theLeft->GetParam() + aDX / 2.0); // linear division otherwise
566 //=======================================================================
569 //=======================================================================
570 TopoDS_Edge GEOMImpl_Fillet1d::Result(const gp_Pnt& thePoint,
571 TopoDS_Edge& theEdge1,
572 TopoDS_Edge& theEdge2)
575 gp_Pnt2d aTargetPoint2d;
576 Standard_Real aX, aY;
577 ElSLib::PlaneParameters(myPlane->Pln().Position(), thePoint, aX, aY);
578 aTargetPoint2d.SetCoord(aX, aY);
580 // choose the nearest circle
581 Standard_Real aDistance, aP;
582 GEOMImpl_Fillet1dPoint *aNearest;
584 TColStd_ListIteratorOfListOfReal anIter(myResultParams);
585 for(aNearest = NULL, a = 1; anIter.More(); anIter.Next(), a++)
587 myStartSide = (myResultOrientation.Value(a)) ? Standard_True : Standard_False;
588 GEOMImpl_Fillet1dPoint *aPoint = new GEOMImpl_Fillet1dPoint(anIter.Value());
590 if (!aPoint->HasSolution(myRadius))
592 aP = fabs(aPoint->GetCenter().Distance(aTargetPoint2d) - myRadius);
593 if (!aNearest || aP < aDistance)
607 // create circle edge
608 gp_Pnt aCenter = ElSLib::PlaneValue(aNearest->GetCenter().X(),
609 aNearest->GetCenter().Y(),
610 myPlane->Pln().Position());
611 Handle(Geom_Circle) aCircle =
612 new Geom_Circle(gp_Ax2(aCenter, myPlane->Pln().Axis().Direction()), myRadius);
613 gp_Pnt2d aPoint2d1, aPoint2d2;
614 myCurve1->D0(aNearest->GetParam(), aPoint2d1);
615 myCurve2->D0(aNearest->GetParam2(), aPoint2d2);
616 gp_Pnt aPoint1 = ElSLib::PlaneValue(aPoint2d1.X(), aPoint2d1.Y(), myPlane->Pln().Position());
617 gp_Pnt aPoint2 = ElSLib::PlaneValue(aPoint2d2.X(), aPoint2d2.Y(), myPlane->Pln().Position());
619 GeomAPI_ProjectPointOnCurve aProj(thePoint, aCircle);
620 Standard_Real aTarGetParam = aProj.LowerDistanceParameter();
621 gp_Pnt aPointOnCircle = aProj.NearestPoint();
623 // Check extrema point manually, because there is a bug in Open CASCADE
624 // in calculation of nearest point to a circle near the parameter 0.0
625 gp_Pnt p0 = ElCLib::Value(0.0, aCircle->Circ());
626 if (p0.Distance(thePoint) < aPointOnCircle.Distance(thePoint))
632 aProj.Perform(aPoint1);
633 Standard_Real aParam1 = aProj.LowerDistanceParameter();
634 aProj.Perform(aPoint2);
635 Standard_Real aParam2 = aProj.LowerDistanceParameter();
636 Standard_Boolean aIsOut = ((aParam1 < aTarGetParam && aParam2 < aTarGetParam) ||
637 (aParam1 > aTarGetParam && aParam2 > aTarGetParam));
638 if (aParam1 > aParam2)
640 BRepBuilderAPI_MakeEdge aBuilder(aCircle->Circ(),
641 aIsOut ? aParam2 : aParam1,
642 aIsOut? aParam1 : aParam2);
643 aResult = aBuilder.Edge();
646 Standard_Real aStart, anEnd;
647 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(myEdge1, aStart, anEnd);
649 aCurve->D1(aNearest->GetParam(), aPoint1, aDir);
652 aCircle->D1(aParam1, aPoint1, aCircleDir);
653 if ((aCircleDir.Angle(aDir) > M_PI / 2.0) ^ aIsOut)
654 aStart = aNearest->GetParam();
656 anEnd = aNearest->GetParam();
658 if (IsDivideEdge(myEdge1, aStart, anEnd))
661 BRepBuilderAPI_MakeEdge aDivider1(aCurve, aStart, anEnd);
663 theEdge2 = aDivider1.Edge();
665 theEdge1 = aDivider1.Edge();
668 aCurve = BRep_Tool::Curve(myEdge2, aStart, anEnd);
669 aCurve->D1(aNearest->GetParam2(), aPoint2, aDir);
671 aCircle->D1(aParam2, aPoint2, aCircleDir);
672 if ((aCircleDir.Angle(aDir) > M_PI / 2.0) ^ (!aIsOut))
673 aStart = aNearest->GetParam2();
675 anEnd = aNearest->GetParam2();
677 if (IsDivideEdge(myEdge2, aStart, anEnd))
679 BRepBuilderAPI_MakeEdge aDivider2(aCurve, aStart, anEnd);
681 theEdge1 = aDivider2.Edge();
683 theEdge2 = aDivider2.Edge();
690 //=======================================================================
691 //function : AddValue
693 //=======================================================================
694 void GEOMImpl_Fillet1dPoint::AddValue(Standard_Real theValue, Standard_Boolean theValid)
697 for(a = 1; a <= myV.Length(); a++)
699 if (theValue < myV.Value(a))
701 myV.InsertBefore(a, theValue);
702 myValid.InsertBefore(a, (Standard_Integer)theValid);
706 myV.Append(theValue);
707 myValid.Append((Standard_Integer)theValid);
710 //=======================================================================
711 //function : ComputeDifference
713 //=======================================================================
714 Standard_Boolean GEOMImpl_Fillet1dPoint::ComputeDifference(GEOMImpl_Fillet1dPoint* thePoint)
717 Standard_Boolean aDiffsSet = (myD.Length() != 0);
718 Standard_Real aDX = thePoint->GetParam() - myParam, aDY;
719 if (thePoint->myV.Length() == myV.Length())
720 { // absolutely the same points
721 for(a = 1; a <= myV.Length(); a++)
723 aDY = thePoint->myV.Value(a) - myV.Value(a);
725 myD.SetValue(a, fabs(aDX) > gp::Resolution() ? (aDY/aDX) : 0);
727 myD.Append( fabs(aDX) > gp::Resolution() ? (aDY/aDX) : 0);
729 return Standard_True;
731 // between the diffeerent points searching for nearest analogs
733 for(a = 1; a <= myV.Length(); a++)
735 for(b = 1; b <= thePoint->myV.Length(); b++)
737 if (b == 1 || fabs(thePoint->myV.Value(b) - myV.Value(a)) < fabs(aDY))
738 aDY = thePoint->myV.Value(b) - myV.Value(a);
742 if ( fabs(aDX) > gp::Resolution() && fabs(aDY / aDX) < fabs(myD.Value(a)))
743 myD.SetValue(a, aDY / aDX);
749 myD.Append( fabs(aDX) > gp::Resolution() ? aDY/aDX : 0);
753 return Standard_False;
756 //=======================================================================
757 //function : FilterPoints
759 //=======================================================================
760 void GEOMImpl_Fillet1dPoint::FilterPoints(GEOMImpl_Fillet1dPoint* thePoint)
762 Standard_Integer a, b;
763 TColStd_SequenceOfReal aDiffs;
764 Standard_Real aY, aY2, aDX = thePoint->GetParam() - myParam;
765 for(a = 1; a <= myV.Length(); a++)
767 // searching for near point from thePoint
768 Standard_Integer aNear = 0;
769 Standard_Real aDiff = aDX * 10000.;
770 aY = myV.Value(a) + myD.Value(a) * aDX;
771 for(b = 1; b <= thePoint->myV.Length(); b++)
773 // calculate hypothesis value of the Y2 with the constant first and second derivative
774 aY2 = aY + aDX * (thePoint->myD.Value(b) - myD.Value(a)) / 2.0;
775 if (aNear == 0 || fabs(aY2 - thePoint->myV.Value(b)) < fabs(aDiff))
778 aDiff = aY2 - thePoint->myV.Value(b);
784 if (myV.Value(a) * thePoint->myV.Value(aNear) > 0)
785 {// the same sign at the same sides of the interval
786 if (myV.Value(a) * myD.Value(a) > 0)
788 if (fabs(myD.Value(a)) > Precision::Confusion())
793 if (fabs(myV.Value(a)) > fabs(thePoint->myV.Value(aNear)))
794 if (thePoint->myV.Value(aNear) * thePoint->myD.Value(aNear) < 0 &&
795 fabs(thePoint->myD.Value(aNear)) > Precision::Confusion())
805 if (myV.Value(a) * thePoint->myV.Value(aNear) > 0)
807 if ((myV.Value(a) + myD.Value(a) * aDX) * myV.Value(a) > Precision::Confusion() &&
808 (thePoint->myV.Value(aNear) + thePoint->myD.Value(aNear) * aDX) * thePoint->myV.Value(aNear) > Precision::Confusion())
817 if ( fabs(aDX) < gp::Resolution() || fabs(aDiff / aDX) > 1.e+7)
824 { // there is no near: remove it from the list
832 Standard_Boolean aFound = Standard_False;
833 for(b = 1; b <= myNear.Length(); b++)
835 if (myNear.Value(b) == aNear)
837 if (fabs(aDiffs.Value(b)) < fabs(aDiff))
838 { // return this 'near'
839 aFound = Standard_True;
847 { // remove the old 'near'
860 myNear.Append(aNear);
861 aDiffs.Append(aDiff);
867 //=======================================================================
870 //=======================================================================
871 GEOMImpl_Fillet1dPoint* GEOMImpl_Fillet1dPoint::Copy()
873 GEOMImpl_Fillet1dPoint* aCopy = new GEOMImpl_Fillet1dPoint(myParam);
875 for(a = 1; a <= myV.Length(); a++)
877 aCopy->myV.Append(myV.Value(a));
878 aCopy->myD.Append(myD.Value(a));
879 aCopy->myValid.Append(myValid.Value(a));
884 //=======================================================================
885 //function : HasSolution
887 //=======================================================================
888 Standard_Integer GEOMImpl_Fillet1dPoint::HasSolution(const Standard_Real theRadius)
891 for(a = 1; a <= myV.Length(); a++)
893 if (fabs(sqrt(fabs(fabs(myV.Value(a)) + theRadius * theRadius)) - theRadius) < Precision::Confusion() / 10.)
899 //=======================================================================
900 //function : RemoveSolution
902 //=======================================================================
903 void GEOMImpl_Fillet1dPoint::RemoveSolution(Standard_Integer theIndex)
905 myV.Remove(theIndex);
906 myD.Remove(theIndex);
907 myValid.Remove(theIndex);
908 myNear.Remove(theIndex);