0021762: Integration of new Boolean Operation algorithm to OCCT.
[occt.git] / src / BOPTools / BOPTools_AlgoTools2D.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #include <BOPTools_AlgoTools2D.ixx>
21
22 #include <Standard_NotImplemented.hxx>
23 #include <Precision.hxx>
24 #include <gp.hxx>
25
26 #include <gp_Pnt.hxx>
27 #include <gp_Pnt2d.hxx>
28 #include <gp_Vec.hxx>
29 #include <gp_Vec2d.hxx>
30
31 #include <Geom2d_Curve.hxx>
32 #include <Geom2d_Line.hxx>
33 #include <Geom2d_Circle.hxx>
34 #include <Geom2d_Ellipse.hxx>
35 #include <Geom2d_Parabola.hxx>
36 #include <Geom2d_Hyperbola.hxx>
37
38 #include <Geom_Curve.hxx>
39 #include <GeomAdaptor_HCurve.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <Geom_Surface.hxx>
42
43 #include <TopLoc_Location.hxx>
44 #include <TopExp.hxx>
45
46 #include <ProjLib_ProjectedCurve.hxx>
47
48 #include <BRep_Tool.hxx>
49 #include <BRepTools.hxx>
50 #include <BRepAdaptor_HSurface.hxx>
51 #include <BRepAdaptor_Curve.hxx>
52 #include <BRep_Builder.hxx>
53 #include <BRepAdaptor_Surface.hxx>
54 #include <Geom2d_Curve.hxx>
55 #include <Geom_Plane.hxx>
56 #include <Geom_RectangularTrimmedSurface.hxx>
57 #include <BRep_Builder.hxx>
58 #include <Geom_Surface.hxx>
59 #include <BOPCol_IndexedMapOfShape.hxx>
60 #include <BOPTools.hxx>
61
62
63 static 
64   Standard_Boolean CheckEdgeLength (const TopoDS_Edge& E);
65
66 //=======================================================================
67 //function : BuildPCurveForEdgeOnFace
68 //purpose  : 
69 //=======================================================================
70   void BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace (const TopoDS_Edge& aE,
71                                                    const TopoDS_Face& aF)
72 {
73   BRep_Builder aBB;
74   Handle(Geom2d_Curve) aC2D;
75   Standard_Real  aTolPC, aTolFact, aTolEdge, aFirst, aLast;
76   
77   Standard_Boolean aHasOld;
78   aHasOld=BOPTools_AlgoTools2D::HasCurveOnSurface (aE, aF, aC2D, aFirst, aLast, aTolEdge);
79   if (aHasOld) {
80     return;
81   }
82   
83
84   BOPTools_AlgoTools2D::CurveOnSurface(aE, aF, aC2D, aTolPC);
85   
86   aTolEdge=BRep_Tool::Tolerance(aE);
87
88   aTolFact=Max(aTolEdge, aTolPC);
89
90   aBB.UpdateEdge(aE, aC2D, aF, aTolFact);
91   return;
92 }
93
94 //=======================================================================
95 //function : EdgeTangent
96 //purpose  : 
97 //=======================================================================
98   Standard_Boolean BOPTools_AlgoTools2D::EdgeTangent(const TopoDS_Edge& anEdge, 
99                                                  const Standard_Real aT,
100                                                  gp_Vec& aTau)
101 {
102   Standard_Boolean isdgE;
103   Standard_Real first, last;
104   
105   isdgE = BRep_Tool::Degenerated(anEdge); 
106   if (isdgE) {
107     return Standard_False;
108   }
109   if (!CheckEdgeLength(anEdge)) {
110     return Standard_False;
111   }
112
113   Handle(Geom_Curve) aC=BRep_Tool::Curve(anEdge, first, last);
114   gp_Pnt aP;
115   aC->D1(aT, aP, aTau);
116   Standard_Real mod = aTau.Magnitude();
117   if(mod > gp::Resolution()) {
118     aTau /= mod;
119   }
120   else {
121     return Standard_False;
122   }
123   //aTau.Normalize(); 
124   if (anEdge.Orientation() == TopAbs_REVERSED){
125     aTau.Reverse();
126   }
127   return Standard_True;
128 }
129
130 //=======================================================================
131 //function : PointOnOnSurface
132 //purpose  : 
133 //=======================================================================
134   void BOPTools_AlgoTools2D::PointOnSurface (const TopoDS_Edge& aE,
135                                          const TopoDS_Face& aF,
136                                          const Standard_Real aParameter,
137                                          Standard_Real& U,
138                                          Standard_Real& V)
139 {
140   gp_Pnt2d aP2D;
141   Handle(Geom2d_Curve) aC2D;
142   Standard_Real aToler, aFirst, aLast;
143
144   BOPTools_AlgoTools2D::CurveOnSurface (aE, aF, aC2D, aFirst, aLast, aToler); 
145   aC2D->D0(aParameter, aP2D);
146   U=aP2D.X();
147   V=aP2D.Y();
148   return;
149 }
150
151 //=======================================================================
152 //function : CurveOnSurface
153 //purpose  : 
154 //=======================================================================
155   void BOPTools_AlgoTools2D::CurveOnSurface (const TopoDS_Edge& aE,
156                                          const TopoDS_Face& aF,
157                                          Handle(Geom2d_Curve)& aC2D,
158                                          Standard_Real& aToler)
159 {
160   Standard_Real aFirst, aLast; 
161
162   BOPTools_AlgoTools2D::CurveOnSurface (aE, aF, aC2D, aFirst, aLast, aToler); 
163
164   return;
165 }
166 //=======================================================================
167 //function : CurveOnSurface
168 //purpose  : 
169 //=======================================================================
170   void BOPTools_AlgoTools2D::CurveOnSurface (const TopoDS_Edge& aE,
171                                          const TopoDS_Face& aF,
172                                          Handle(Geom2d_Curve)& aC2D,
173                                          Standard_Real& aFirst,
174                                          Standard_Real& aLast,
175                                          Standard_Real& aToler)
176 {
177   Standard_Boolean aHasOld;
178   Handle(Geom2d_Curve) C2D;
179
180   aHasOld=BOPTools_AlgoTools2D::HasCurveOnSurface (aE, aF, C2D, aFirst, aLast, aToler);
181   if (aHasOld) {
182     aC2D=C2D;
183     return;
184   }
185
186   BOPTools_AlgoTools2D::Make2D(aE, aF, C2D, aFirst, aLast, aToler);
187   aC2D=C2D;
188   return;
189 }
190
191 //=======================================================================
192 //function : HasCurveOnSurface
193 //purpose  : 
194 //=======================================================================
195   Standard_Boolean BOPTools_AlgoTools2D::HasCurveOnSurface (const TopoDS_Edge& aE,
196                                                         const TopoDS_Face& aF,
197                                                         Handle(Geom2d_Curve)& aC2D,
198                                                         Standard_Real& aFirst,
199                                                         Standard_Real& aLast,
200                                                         Standard_Real& aToler)
201 {
202   Standard_Boolean aHasOld;
203   
204   aToler=BRep_Tool::Tolerance(aE);
205   BRep_Tool::Range(aE, aFirst, aLast);
206
207   if((aLast - aFirst) < Precision::PConfusion()) {
208     return Standard_False;
209   }
210
211   aC2D  =BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
212   aHasOld=!aC2D.IsNull();
213   return aHasOld;
214 }
215 //=======================================================================
216 //function : HasCurveOnSurface
217 //purpose  : 
218 //=======================================================================
219   Standard_Boolean BOPTools_AlgoTools2D::HasCurveOnSurface (const TopoDS_Edge& aE,
220                                                         const TopoDS_Face& aF)
221                                                    
222 {
223   Standard_Boolean aHasOld;
224   Handle(Geom2d_Curve) aC2D;
225   Standard_Real aFirst, aLast;
226   BRep_Tool::Range(aE, aFirst, aLast);
227
228   if((aLast - aFirst) < Precision::PConfusion()) {
229     return Standard_False;
230   }
231
232   aC2D  =BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
233   aHasOld=!aC2D.IsNull();
234   return aHasOld;
235 }
236
237 //=======================================================================
238 //function : AdjustPCurveOnFace
239 //purpose  : 
240 //=======================================================================
241   void BOPTools_AlgoTools2D::AdjustPCurveOnFace (const TopoDS_Face& aF,
242                                              const Handle(Geom_Curve)&   aC3D,
243                                              const Handle(Geom2d_Curve)& aC2D, 
244                                              Handle(Geom2d_Curve)& aC2DA)
245 {
246   Standard_Real first, last;
247
248   first = aC3D -> FirstParameter();
249   last  = aC3D -> LastParameter();
250  
251   BOPTools_AlgoTools2D::AdjustPCurveOnFace (aF, first, last, aC2D, aC2DA);
252
253 //=======================================================================
254 //function : AdjustPCurveOnFace
255 //purpose  : 
256 //=======================================================================
257   void BOPTools_AlgoTools2D::AdjustPCurveOnFace (const TopoDS_Face& aF,
258                                              const Standard_Real aFirst,
259                                              const Standard_Real aLast,
260                                              const Handle(Geom2d_Curve)& aC2D, 
261                                              Handle(Geom2d_Curve)& aC2DA)
262 {
263   Standard_Boolean mincond, maxcond, decalu, decalv;
264   Standard_Integer k, iCnt;
265   Standard_Real UMin, UMax, VMin, VMax, aT, u2, v2, du, dv, aDelta;
266   Standard_Real aUPeriod, aUP2, aUP1, aUNew, aDif, aUx;
267   //
268   aDelta=Precision::PConfusion();
269   
270   BRepAdaptor_Surface aBAS(aF, Standard_False);
271  
272   BRepTools::UVBounds(aF, UMin, UMax, VMin, VMax);
273   
274   aT =.5*(aFirst+aLast);
275
276   gp_Pnt2d pC2D; 
277   aC2D->D0(aT, pC2D);
278
279   u2 = pC2D.X();
280   v2 = pC2D.Y();
281  
282   du = 0.;
283   if (aBAS.IsUPeriodic()) {
284     aUPeriod=aBAS.UPeriod(); 
285     mincond = (u2 < UMin-aDelta);
286     maxcond = (u2 > UMax+aDelta); 
287     
288     decalu = mincond || maxcond;
289     if (decalu) {
290       //du = ( mincond ) ? UPeriod : -UPeriod;
291       //
292       iCnt=1;
293       aUP2=aUPeriod+aUPeriod+aDelta;
294       aUP1=aUPeriod+aDelta;
295       //
296       if (u2 > aUP2) {
297         for(k=1; 1; ++k) {
298           aUx=u2-k*aUPeriod;
299           if (aUx < aUP1) {
300             iCnt=k;
301             break;
302           }
303         }
304       }
305       else if (u2 < -aUP2) {
306         for(k=1; 1; ++k) {
307           aUx=u2+k*aUPeriod;
308           if (aUx > -aUP1) {
309             iCnt=k+1;
310             break;
311           }
312         }
313       }
314       du = ( mincond ) ? aUPeriod : -aUPeriod;
315       du=iCnt*du;
316     }
317     //
318     aUNew=u2+du;
319     if (aUNew<(UMin-aDelta) || 
320         aUNew>(UMax+aDelta)) {
321       // So previous correction was wrong.
322       // Try to be closer to UMin or UMax.
323       du=0.;
324       if (u2>UMax){
325         aDif=u2-UMax;
326         if (aDif < 4.e-7) {
327           du=-aDif;
328         }
329       }
330     }
331   } // if (BAHS->IsUPeriodic())
332   //
333   // dv
334   dv = 0.;
335   if (aBAS.IsVPeriodic()) {
336     Standard_Real aVPeriod, aVm, aVr, aVmid, dVm, dVr;
337     //
338     aVPeriod=aBAS.VPeriod();
339     mincond = (VMin - v2 > aDelta);
340     maxcond = (v2 - VMax > aDelta);
341     decalv = mincond || maxcond;
342     if (decalv) {
343       dv = ( mincond ) ? aVPeriod : -aVPeriod;
344     }
345     //
346     //xf
347     if ((VMax-VMin<aVPeriod) && dv) {
348       aVm=v2;
349       aVr=v2+dv;
350       aVmid=0.5*(VMin+VMax);
351       dVm=fabs(aVm-aVmid);
352       dVr=fabs(aVr-aVmid);
353       if (dVm<dVr) {
354         dv=0.;
355       }
356     }
357     //xt
358   }
359   //
360   // Translation if necessary
361   Handle(Geom2d_Curve) aC2Dx=aC2D;
362
363   if ( du != 0. || dv != 0.) {
364     Handle(Geom2d_Curve) PCT = Handle(Geom2d_Curve)::DownCast(aC2Dx->Copy());
365     gp_Vec2d aV2D(du,dv);
366     PCT->Translate(aV2D);
367     aC2Dx = PCT;
368   }
369
370   aC2DA=aC2Dx;
371 }
372
373 //=======================================================================
374 //function : IntermediatePoint
375 //purpose  : 
376 //=======================================================================
377   Standard_Real BOPTools_AlgoTools2D::IntermediatePoint (const Standard_Real aFirst,
378                                                      const Standard_Real aLast)
379 {
380   //define parameter division number as 10*e^(-PI) = 0.43213918
381   const Standard_Real PAR_T = 0.43213918;
382   Standard_Real aParm;
383   aParm=(1.-PAR_T)*aFirst + PAR_T*aLast;
384   return aParm;
385 }
386 //=======================================================================
387 //function : IntermediatePoint
388 //purpose  : 
389 //=======================================================================
390   Standard_Real BOPTools_AlgoTools2D::IntermediatePoint (const TopoDS_Edge& aE)
391                                                 
392 {
393   Standard_Real aT, aT1, aT2;
394
395   Handle(Geom_Curve)aC1=BRep_Tool::Curve(aE, aT1, aT2);
396   if (aC1.IsNull())
397     BRep_Tool::Range(aE, aT1, aT2);
398
399   aT=BOPTools_AlgoTools2D::IntermediatePoint(aT1, aT2);
400   return aT;
401 }
402
403 //=======================================================================
404 //function : BuildPCurveForEdgeOnPlane
405 //purpose  : 
406 //=======================================================================
407   void BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane (const TopoDS_Edge& aE,
408                                                     const TopoDS_Face& aF)
409
410   Standard_Real aTolE;
411   TopLoc_Location aLoc;
412   Handle(Geom2d_Curve) aC2D;
413   Handle(Geom_Plane) aGP;
414   Handle(Geom_RectangularTrimmedSurface) aGRTS;
415   BRep_Builder aBB;
416   //
417   const Handle(Geom_Surface)& aS = BRep_Tool::Surface(aF, aLoc);
418   aGRTS=Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
419   if(!aGRTS.IsNull()){
420     aGP=Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
421     }    
422   else {
423     aGP=Handle(Geom_Plane)::DownCast(aS);
424   }
425   //
426   if (aGP.IsNull()) {
427     return;
428   }
429   //
430   BOPTools_AlgoTools2D::CurveOnSurface(aE, aF, aC2D, aTolE);
431   aBB.UpdateEdge(aE, aC2D, aF, aTolE);
432   //
433   return;
434 }
435
436 //=======================================================================
437 //function : Make2D
438 //purpose  : 
439 //=======================================================================
440   void BOPTools_AlgoTools2D::Make2D (const TopoDS_Edge& aE,
441                                  const TopoDS_Face& aF,
442                                  Handle(Geom2d_Curve)& aC2D,
443                                  Standard_Real& aFirst,
444                                  Standard_Real& aLast,
445                                  Standard_Real& aToler)
446 {
447   Standard_Boolean aLocIdentity;
448   Standard_Real f3d, l3d;
449   TopLoc_Location aLoc;
450
451   Handle(Geom2d_Curve) C2D; 
452   
453   
454   C2D=BRep_Tool::CurveOnSurface(aE, aF, aFirst, aLast);
455   
456   if (!C2D.IsNull()) {
457     aC2D=C2D;
458     return;
459   }
460
461   Handle(Geom_Curve) C3D2, C3D;
462   C3D = BRep_Tool::Curve(aE, aLoc, f3d, l3d);
463   //
464   if (C3D.IsNull()) { 
465     // aE has no 3D curve, so nothing is done
466   }
467   //
468   aLocIdentity=aLoc.IsIdentity();
469     
470   if (aLocIdentity) {
471     C3D2 = C3D;
472   }
473   else {
474     C3D2 = Handle(Geom_Curve)::
475       DownCast(C3D->Transformed(aLoc.Transformation()));
476   }
477   
478   //
479   aToler=.5*BRep_Tool::Tolerance(aE);
480   BOPTools_AlgoTools2D::MakePCurveOnFace(aF, C3D2, f3d, l3d, aC2D, aToler);
481   //
482   aFirst = f3d; 
483   aLast  = l3d;
484 }
485
486 //=======================================================================
487 //function : MakePCurveOnFace
488 //purpose  : 
489 //=======================================================================
490   void BOPTools_AlgoTools2D::MakePCurveOnFace (const TopoDS_Face& aF,
491                                            const Handle(Geom_Curve)& aC3D,
492                                            Handle(Geom2d_Curve)& aC2D, //->
493                                            Standard_Real& TolReached2d)
494 {
495   Standard_Real aFirst, aLast;
496
497   aFirst = aC3D -> FirstParameter();
498   aLast  = aC3D -> LastParameter();
499   //
500   TolReached2d=0.;
501   //
502   BOPTools_AlgoTools2D::MakePCurveOnFace (aF, aC3D, aFirst, aLast, aC2D, TolReached2d);
503 }
504
505 //=======================================================================
506 //function : MakePCurveOnFace
507 //purpose  : 
508 //=======================================================================
509   void BOPTools_AlgoTools2D::MakePCurveOnFace (const TopoDS_Face& aF,
510                                            const Handle(Geom_Curve)& aC3D,
511                                            const Standard_Real aFirst,
512                                            const Standard_Real aLast,
513                                            Handle(Geom2d_Curve)& aC2D, 
514                                            Standard_Real& TolReached2d)
515 {
516   Standard_Real aTolR;
517   Handle(Geom2d_Curve) aC2DA;
518
519   BRepAdaptor_Surface aBAS(aF, Standard_False);
520   Handle(BRepAdaptor_HSurface) aBAHS = new BRepAdaptor_HSurface(aBAS);
521   Handle(GeomAdaptor_HCurve)   aBAHC = new GeomAdaptor_HCurve(aC3D, aFirst, aLast);
522   
523   //when the type of surface is GeomAbs_SurfaceOfRevolution
524   if (aBAS.GetType() == GeomAbs_SurfaceOfRevolution) {
525     Standard_Real aTR = 1.e-7;
526     ProjLib_ProjectedCurve aProj1(aBAHS, aBAHC, aTR);
527     BOPTools_AlgoTools2D::MakePCurveOfType(aProj1, aC2D);
528     aTolR = aProj1.GetTolerance();
529   } else {
530     ProjLib_ProjectedCurve aProjCurv(aBAHS, aBAHC);// 1
531     BOPTools_AlgoTools2D::MakePCurveOfType(aProjCurv, aC2D);
532     aTolR=aProjCurv.GetTolerance();
533   }
534   //
535   if (aC2D.IsNull()) { 
536     ProjLib_ProjectedCurve aProjCurvAgain(aBAHS, aBAHC, TolReached2d);// 2
537     BOPTools_AlgoTools2D::MakePCurveOfType(aProjCurvAgain, aC2D);
538     aTolR = aProjCurvAgain.GetTolerance();
539     //
540     if (aC2D.IsNull()) { 
541       Standard_Real aTR=0.0001;
542       ProjLib_ProjectedCurve aProj3(aBAHS, aBAHC, aTR);// 3
543       BOPTools_AlgoTools2D::MakePCurveOfType(aProj3, aC2D);
544       aTolR = aProj3.GetTolerance();
545     }
546   }
547   TolReached2d=aTolR;
548   
549   BOPTools_AlgoTools2D::AdjustPCurveOnFace (aF, aFirst, aLast, aC2D, aC2DA);
550   aC2D=aC2DA;
551 }
552
553 //=======================================================================
554 //function : MakePCurveOfType
555 //purpose  : 
556 //=======================================================================
557   void  BOPTools_AlgoTools2D::MakePCurveOfType(const ProjLib_ProjectedCurve& PC, 
558                                            Handle(Geom2d_Curve)& C2D)
559 {
560   
561   switch (PC.GetType()) {
562
563   case GeomAbs_Line : 
564     C2D = new Geom2d_Line(PC.Line()); 
565     break;
566   case GeomAbs_Circle : 
567     C2D = new Geom2d_Circle(PC.Circle());
568     break;
569   case GeomAbs_Ellipse :
570     C2D = new Geom2d_Ellipse(PC.Ellipse());
571     break;
572   case GeomAbs_Parabola : 
573     C2D = new Geom2d_Parabola(PC.Parabola()); 
574     break;
575   case GeomAbs_Hyperbola : 
576     C2D = new Geom2d_Hyperbola(PC.Hyperbola()); 
577     break;
578   case GeomAbs_BSplineCurve :
579     C2D = PC.BSpline(); 
580     break;
581   case GeomAbs_BezierCurve : 
582   case GeomAbs_OtherCurve : 
583     default :
584     Standard_NotImplemented::Raise("BOPTools_AlgoTools2D::MakePCurveOfType");
585     break;
586   }
587 }
588
589 //=======================================================================
590 //function : CheckEdgeLength
591 //purpose  : 
592 //=======================================================================
593 Standard_Boolean CheckEdgeLength (const TopoDS_Edge& E)
594 {
595   BRepAdaptor_Curve BC(E);
596
597   BOPCol_IndexedMapOfShape aM;
598   BOPTools::MapShapes(E, TopAbs_VERTEX, aM);
599   Standard_Integer i, anExtent, aN=10;
600   Standard_Real ln=0., d, t, f, l, dt; 
601   anExtent=aM.Extent();
602
603   if (anExtent!=1) 
604     return Standard_True;
605     
606   gp_Pnt p1, p2;
607   f = BC.FirstParameter();
608   l = BC.LastParameter();
609   dt=(l-f)/aN;
610   
611   BC.D0(f, p1);
612   for (i=1; i<=aN; i++) {
613     t=f+i*dt;
614     
615     if (i==aN) 
616       BC.D0(l, p2);
617     else 
618       BC.D0(t, p2);
619     
620     d=p1.Distance(p2);
621     ln+=d;
622     p1=p2;
623   }
624   
625   return (ln > Precision::Confusion()); 
626 }
627
628
629
630
631
632
633
634
635 /*
636 //=======================================================================
637 //function : FaceNormal
638 //purpose  : 
639 //=======================================================================
640   void BOPTools_AlgoTools2D::FaceNormal (const TopoDS_Face& aF,
641                                      const Standard_Real U,
642                                      const Standard_Real V,
643                                      gp_Vec& aN)
644 {
645   gp_Pnt aPnt ;
646   gp_Vec aD1U, aD1V;
647   Handle(Geom_Surface) aSurface;
648
649   aSurface=BRep_Tool::Surface(aF);
650   aSurface->D1 (U, V, aPnt, aD1U, aD1V);
651   aN=aD1U.Crossed(aD1V);
652   aN.Normalize();  
653   if (aF.Orientation() == TopAbs_REVERSED){
654     aN.Reverse();
655   }
656   return;
657 }
658 //=======================================================================
659 //function : RemovePCurveForEdgeOnFace
660 //purpose  : 
661 //=======================================================================
662   void BOPTools_AlgoTools2D::RemovePCurveForEdgeOnFace (const TopoDS_Edge& aE,
663                                                     const TopoDS_Face& aF)
664 {
665   BRep_Builder aBB;
666   Handle(Geom2d_Curve) aC2D;
667   Standard_Real  aTol;
668
669   aTol=BRep_Tool::Tolerance(aE);
670   aBB.UpdateEdge(aE, aC2D, aF, aTol);
671 }
672 //=======================================================================
673 //function : MakeCurveOnSurface
674 //purpose  : 
675 //=======================================================================
676   void BOPTools_AlgoTools2D::MakeCurveOnSurface (const TopoDS_Edge& aE,
677                                              const TopoDS_Face& aF,
678                                              Handle(Geom2d_Curve)& aC2D,
679                                              Standard_Real& aFirst,
680                                              Standard_Real& aLast,
681                                              Standard_Real& aToler)
682 {
683   BOPTools_AlgoTools2D::Make2D(aE, aF, aC2D, aFirst, aLast, aToler);
684 }
685
686 //=======================================================================
687 //function : TangentOnEdge
688 //purpose  : 
689 //=======================================================================
690   Standard_Boolean BOPTools_AlgoTools2D::TangentOnEdge(const Standard_Real par, 
691                                                    const TopoDS_Edge& E, 
692                                                    gp_Vec& Tg)
693 {
694   Standard_Boolean isdgE;
695   
696   isdgE = BRep_Tool::Degenerated(E); 
697   if (isdgE) {
698     return Standard_False;
699   }
700   if (!CheckEdgeLength(E)) {
701     return Standard_False;
702   }
703
704   BRepAdaptor_Curve BC(E);
705   //
706   // Body 
707   Standard_Real f, l, tolE, tolp;
708   Standard_Boolean onf, onl, inbounds;
709
710   f = BC.FirstParameter();
711   l = BC.LastParameter();
712   tolE = BC.Tolerance(); 
713   tolp = BC.Resolution(tolE);
714   
715   onf = Abs(f-par)<tolp; 
716   onl = Abs(l-par)<tolp; 
717   inbounds = (f<par) && (par<l);
718
719   if ((!inbounds) && (!onf) && (!onl)) {
720     return Standard_False;
721   }
722   
723   
724   gp_Pnt aP;
725
726   BC.D1(par, aP, Tg);
727   Tg.Normalize(); 
728   
729   return Standard_True;
730 }
731 //=======================================================================
732 //function : TangentOnEdge
733 //purpose  : 
734 //=======================================================================
735   Standard_Boolean BOPTools_AlgoTools2D::TangentOnEdge(const TopoDS_Edge& aE, 
736                                                    gp_Dir& DTg)
737 {
738   Standard_Real aT;
739   gp_Vec aTg;
740
741   DTg.SetCoord(1.,0.,0.);
742
743   aT= BOPTools_AlgoTools2D::IntermediatePoint (aE);
744   Standard_Boolean bIsFound=BOPTools_AlgoTools2D::TangentOnEdge(aT, aE, aTg);
745   if (bIsFound) {
746     gp_Dir aDTmp(aTg);
747     DTg=aDTmp;
748   }
749   return bIsFound;
750 }
751   
752 //=======================================================================
753 //function : TangentOnVertex
754 //purpose  : 
755 //=======================================================================
756   Standard_Boolean BOPTools_AlgoTools2D::TangentOnVertex (const TopoDS_Vertex& v, 
757                                                       const TopoDS_Vertex& vl, 
758                                                       const TopoDS_Edge& e,
759                                                       gp_Vec& aVec)
760 // tg oriented INSIDE 1d(e)
761 // vl : last vertex of e
762 {
763   Standard_Boolean ok;
764   Standard_Real par;
765   gp_Vec tg; 
766
767   par = BRep_Tool::Parameter(v, e);  
768   ok =BOPTools_AlgoTools2D::TangentOnEdge (par, e, tg);
769   if (!ok) {
770     return ok;
771   }
772   if (v.IsSame(vl)) {
773     tg.Reverse();
774   }
775   aVec=tg;
776
777   return ok;
778 }
779
780 //=======================================================================
781 //function : EdgeBounds
782 //purpose  : 
783 //=======================================================================
784   void BOPTools_AlgoTools2D::EdgeBounds (const TopoDS_Edge& aE,
785                                      Standard_Real& aFirst,
786                                      Standard_Real& aLast)
787 {
788   BRepAdaptor_Curve aBC(aE);
789   aFirst= aBC.FirstParameter();
790   aLast = aBC.LastParameter();
791 }
792
793
794 */