1 // Created on: 1993-12-15
2 // Created by: Christophe MARION
3 // Copyright (c) 1993-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 <BRepExtrema_ExtCC.hxx>
18 
19 #include <BRep_Tool.hxx>
20 #include <Extrema_POnCurv.hxx>
21 #include <BRepAdaptor_Curve.hxx>
22 
23 
24 //=======================================================================
25 //function : BRepExtrema_ExtCC
26 //purpose  :
27 //=======================================================================
28 
BRepExtrema_ExtCC(const TopoDS_Edge & E1,const TopoDS_Edge & E2)29 BRepExtrema_ExtCC::BRepExtrema_ExtCC(const TopoDS_Edge& E1, const TopoDS_Edge& E2)
30 {
31   Initialize(E2);
32   Perform(E1);
33 }
34 
35 //=======================================================================
36 //function : Initialize
37 //purpose  :
38 //=======================================================================
39 
Initialize(const TopoDS_Edge & E2)40 void BRepExtrema_ExtCC::Initialize(const TopoDS_Edge& E2)
41 {
42   if (!BRep_Tool::IsGeometric(E2))
43     return;  // protect against non-geometric type (e.g. polygon)
44   Standard_Real V1, V2;
45   BRepAdaptor_Curve Curv(E2);
46   myHC = new BRepAdaptor_Curve(Curv);
47   Standard_Real Tol = Min(BRep_Tool::Tolerance(E2), Precision::Confusion());
48   Tol = Max(Curv.Resolution(Tol), Precision::PConfusion());
49   BRep_Tool::Range(E2,V1,V2);
50   myExtCC.SetCurve (2, *myHC, V1, V2);
51   myExtCC.SetTolerance(2, Tol);
52 }
53 
54 //=======================================================================
55 //function : Perform
56 //purpose  :
57 //=======================================================================
58 
Perform(const TopoDS_Edge & E1)59 void BRepExtrema_ExtCC::Perform(const TopoDS_Edge& E1)
60 {
61   if (!BRep_Tool::IsGeometric(E1))
62     return;  // protect against non-geometric type (e.g. polygon)
63   Standard_Real U1, U2;
64   BRepAdaptor_Curve Curv(E1);
65   Handle(BRepAdaptor_Curve) HC = new BRepAdaptor_Curve(Curv);
66   Standard_Real Tol = Min(BRep_Tool::Tolerance(E1), Precision::Confusion());
67   Tol = Max(Curv.Resolution(Tol), Precision::PConfusion());
68   BRep_Tool::Range(E1,U1,U2);
69   myExtCC.SetCurve (1, *HC, U1, U2);
70   myExtCC.SetTolerance(1, Tol);
71   // If we enable SetSingleSolutionFlag Extrema will run much quicker on almost parallel curves
72   // (e.g. bug 27665), however some solutions will be lost, e.g. see bug 28183.
73   //myExtCC.SetSingleSolutionFlag(Standard_True);
74   myExtCC.Perform();
75 }
76 
77 //=======================================================================
78 //function : ParameterOnE1
79 //purpose  :
80 //=======================================================================
81 
ParameterOnE1(const Standard_Integer N) const82 Standard_Real BRepExtrema_ExtCC::ParameterOnE1(const Standard_Integer N) const
83 {
84   Extrema_POnCurv POnE1, POnE2;
85   myExtCC.Points(N, POnE1, POnE2);
86   return POnE1.Parameter();
87 }
88 
89 //=======================================================================
90 //function : PointOnE1
91 //purpose  :
92 //=======================================================================
93 
PointOnE1(const Standard_Integer N) const94 gp_Pnt BRepExtrema_ExtCC::PointOnE1(const Standard_Integer N) const
95 {
96   Extrema_POnCurv POnE1, POnE2;
97   myExtCC.Points(N, POnE1, POnE2);
98   return POnE1.Value();
99 }
100 
101 //=======================================================================
102 //function : ParameterOnE2
103 //purpose  :
104 //=======================================================================
105 
ParameterOnE2(const Standard_Integer N) const106 Standard_Real BRepExtrema_ExtCC::ParameterOnE2(const Standard_Integer N) const
107 {
108   Extrema_POnCurv POnE1, POnE2;
109   myExtCC.Points(N, POnE1, POnE2);
110   return POnE2.Parameter();
111 }
112 
113 //=======================================================================
114 //function : PointOnE2
115 //purpose  :
116 //=======================================================================
117 
PointOnE2(const Standard_Integer N) const118 gp_Pnt BRepExtrema_ExtCC::PointOnE2(const Standard_Integer N) const
119 {
120   Extrema_POnCurv POnE1, POnE2;
121   myExtCC.Points(N, POnE1, POnE2);
122   return POnE2.Value();
123 }
124 
125 
126 //=======================================================================
127 //function : TrimmedSquareDistances
128 //purpose  :
129 //=======================================================================
130 
TrimmedSquareDistances(Standard_Real & dist11,Standard_Real & dist12,Standard_Real & dist21,Standard_Real & dist22,gp_Pnt & pnt11,gp_Pnt & pnt12,gp_Pnt & pnt21,gp_Pnt & pnt22) const131 void BRepExtrema_ExtCC::TrimmedSquareDistances
132   (Standard_Real& dist11,
133    Standard_Real& dist12,
134    Standard_Real& dist21,
135    Standard_Real& dist22,
136    gp_Pnt& pnt11,
137    gp_Pnt& pnt12,
138    gp_Pnt& pnt21,
139    gp_Pnt& pnt22) const
140 {
141   myExtCC.TrimmedSquareDistances(dist11,dist12,dist21,dist22,
142                                  pnt11,pnt12,pnt21,pnt22);
143 }
144