c043128db76cccfcfa2162377b0ce26c25d801c9
[occt.git] / src / Extrema / Extrema_GenLocateExtCS.cxx
1 // Created on: 1996-01-25
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1996-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
18 #include <Adaptor3d_Curve.hxx>
19 #include <Adaptor3d_Surface.hxx>
20 #include <Extrema_FuncExtCS.hxx>
21 #include <Extrema_GenLocateExtCS.hxx>
22 #include <Extrema_POnCurv.hxx>
23 #include <Extrema_POnSurf.hxx>
24 #include <math_FunctionSetRoot.hxx>
25 #include <math_NewtonFunctionSetRoot.hxx>
26 #include <math_Vector.hxx>
27 #include <Standard_DomainError.hxx>
28 #include <StdFail_NotDone.hxx>
29
30 //=======================================================================
31 //function : Extrema_GenLocateExtCS
32 //purpose  : 
33 //=======================================================================
34 Extrema_GenLocateExtCS::Extrema_GenLocateExtCS()
35 : myDone(Standard_False),
36   mySqDist(RealLast())
37 {
38 }
39
40 //=======================================================================
41 //function : Extrema_GenLocateExtCS
42 //purpose  : 
43 //=======================================================================
44
45  Extrema_GenLocateExtCS::Extrema_GenLocateExtCS(const Adaptor3d_Curve& C, 
46                                                 const Adaptor3d_Surface& S, 
47                                                 const Standard_Real T, 
48                                                 const Standard_Real U, 
49                                                 const Standard_Real V, 
50                                                 const Standard_Real Tol1, 
51                                                 const Standard_Real Tol2)
52 {
53   Perform(C,S,T,U,V,Tol1,Tol2);
54 }
55
56 //=======================================================================
57 //function : Perform
58 //purpose  : 
59 //=======================================================================
60
61 void Extrema_GenLocateExtCS::Perform(const Adaptor3d_Curve& C, 
62                                      const Adaptor3d_Surface& S, 
63                                      const Standard_Real T, 
64                                      const Standard_Real U, 
65                                      const Standard_Real V, 
66                                      const Standard_Real Tol1, 
67                                      const Standard_Real Tol2)
68 {
69   myDone = Standard_False;
70
71   Standard_Real Tinf, Tsup;
72   Tinf = C.FirstParameter();
73   Tsup = C.LastParameter();
74
75   Standard_Real Uinf, Usup, Vinf, Vsup;
76   Uinf = S.FirstUParameter();
77   Usup = S.LastUParameter();
78   Vinf = S.FirstVParameter();
79   Vsup = S.LastVParameter();
80
81   Extrema_FuncExtCS F (C,S);
82   math_Vector Tol(1, 3), Start(1, 3), BInf(1, 3), BSup(1, 3);
83   Tol(1) = Tol1;
84   Tol(2) = Tol2;
85   Tol(3) = Tol2;
86
87   Start(1) = T;
88   Start(2) = U;
89   Start(3) = V;
90
91   BInf(1) = Tinf;
92   BInf(2) = Uinf;
93   BInf(3) = Vinf;
94
95   BSup(1) = Tsup;
96   BSup(2) = Usup;
97   BSup(3) = Vsup;
98
99   math_FunctionSetRoot SR (F, Tol);
100   SR.Perform(F, Start, BInf, BSup);
101   if (!SR.IsDone()) 
102     return;
103
104   mySqDist = F.SquareDistance(1);
105   myPoint1 = F.PointOnCurve(1);
106   myPoint2 = F.PointOnSurface(1);
107   myDone = Standard_True;
108
109 }
110
111 //=======================================================================
112 //function : IsDone
113 //purpose  : 
114 //=======================================================================
115
116 Standard_Boolean Extrema_GenLocateExtCS::IsDone() const 
117 {
118   return myDone;
119 }
120
121 //=======================================================================
122 //function : Value
123 //purpose  : 
124 //=======================================================================
125
126 Standard_Real Extrema_GenLocateExtCS::SquareDistance() const 
127 {
128   if (!IsDone()) { throw StdFail_NotDone(); }
129   return mySqDist;
130 }
131
132 //=======================================================================
133 //function : PointOnCurve
134 //purpose  : 
135 //=======================================================================
136
137 const Extrema_POnCurv& Extrema_GenLocateExtCS::PointOnCurve() const 
138 {
139   if (!IsDone()) { throw StdFail_NotDone(); }
140   return myPoint1;
141 }
142
143 //=======================================================================
144 //function : PointOnSurface
145 //purpose  : 
146 //=======================================================================
147
148 const Extrema_POnSurf& Extrema_GenLocateExtCS::PointOnSurface() const 
149 {
150   if (!IsDone()) { throw StdFail_NotDone(); }
151   return myPoint2;
152 }
153