0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / Geom2dLProp / Geom2dLProp_FuncCurExt.cxx
1 // Created on: 1994-09-06
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1994-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 <Geom2d_Curve.hxx>
19 #include <Geom2dLProp_Curve2dTool.hxx>
20 #include <Geom2dLProp_FuncCurExt.hxx>
21 #include <gp.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <Precision.hxx>
24
25 //=============================================================================
26 //function :
27 // purpose :
28 //=============================================================================
29 Geom2dLProp_FuncCurExt::Geom2dLProp_FuncCurExt(const Handle(Geom2d_Curve)&  C,
30                                                const Standard_Real Tol)
31                                                :theCurve(C)
32 {
33   epsX  = Tol;
34 }
35
36 //=============================================================================
37 //function : Value 
38 // purpose : KC = (V1^V2.Z) / ||V1||^3  avec V1 tangente etV2 derivee seconde.
39 //           F  = d KC/ dU.
40 //=============================================================================
41 Standard_Boolean  Geom2dLProp_FuncCurExt::Value (const Standard_Real  X,
42                                                  Standard_Real& F)
43 {
44   gp_Pnt2d            P1;
45   gp_Vec2d            V1,V2,V3;
46
47   Geom2dLProp_Curve2dTool::D3(theCurve,X,P1,V1,V2,V3);
48   Standard_Real CPV1V2 = V1.Crossed(V2);
49   Standard_Real CPV1V3 = V1.Crossed(V3);
50   Standard_Real V1V2   = V1.Dot(V2);
51   Standard_Real V1V1   = V1.SquareMagnitude();
52   Standard_Real NV1    = Sqrt(V1V1);
53   Standard_Real V13    = V1V1*NV1;
54   Standard_Real V15    = V13*V1V1;
55
56   if (V15 < gp::Resolution()) {
57     return Standard_False;
58   }
59   F = CPV1V3/V13 - 3*CPV1V2*V1V2/V15;
60
61   return Standard_True;
62 }
63
64 //=============================================================================
65 //function : Derivative
66 // purpose :
67 //=============================================================================
68 Standard_Boolean Geom2dLProp_FuncCurExt::Derivative(const Standard_Real  X,
69                                                     Standard_Real& D)
70 {  
71   Standard_Real F;
72   return Values (X,F,D) ;
73 }
74
75 //=============================================================================
76 //function : Values
77 // purpose :
78 //=============================================================================
79 Standard_Boolean Geom2dLProp_FuncCurExt::Values (const Standard_Real  X,
80                                                  Standard_Real& F,
81                                                  Standard_Real& D)
82 {
83   Standard_Real F2;
84   Standard_Real Dx= epsX/100.;
85
86   if (X+Dx > Geom2dLProp_Curve2dTool::LastParameter(theCurve)) {Dx = - Dx;}
87
88   Value (X,F);
89   Value (X+Dx,F2);
90   D     = (F2 - F)/Dx;
91
92   return Standard_True;
93 }
94
95
96 //=============================================================================
97 //function : IsMinKC
98 // purpose : Teste si le parametere coorespond a un minimum du rayon de courbure
99 //           par comparaison avec un point voisin.
100 //=============================================================================
101 Standard_Boolean Geom2dLProp_FuncCurExt::IsMinKC (const Standard_Real  X) const
102 {
103   gp_Pnt2d            P1;
104   gp_Vec2d            V1,V2,V3;
105   Standard_Real  Dx= epsX;
106   Standard_Real  KC,KP;
107
108   Geom2dLProp_Curve2dTool::D3(theCurve,X,P1,V1,V2,V3);
109   Standard_Real CPV1V2 = V1.Crossed(V2);
110   Standard_Real V1V1   = V1.SquareMagnitude();
111   Standard_Real NV1    = Sqrt(V1V1);
112   Standard_Real V13    = V1V1*NV1;
113
114   if (V13 < gp::Resolution()) {return Standard_False;}
115
116   KC = CPV1V2/V13;
117
118   if (X+Dx > Geom2dLProp_Curve2dTool::LastParameter(theCurve)) {Dx = - Dx;}
119
120   Geom2dLProp_Curve2dTool::D3(theCurve,X+Dx,P1,V1,V2,V3);
121   CPV1V2 = V1.Crossed(V2);
122   V1V1   = V1.SquareMagnitude();
123   NV1    = Sqrt(V1V1);
124   V13    = V1V1*NV1;
125
126   if (V13 < gp::Resolution()) { return Standard_False;}
127   KP = CPV1V2/V13;
128
129   if   (Abs(KC) > Abs(KP)) {return Standard_True ;}
130   else                     {return Standard_False;} 
131
132 }