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