0023934: Compiler warnings in MS VC++ 10
[occt.git] / src / Extrema / Extrema_FuncExtPS.cxx
CommitLineData
b311480e 1// Created on: 1995-07-18
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22// Modified by skv - Thu Sep 30 15:21:07 2004 OCC593
23
24
25#include <Extrema_FuncExtPS.ixx>
26#include <gp_Vec.hxx>
27#include <gp_Pnt.hxx>
28#include <Standard_TypeMismatch.hxx>
29#include <Precision.hxx>
30#include <GeomAbs_IsoType.hxx>
31
7fd59977 32Extrema_FuncExtPS::Extrema_FuncExtPS ()
33{
34 myPinit = Standard_False;
35 mySinit = Standard_False;
7fd59977 36}
6062bf3e 37
7fd59977 38//=============================================================================
39Extrema_FuncExtPS::Extrema_FuncExtPS (const gp_Pnt& P,
40 const Adaptor3d_Surface& S)
41{
42 myP = P;
43 myS = (Adaptor3d_SurfacePtr)&S;
7fd59977 44 myPinit = Standard_True;
45 mySinit = Standard_True;
46}
47
48//=============================================================================
49void Extrema_FuncExtPS::Initialize(const Adaptor3d_Surface& S)
50{
51 myS = (Adaptor3d_SurfacePtr)&S;
7fd59977 52 mySinit = Standard_True;
53 myPoint.Clear();
54 mySqDist.Clear();
55}
56
57//=============================================================================
58
59void Extrema_FuncExtPS::SetPoint(const gp_Pnt& P)
60{
61 myP = P;
62 myPinit = Standard_True;
63 myPoint.Clear();
64 mySqDist.Clear();
65}
66
67//=============================================================================
68
69//=============================================================================
70
71Standard_Integer Extrema_FuncExtPS::NbVariables () const { return 2;}
72//=============================================================================
73
74Standard_Integer Extrema_FuncExtPS::NbEquations () const { return 2;}
75//=============================================================================
76
77Standard_Boolean Extrema_FuncExtPS::Value (const math_Vector& UV,
78 math_Vector& F)
79{
80 if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
81 myU = UV(1);
82 myV = UV(2);
83 gp_Vec Dus, Dvs;
84 myS->D1(myU,myV,myPs,Dus,Dvs);
85
86 gp_Vec PPs (myP,myPs);
6062bf3e 87
7fd59977 88 F(1) = PPs.Dot(Dus);
89 F(2) = PPs.Dot(Dvs);
90
91 return Standard_True;
92}
93//=============================================================================
94
95Standard_Boolean Extrema_FuncExtPS::Derivatives (const math_Vector& UV,
96 math_Matrix& Df)
97{
98 math_Vector F(1,2);
99 return Values(UV,F,Df);
100}
101//=============================================================================
102
103Standard_Boolean Extrema_FuncExtPS::Values (const math_Vector& UV,
104 math_Vector& F,
105 math_Matrix& Df)
106{
107 if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
108 myU = UV(1);
109 myV = UV(2);
110 gp_Vec Dus, Dvs, Duus, Dvvs, Duvs;
111 myS->D2(myU,myV,myPs,Dus,Dvs,Duus,Dvvs,Duvs);
112
113 gp_Vec PPs (myP,myPs);
7fd59977 114
6062bf3e
G
115 Df(1,1) = Dus.SquareMagnitude() + PPs.Dot(Duus);
116 Df(1,2) = Dvs.Dot(Dus) + PPs.Dot(Duvs);
117 Df(2,1) = Df(1,2);
118 Df(2,2) = Dvs.SquareMagnitude() + PPs.Dot(Dvvs);
7fd59977 119
6062bf3e 120 // 3. Value
7fd59977 121 F(1) = PPs.Dot(Dus);
122 F(2) = PPs.Dot(Dvs);
123
124 return Standard_True;
125}
126//=============================================================================
127
128Standard_Integer Extrema_FuncExtPS::GetStateNumber ()
129{
130 if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
5368adff 131 //comparison of solution with previous solutions
132 Standard_Integer i = 1, nbSol = mySqDist.Length();
133 Standard_Real tol2d = Precision::PConfusion() * Precision::PConfusion();
134
135 for( ; i <= nbSol; i++)
136 {
137 Standard_Real aU, aV;
138 myPoint(i).Parameter(aU, aV);
139 if( ((myU - aU ) * (myU - aU ) + (myV - aV ) * (myV - aV )) <= tol2d )
140 break;
141 }
142 if( i <= nbSol)
143 return 0;
7fd59977 144 mySqDist.Append(myPs.SquareDistance(myP));
145 myPoint.Append(Extrema_POnSurf(myU,myV,myPs));
146 return 0;
147}
148//=============================================================================
149
150Standard_Integer Extrema_FuncExtPS::NbExt () const
151{
152 return mySqDist.Length();
153}
154//=============================================================================
155
156Standard_Real Extrema_FuncExtPS::SquareDistance (const Standard_Integer N) const
157{
158 if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
159 return mySqDist.Value(N);
160}
161//=============================================================================
162
163Extrema_POnSurf Extrema_FuncExtPS::Point (const Standard_Integer N) const
164{
165 if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
166 return myPoint.Value(N);
167}