0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / BRepFill / BRepFill_TrimEdgeTool.cxx
1 // Created on: 1995-04-24
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepFill_TrimEdgeTool.ixx>
18 #include <BRep_Tool.hxx>
19 #include <Bisector_BisecAna.hxx>
20 #include <Geom2d_Curve.hxx>
21 #include <Geom2d_TrimmedCurve.hxx>
22 #include <Geom2d_CartesianPoint.hxx>
23 #include <Geom_Curve.hxx>
24 #include <GeomProjLib.hxx>
25 #include <Geom_TrimmedCurve.hxx>
26 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
27 #include <Geom2dInt_GInter.hxx>
28 #include <gp_Pnt.hxx>
29 #include <TopLoc_Location.hxx>
30 #include <TopoDS.hxx>
31 #include <Precision.hxx>
32 #include <IntRes2d_IntersectionPoint.hxx>
33 #include <IntRes2d_IntersectionSegment.hxx>
34 #include <ElCLib.hxx>
35 #include <StdFail_NotDone.hxx>
36 #ifdef OCCT_DEBUG
37 //#define DRAW
38 #ifdef DRAW
39 #include <DrawTrSurf.hxx>
40 #include <DBRep.hxx>
41 #include <Geom2d_Point.hxx>
42 static Standard_Boolean Affich       = Standard_False;
43 static Standard_Boolean AffichInt    = Standard_False;
44 static Standard_Integer intind       = 0;
45 #endif
46 #endif
47
48
49 //=======================================================================
50 //function : SimpleExpression
51 //purpose  : 
52 //=======================================================================
53
54 static void SimpleExpression (const Bisector_Bisec&        B, 
55   Handle(Geom2d_Curve)&  Bis)
56 {
57   Bis = B.Value();
58
59   Handle(Standard_Type) BT = Bis->DynamicType();
60   if (BT == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
61     Handle(Geom2d_TrimmedCurve) TrBis 
62       = Handle(Geom2d_TrimmedCurve)::DownCast(Bis);
63     Handle(Geom2d_Curve) BasBis = TrBis->BasisCurve();
64     BT = BasBis->DynamicType();
65     if (BT == STANDARD_TYPE(Bisector_BisecAna)) {
66       Bis = Handle(Bisector_BisecAna)::DownCast(BasBis)->Geom2dCurve();
67       Bis = new Geom2d_TrimmedCurve (Bis,
68         TrBis->FirstParameter(),
69         TrBis->LastParameter());
70     }
71   }
72 }
73
74
75 //=======================================================================
76 //function : BRepFill_TrimEdgeTool
77 //purpose  : 
78 //=======================================================================
79
80 BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool()
81 {
82 }
83
84
85 //=======================================================================
86 //function : BRepFill_TrimEdgeTool
87 //purpose  : 
88 //=======================================================================
89
90 BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool
91   (const Bisector_Bisec& Bisec,
92   const Handle(Geom2d_Geometry)& S1,
93   const Handle(Geom2d_Geometry)& S2,
94   const Standard_Real   Offset) :
95 myOffset(Offset),
96   myBisec(Bisec)
97 {
98   isPoint1 = (S1->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint));
99   isPoint2 = (S2->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint));
100
101   // return geometries of shapes.
102   //  Standard_Real f,l;
103   if (isPoint1) {
104     myP1 = Handle(Geom2d_Point)::DownCast(S1)->Pnt2d();
105   }
106   else {
107     myC1 = Handle(Geom2d_Curve)::DownCast(S1);
108 #ifdef DRAW
109     if ( Affich) {
110       //POP pour NT
111       char* myC1name = "myC1";
112       DrawTrSurf::Set(myC1name,myC1);
113       //      DrawTrSurf::Set("myC1",myC1);
114     }
115 #endif
116   }
117   if (isPoint2) {
118     myP2 = Handle(Geom2d_Point)::DownCast(S2)->Pnt2d();
119   }
120   else {
121     myC2 = Handle(Geom2d_Curve)::DownCast(S2);
122 #ifdef DRAW
123     if ( Affich) {
124       char* myC2name = "myC2";
125       DrawTrSurf::Set(myC2name,myC2);
126       //      DrawTrSurf::Set("myC2",myC2);
127     }
128 #endif
129   }
130   // return the simple expression of the bissectrice
131   Handle(Geom2d_Curve) Bis;
132   SimpleExpression(myBisec, Bis);
133   myBis = Geom2dAdaptor_Curve(Bis);
134 #ifdef DRAW
135   if ( Affich) {
136     char* myBisname = "myBis";
137     DrawTrSurf::Set(myBisname,Bis);
138   }
139 #endif
140
141 }
142
143 //=======================================================================
144 //function : Bubble
145 //purpose  : Order the sequence of points by increasing x. 
146 //=======================================================================
147
148 static void Bubble(TColgp_SequenceOfPnt& Seq) 
149 {
150   Standard_Boolean Invert = Standard_True;
151   Standard_Integer NbPoints = Seq.Length();
152   while (Invert) {
153     Invert = Standard_False;
154     for ( Standard_Integer i = 1; i < NbPoints; i++) {
155       gp_Pnt P1 = Seq.Value(i);
156       gp_Pnt P2 = Seq.Value(i+1);
157       if (P2.X()<P1.X())  {
158         Seq.Exchange(i,i+1);
159         Invert = Standard_True;
160       }
161     }
162   }
163 }
164
165
166 //=======================================================================
167 //function : EvalParameters  
168 //purpose  : 
169 //=======================================================================
170
171 static void EvalParameters(const Geom2dAdaptor_Curve& Bis,
172   const Geom2dAdaptor_Curve& AC,
173   TColgp_SequenceOfPnt& Params)
174 {
175   Geom2dInt_GInter Intersector;
176   Standard_Real Tol = Precision::Confusion();
177   //  Standard_Real TolC = 1.e-9;
178
179   Geom2dAdaptor_Curve CBis(Bis);
180   Geom2dAdaptor_Curve CAC (AC);
181
182   //Intersector = Geom2dInt_GInter(CBis, CAC, TolC, Tol);
183   Intersector = Geom2dInt_GInter(CAC, CBis, Tol, Tol);
184
185   Standard_Integer NbPoints, NbSegments;
186   Standard_Real U1, U2;
187   gp_Pnt P;
188
189   if ( !Intersector.IsDone()) {
190     StdFail_NotDone::Raise("BRepFill_TrimSurfaceTool::IntersectWith");
191   }
192
193   NbPoints = Intersector.NbPoints();
194
195   if (NbPoints > 0) {
196     for ( Standard_Integer i = 1; i <= NbPoints; i++) {
197       U1 = Intersector.Point(i).ParamOnSecond();
198       U2 = Intersector.Point(i).ParamOnFirst();
199       P = gp_Pnt(U1,U2,0.);
200       Params.Append(P);
201     }
202
203   }
204
205   NbSegments = Intersector.NbSegments();
206
207   if (NbSegments > 0) {
208     IntRes2d_IntersectionSegment Seg;
209     for ( Standard_Integer i = 1; i <= NbSegments; i++) {
210       Seg = Intersector.Segment(i);
211       U1  = Seg.FirstPoint().ParamOnSecond();
212       Standard_Real Ulast = Seg.LastPoint().ParamOnSecond();
213       if ( Abs(U1    - CBis.FirstParameter()) <= Tol &&
214         Abs(Ulast - CBis.LastParameter())  <= Tol    ) {
215           P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.);
216           Params.Append(P);
217           P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.);
218           Params.Append(P);
219       }
220       else {
221         U1 += Seg.LastPoint().ParamOnSecond();
222         U1 /= 2.;
223         U2  = Seg.FirstPoint().ParamOnFirst();
224         U2 += Seg.LastPoint().ParamOnFirst();
225         U2 /= 2.;
226         P = gp_Pnt(U1,U2,0.);
227         Params.Append(P);
228       }
229     }
230   }
231
232   // Order the sequence by growing parameter on the bissectrice.
233   Bubble( Params);
234 }
235
236 static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis,
237   const Geom2dAdaptor_Curve& AC,
238   TColgp_SequenceOfPnt& Params,
239   const Standard_Real Tol)
240 {
241   Geom2dInt_GInter Intersector;
242   Standard_Real TolC = Tol;
243
244   Geom2dAdaptor_Curve CBis(Bis);
245   Geom2dAdaptor_Curve CAC (AC);
246
247   Intersector = Geom2dInt_GInter(CAC, CBis, TolC, Tol);
248
249   Standard_Integer NbPoints, NbSegments;
250   Standard_Real U1, U2;
251   gp_Pnt P;
252
253   if ( !Intersector.IsDone()) {
254     StdFail_NotDone::Raise("BRepFill_TrimSurfaceTool::IntersectWith");
255   }
256
257   NbPoints = Intersector.NbPoints();
258
259   if (NbPoints > 0) {
260     for ( Standard_Integer i = 1; i <= NbPoints; i++) {
261       U1 = Intersector.Point(i).ParamOnSecond();
262       U2 = Intersector.Point(i).ParamOnFirst();
263       P = gp_Pnt(U1,U2,0.);
264       Params.Append(P);
265     }
266
267   }
268
269   NbSegments = Intersector.NbSegments();
270
271   if (NbSegments > 0) {
272     IntRes2d_IntersectionSegment Seg;
273     for ( Standard_Integer i = 1; i <= NbSegments; i++) {
274       Seg = Intersector.Segment(i);
275       U1  = Seg.FirstPoint().ParamOnSecond();
276       Standard_Real Ulast = Seg.LastPoint().ParamOnSecond();
277       if ( Abs(U1    - CBis.FirstParameter()) <= Tol &&
278         Abs(Ulast - CBis.LastParameter())  <= Tol    ) {
279           P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.);
280           Params.Append(P);
281           P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.);
282           Params.Append(P);
283       }
284       else {
285         U1 += Seg.LastPoint().ParamOnSecond();
286         U1 /= 2.;
287         U2  = Seg.FirstPoint().ParamOnFirst();
288         U2 += Seg.LastPoint().ParamOnFirst();
289         U2 /= 2.;
290         P = gp_Pnt(U1,U2,0.);
291         Params.Append(P);
292       }
293     }
294   }
295
296   // Order the sequence by parameter growing on the bissectrice.
297   Bubble( Params);
298 }
299
300
301 //=======================================================================
302 //function : IntersectWith
303 //purpose  : 
304 //=======================================================================
305
306 void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1,
307                                           const TopoDS_Edge& Edge2,
308                                           const GeomAbs_JoinType theJoinType,
309                                           TColgp_SequenceOfPnt& Params)
310 {
311   Params.Clear();
312
313   // return curves associated to edges.
314   TopLoc_Location L;
315   Standard_Real   f,l;
316   Handle(Geom_Surface) Surf;
317
318   Handle(Geom2d_Curve) C1;
319   BRep_Tool::CurveOnSurface(Edge1,C1,Surf,L,f,l);
320   Geom2dAdaptor_Curve AC1(C1,f,l);
321
322   Handle(Geom2d_Curve) C2;
323   BRep_Tool::CurveOnSurface(Edge2,C2,Surf,L,f,l);
324   Geom2dAdaptor_Curve AC2(C2,f,l);
325
326 #ifdef DRAW
327   if ( AffichInt) {
328     f = AC1.FirstParameter();
329     l = AC1.LastParameter();
330     char name[32];
331     sprintf(name,"C1_%d", ++intind);
332     DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(C1,f,l));
333     f = AC2.FirstParameter();
334     l = AC2.LastParameter();
335     sprintf(name,"C2_%d", intind);
336     DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(C2,f,l));
337     f = myBis.FirstParameter();
338     l = myBis.LastParameter();
339     sprintf(name,"BIS%d", intind);
340     DrawTrSurf::Set(name, new Geom2d_TrimmedCurve(myBis.Curve(),f,l));
341     sprintf(name,"E1_%d", intind);
342     DBRep::Set(name, Edge1);
343     sprintf(name,"E2_%d", intind);
344     DBRep::Set(name, Edge2);
345
346   }
347 #endif
348
349   // Calculate intersection
350   TColgp_SequenceOfPnt Points2;
351   gp_Pnt PSeq;
352
353   EvalParameters (myBis,AC1,Params);
354   EvalParameters (myBis,AC2,Points2);
355
356
357
358   Standard_Integer SeanceDeRattrapage=0;
359   Standard_Real TolInit= 1.e-9;
360   Standard_Integer nn = 7;
361
362   if((AC1.GetType() != GeomAbs_Circle && AC1.GetType() != GeomAbs_Line) ||
363     (AC2.GetType() != GeomAbs_Circle && AC2.GetType() != GeomAbs_Line)) {
364
365       TolInit = 1.e-8;
366       nn = 6;
367   }
368
369   if(Params.IsEmpty() && Points2.IsEmpty())
370   {
371     //Check, may be there are no intersections at all
372     // for case myBis == Line
373     if(myBis.GetType() == GeomAbs_Line)
374     {
375       Standard_Real dmax = TolInit;
376       Standard_Integer n = 0;
377       while(n < nn)
378       {
379         dmax *= 10.0;
380         ++n;
381       }
382       dmax *= dmax;
383       //
384       gp_Lin2d anL = myBis.Line();
385       Standard_Boolean isFar1 = Standard_True;
386       Standard_Boolean isFar2 = Standard_True;
387       gp_Pnt2d aP;
388       //
389       Standard_Real d = RealLast();
390       AC1.D0(AC1.FirstParameter(), aP);
391       Standard_Real par = ElCLib::Parameter(anL, aP);
392       if(par >= myBis.FirstParameter() && par <= myBis.LastParameter())
393       {
394         d = anL.SquareDistance(aP);
395       }
396       AC1.D0(AC1.LastParameter(), aP);
397       par = ElCLib::Parameter(anL, aP);
398       if(par >= myBis.FirstParameter() && par <= myBis.LastParameter())
399       {
400         d = Min(anL.SquareDistance(aP), d);
401       }
402       isFar1 = d > dmax;
403       //
404       d = RealLast();
405       AC2.D0(AC2.FirstParameter(), aP);
406       par = ElCLib::Parameter(anL, aP);
407       if(par >= myBis.FirstParameter() && par <= myBis.LastParameter())
408       {
409         d = anL.SquareDistance(aP);
410       }
411       AC2.D0(AC2.LastParameter(), aP);
412       par = ElCLib::Parameter(anL, aP);
413       if(par >= myBis.FirstParameter() && par <= myBis.LastParameter())
414       {
415         d = Min(anL.SquareDistance(aP), d);
416       }
417       isFar2 = d > dmax;
418       //
419       if(isFar1 && isFar2)
420       {
421         return;
422       }
423     }
424   }
425
426   while (     SeanceDeRattrapage < nn // TolInit <= 0.01
427     && ( Points2.Length() != Params.Length() || 
428     (Points2.Length() == 0 && Params.Length() == 0) ) ) {
429
430 #ifdef OCCT_DEBUG
431       cout << "BRepFill_TrimEdgeTool: incoherent intersection. Try with a greater tolerance" << endl;
432 #endif
433
434       Params.Clear();
435       Points2.Clear();
436
437       TolInit*=10.0;
438
439       EvalParametersBis(myBis,AC1,Params,TolInit);
440       EvalParametersBis(myBis,AC2,Points2,TolInit); 
441       SeanceDeRattrapage++;
442   }
443
444 #ifdef OCCT_DEBUG
445   if(SeanceDeRattrapage != 0) cout << "SeanceDeRattrapage = " << SeanceDeRattrapage << endl;
446   if(SeanceDeRattrapage == nn) { 
447     cout << "BRepFill_TrimEdgeTool: incoherent intersection" << endl;
448   }
449 #endif
450
451
452   if(Params.Length() == 0 && Points2.Length() == 1) {
453
454     //cout << "Params.Length() == 0 && Points2.Length() == 1" << endl;
455     Standard_Real dmin, dmax = 0.25*myOffset*myOffset;
456     Standard_Real tBis = Points2(1).X();
457     gp_Pnt2d PBis = myBis.Value(tBis);
458
459     Standard_Real t = AC1.FirstParameter();
460     gp_Pnt2d PC = AC1.Value(t);
461     dmin = PC.SquareDistance(PBis);
462     gp_Pnt P(tBis, t, 0.);
463     if(dmin < dmax)
464     {
465       Params.Append(P);
466     }
467
468     t = AC1.LastParameter();
469     PC = AC1.Value(t);
470     Standard_Real dmin1 = PC.SquareDistance(PBis);
471     if(dmin > dmin1 && dmin1 < dmax ) {
472       P.SetY(t);
473       if(Params.IsEmpty())
474         Params.Append(P);
475       else
476         Params.SetValue(1,P);
477     }
478   }
479   else if(Params.Length() == 1 && Points2.Length() == 0) {
480
481     //cout << "Params.Length() == 1 && Points2.Length() == 0" << endl;
482     Standard_Real dmin, dmax = 0.25*myOffset*myOffset;
483     Standard_Real tBis = Params(1).X();
484     gp_Pnt2d PBis = myBis.Value(tBis);
485
486     Standard_Real t = AC2.FirstParameter();
487     gp_Pnt2d PC = AC2.Value(t);
488     dmin = PC.SquareDistance(PBis);
489     gp_Pnt P(tBis, t, 0.);
490     if(dmin < dmax)
491     {
492       Points2.Append(P);
493     }
494
495     t = AC2.LastParameter();
496     PC = AC2.Value(t);
497     Standard_Real dmin1 = PC.SquareDistance(PBis);
498     if(dmin > dmin1 && dmin1 < dmax ) {
499       P.SetY(t);
500       if(Points2.IsEmpty())
501         Points2.Append(P);
502       else
503         Points2.SetValue(1,P);
504     }
505   }
506
507   // small manipulation to remove incorrect intersections:
508   // return only common intersections (same parameter
509   // on the bissectrice.).
510   // The tolerance can be eventually changed.
511
512   gp_Pnt P1,P2;
513   Standard_Real Tol = 4 * 100 * Precision::PConfusion();
514   Standard_Integer i = 1;
515   Standard_Integer NbPoints = Params.Length();
516
517   if(NbPoints == 1 && Points2.Length() == 1) {
518     //cout << "NbPoints == 1 && Points2.Length() == 1" << endl;
519     for ( i = 1; i <= NbPoints; i++) {
520       PSeq = Params(i);
521       PSeq.SetZ((Points2.Value(i)).Y());
522       Params.SetValue(i,PSeq);
523     }
524     return;
525   }    
526
527   i = 1;
528   while ( i <= Min( Params.Length(), Points2.Length())) {
529     P1 = Params(i);
530     P2 = Points2(i);
531     Standard_Real P1xP2x=Abs( P1.X() - P2.X());
532
533     if ( P1xP2x > Tol ) {
534 #ifdef OCCT_DEBUG
535       cout << "BRepFill_TrimEdgeTool: no same parameter on the bissectrice" << endl;
536 #endif
537       if(P1xP2x>TolInit) { 
538 #ifdef OCCT_DEBUG
539         cout << "BRepFill_TrimEdgeTool: Continue somehow" << endl;
540 #endif  
541         i++;
542       }
543       else { 
544         if ( P1.X() < P2.X()) Params.Remove(i);
545         else                  Points2.Remove(i);
546       }
547     }
548     else i++;
549   }
550
551   if ( Params.Length() > Points2.Length()) {
552     Params.Remove(Points2.Length()+1, Params.Length());
553   }
554   else if ( Params.Length() < Points2.Length()) {
555     Points2.Remove(Params.Length()+1, Points2.Length());
556   }
557
558   NbPoints = Params.Length();
559
560   if (NbPoints > 0 && theJoinType == GeomAbs_Intersection)
561   {
562     //Remove all vertices with non-minimal parameter
563     Standard_Integer imin = 1;
564     for (i = 2; i <= NbPoints; i++)
565       if (Params(i).X() < Params(imin).X())
566         imin = i;
567     gp_Pnt Pnt1 = Params(imin);
568     gp_Pnt Pnt2 = Points2(imin);
569     Params.Clear();
570     Points2.Clear();
571     Params.Append(Pnt1);
572     Points2.Append(Pnt2);
573   }
574   
575   NbPoints = Params.Length();
576   for ( i = 1; i <= NbPoints; i++) {
577     PSeq = Params(i);
578     PSeq.SetZ((Points2.Value(i)).Y());
579     Params.SetValue(i,PSeq);
580   }
581 }
582
583 //=======================================================================
584 //function : AddOrConfuse
585 //purpose  : the first or the last point of the bissectrice is on the 
586 //           parallel if it was not found in the intersections, 
587 //           it is projected on parallel lines and added in the parameters 
588 //=======================================================================
589
590 void BRepFill_TrimEdgeTool::AddOrConfuse(const Standard_Boolean  Start,
591   const TopoDS_Edge&      Edge1,
592   const TopoDS_Edge&      Edge2,
593   TColgp_SequenceOfPnt&   Params) 
594   const 
595 {
596   Standard_Boolean  ToProj = Standard_True;
597   gp_Pnt2d          PBis;
598   Standard_Real     Tol = 10*Precision::Confusion(); 
599
600   // return curves associated to edges.
601   TopLoc_Location L;
602   Standard_Real   f,l;
603   Handle(Geom_Surface) Surf;
604
605   Handle(Geom2d_Curve) C1;
606   BRep_Tool::CurveOnSurface(Edge1,C1,Surf,L,f,l);
607   Geom2dAdaptor_Curve AC1(C1,f,l);
608
609
610   if (Start) PBis = myBis.Value(myBis.FirstParameter());
611   else       PBis = myBis.Value(myBis.LastParameter ()); 
612
613   // Test if the end of the bissectrice is in the set of intersection points.
614   if (!Params.IsEmpty()) {
615     gp_Pnt2d P;
616     if (Start) P = AC1.Value(Params.First().Y());
617     else       P = AC1.Value(Params.Last ().Y()); 
618     ToProj     = !PBis.IsEqual(P,Tol);
619   }
620
621   if (ToProj) {
622 #ifdef OCCT_DEBUG
623     cout << " project extremity bissectrice on parallel."<<endl;
624 #endif
625
626     // Project point on parallels and add in Params
627
628     Standard_Real f2,l2;
629     Handle(Geom2d_Curve) C2;
630     BRep_Tool::CurveOnSurface(Edge2,C2,Surf,L,f2,l2);
631
632     Geom2dAPI_ProjectPointOnCurve Projector1(PBis,C1,f,l);    
633     Geom2dAPI_ProjectPointOnCurve Projector2(PBis,C2,f2,l2);
634
635     if (Projector1.NbPoints() == 0) {
636 #ifdef OCCT_DEBUG
637       cout << "Failed projection in BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
638 #endif
639       return;
640     }
641     if (!Projector1.NearestPoint().IsEqual(PBis,Tol)) {
642 #ifdef OCCT_DEBUG
643       cout <<"Incorrect solution in BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
644 #endif
645       return;
646     }
647     if (Projector2.NbPoints() == 0) {
648 #ifdef OCCT_DEBUG
649       cout << "Failed projection in BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
650 #endif
651       return;
652     }
653     if (!Projector2.NearestPoint().IsEqual(PBis,Tol)) {
654 #ifdef OCCT_DEBUG
655       cout <<" Mauvaisesolution dans BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
656 #endif
657       return;
658     }
659     gp_Pnt PInt (0,
660       Projector1.LowerDistanceParameter(),
661       Projector2.LowerDistanceParameter());
662     if (Start) {
663       PInt.SetX (myBis.FirstParameter());
664       Params.Prepend(PInt);
665     }
666     else {
667       PInt.SetX (myBis.LastParameter());
668       Params.Append(PInt);
669     }
670   }
671 }
672
673 //=======================================================================
674 //function : IsInside
675 //purpose  : 
676 //=======================================================================
677
678 Standard_Boolean BRepFill_TrimEdgeTool::IsInside(const gp_Pnt2d& P) const 
679 {
680   //  Modified by Sergey KHROMOV - Fri Sep 27 11:43:12 2002 Begin
681   //   Standard_Real Dist;
682   Standard_Real Dist = RealLast();
683   //  Modified by Sergey KHROMOV - Fri Sep 27 11:43:12 2002 End
684   if (isPoint1) 
685     Dist = P.Distance(myP1);
686   else if (isPoint2) 
687     Dist = P.Distance(myP2);
688   else {
689     Geom2dAPI_ProjectPointOnCurve Projector(P,myC1);
690     if (Projector.NbPoints() > 0) {
691       Dist = Projector.LowerDistance();
692     }
693     //  Modified by Sergey KHROMOV - Fri Sep 27 11:43:43 2002 Begin
694     //     else {
695     //       gp_Pnt2d PF = myC1->Value(myC1->FirstParameter());
696     //       gp_Pnt2d PL = myC1->Value(myC1->LastParameter());
697     //       Dist = Min (P.Distance(PF),P.Distance(PL));
698     //     }
699
700     // Check of distances between P and first and last point of the first curve
701     // should be performed in any case, despite of the results of projection.
702     gp_Pnt2d      PF       = myC1->Value(myC1->FirstParameter());
703     gp_Pnt2d      PL       = myC1->Value(myC1->LastParameter());
704     Standard_Real aDistMin = Min (P.Distance(PF),P.Distance(PL));
705
706     if (Dist > aDistMin)
707       Dist = aDistMin;
708     //  Modified by Sergey KHROMOV - Fri Sep 27 11:43:44 2002 End
709   }
710
711   //  return (Dist < Abs(myOffset);
712   // return (Dist < Abs(myOffset) + Precision::Confusion());
713   return (Dist < Abs(myOffset) - Precision::Confusion());
714 }
715