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