0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
[occt.git] / src / Extrema / Extrema_GenLocateExtCC.gxx
CommitLineData
b311480e 1// Created on: 1995-07-18
2// Created by: Modelistation
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 <StdFail_NotDone.hxx>
18#include <math_FunctionSetRoot.hxx>
19#include <math_Vector.hxx>
20
21//=============================================================================
22Extrema_GenLocateExtCC::Extrema_GenLocateExtCC (const Curve1& C1,
23 const Curve2& C2,
24 const Standard_Real U0, const Standard_Real V0,
25 const Standard_Real TolU, const Standard_Real TolV)
26/*-----------------------------------------------------------------------------
27Fonction:
28 Recherche du couple de valeurs de parametre (U,V) tel que:
29 - dist(C1(u),C2(v)) passe par un extremum,
30 - (U,V) soit la solution la plus proche de (U0,V0).
31
32Methode:
33 Si (u,v) est solution, alors:
34 { F1(u,v)=(C1(u)-C2(v)).dC1/du(u) = 0.
35 { F2(u,v)=(C1(u)-C2(v)).dC2/dv(v) = 0.
36 Le probleme consiste a rechercher, dans les intervalles de definition
37 des courbes, la racine du systeme la plus proche de (U0,V0).
38 On utilise la classe math_FunctionSetRoot avec les arguments de construction
39 suivants:
40 - F: Extrema_FuncExtCC cree a partir de C1 et C2,
41 - math_Vector(U0,V0),
42 - math_Vector(TolU,TolV),
43 - math_Vector(Uinf,Usup),
44 - math_Vector(Vinf,Vsup),
45 - 100. .
46-----------------------------------------------------------------------------*/
47{
48 myDone = Standard_False;
49
50 Standard_Real Uinf = Tool1::FirstParameter(C1);
51 Standard_Real Usup = Tool1::LastParameter(C1);
52 Standard_Real Uu;
53 if (Uinf>Usup) {
54 Uu=Uinf;
55 Uinf=Usup;
56 Usup =Uu;
57 }
58
59 Standard_Real Vinf = Tool2::FirstParameter(C2);
60 Standard_Real Vsup = Tool2::LastParameter(C2);
61 if (Vinf>Vsup) {
62 Uu=Vinf;
63 Vinf=Vsup;
64 Vsup =Uu;
65 }
66
67 Extrema_CCLocF F (C1,C2);
68 math_Vector Tol(1, 2);
69 Tol(1) = TolU;
70 Tol(2) = TolV;
71 Standard_Real Tolf = 1.e-10;
72
73 math_Vector Start(1,2);
74 math_Vector Uuinf(1,2);
75 math_Vector Uusup(1,2);
76
77 Start(1) = U0;
78 Start(2) = V0;
79
80 Uuinf(1)=Uinf;
81 Uuinf(2)=Vinf;
82 Uusup(1)=Usup;
83 Uusup(2)=Vsup;
84
859a47c3 85 math_FunctionSetRoot S(F, Tol);
86 S.Perform(F, Start, Uuinf, Uusup);
87
7fd59977 88 if (S.IsDone() && F.NbExt() > 0) {
89 mySqDist = F.SquareDistance(1);
90 F.Points(1,myPoint1,myPoint2);
91 Start(1)=myPoint1.Parameter();
92 Start(2)=myPoint2.Parameter();
93 math_Vector Ff(1,2);
94 F.Value(Start,Ff);
95// cout << "Ff(1) = "<<Ff(1)<<endl;
96// cout << "Ff(2) = "<<Ff(2)<<endl;
97 if ((Ff(1)<Tolf) && (Ff(2)<Tolf) ) myDone = Standard_True;
98 }
99}
100//=============================================================================
101
102Standard_Boolean Extrema_GenLocateExtCC::IsDone () const { return myDone; }
103//=============================================================================
104
105Standard_Real Extrema_GenLocateExtCC::SquareDistance() const
106{
107 if (!IsDone()) { StdFail_NotDone::Raise(); }
108 return mySqDist;
109}
110//=============================================================================
111
112void Extrema_GenLocateExtCC::Point (POnC& P1, POnC& P2)
113 const
114{
115 if (!IsDone()) { StdFail_NotDone::Raise(); }
116 P1 = myPoint1;
117 P2 = myPoint2;
118}
119//=============================================================================