summaryrefslogtreecommitdiff
path: root/src/ProjLib/ProjLib_PrjResolve.cxx
blob: d51e99effa994457f65987c7737cbb04cb26fed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// File:	ProjLib_PrjResolve.cxx
// Created:	Thu Nov  6 14:02:04 1997
// Author:	Roman BORISOV
//		<rbv@redfox.nnov.matra-dtv.fr>


#include <ProjLib_PrjResolve.ixx>
#include <ProjLib_PrjFunc.hxx>
#include <math_FunctionSetRoot.hxx>
#include <math_NewtonFunctionSetRoot.hxx>

 ProjLib_PrjResolve::ProjLib_PrjResolve(const Adaptor3d_Curve& C,const Adaptor3d_Surface& S,const Standard_Integer Fix) : myFix(Fix)
{
  if (myFix > 3 || myFix < 1) Standard_ConstructionError::Raise();
  mySolution = gp_Pnt2d(0.,0.);
  myCurve    = (Adaptor3d_CurvePtr)&C;
  mySurface  = (Adaptor3d_SurfacePtr)&S; 
}

// void ProjLib_PrjResolve::Perform(const Standard_Real t, const Standard_Real U, const Standard_Real  V, const gp_Pnt2d& Tol2d, const gp_Pnt2d& Inf, const gp_Pnt2d& Sup, const Standard_Real FuncTol, const Standard_Boolean StrictInside)
 void ProjLib_PrjResolve::Perform(const Standard_Real t, const Standard_Real U, const Standard_Real  V, const gp_Pnt2d& Tol2d, const gp_Pnt2d& Inf, const gp_Pnt2d& Sup, const Standard_Real FuncTol, const Standard_Boolean )
{

  myDone = Standard_False;
  Standard_Real FixVal = 0.;
  gp_Pnt2d ExtInf(0.,0.), ExtSup(0.,0.);
  Standard_Real ExtU = 10*Tol2d.X(), ExtV = 10*Tol2d.Y();
  math_Vector Tol(1, 2), Start(1, 2), BInf(1, 2), BSup(1, 2);

  ExtInf.SetCoord(Inf.X() - ExtU, Inf.Y() - ExtV);
  ExtSup.SetCoord(Sup.X() + ExtU, Sup.Y() + ExtV);
  BInf(1) = ExtInf.X();
  BInf(2) = ExtInf.Y();
  BSup(1) = ExtSup.X();
  BSup(2) = ExtSup.Y();
  Tol(1) = Tol2d.X();
  Tol(2) = Tol2d.Y();
 
  switch(myFix) {
  case 1:
    Start(1) = U;
    Start(2) = V;
    FixVal = t;
    break;
  case 2:
    Start(1) = t;
    Start(2) = V;
    FixVal = U;
    break;
  case 3:
    Start(1) = t;
    Start(2) = U;
    FixVal = V;
  }

  ProjLib_PrjFunc F(myCurve, FixVal, mySurface, myFix);
  

//  Standard_Integer option = 1;//2;
//  if (option == 1) {
//    math_FunctionSetRoot S1 (F, Start,Tol, BInf, BSup);
//    if (!S1.IsDone()) { return; }
//  }
//  else {
    math_NewtonFunctionSetRoot SR (F, Tol, 1.e-10);
    SR.Perform(F, Start, BInf, BSup);
//    if (!SR.IsDone()) { return; }
    if (!SR.IsDone()) {
        math_FunctionSetRoot S1 (F, Start,Tol, BInf, BSup);
        if (!S1.IsDone()) { return; }
    }
   


  mySolution.SetXY(F.Solution().XY());

// computation of myDone
  myDone = Standard_True;

  Standard_Real ExtraU , ExtraV;
//  if(!StrictInside) {
    ExtraU = Tol2d.X();
    ExtraV = Tol2d.Y();
//  }
  if (Abs(mySolution.X()-Inf.X()) < Tol2d.X()) mySolution.SetX(Inf.X());
  if (Abs(mySolution.X()-Sup.X()) < Tol2d.X()) mySolution.SetX(Sup.X()); 
  if (Abs(mySolution.Y()-Inf.Y()) < Tol2d.Y()) mySolution.SetY(Inf.Y());
  if (Abs(mySolution.Y()-Sup.Y()) < Tol2d.Y()) mySolution.SetY(Sup.Y()); 
  if (mySolution.X() < Inf.X() - ExtraU || 
      mySolution.X() > Sup.X() + ExtraU ||
      mySolution.Y() < Inf.Y() - ExtraV || 
      mySolution.Y() > Sup.Y() + ExtraV) myDone = Standard_False;
  else if (FuncTol > 0) {
    math_Vector X(1,2,0.), FVal(1,2,0.);
    X(1) = mySolution.X();
    X(2) = mySolution.Y();

    
    F.Value(X, FVal);   

    if ((FVal(1)*FVal(1) + FVal(2)*FVal(2)) > FuncTol) myDone = Standard_False;
  }


}

 Standard_Boolean ProjLib_PrjResolve::IsDone() const
{
  return myDone;
}

 gp_Pnt2d ProjLib_PrjResolve::Solution() const
{
  if (!IsDone())  StdFail_NotDone::Raise(); 
  return mySolution;
}