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