0023360: Test cases for command mkoffset produce different results on different versi...
[occt.git] / src / Bisector / Bisector_FunctionH.cxx
1 // Created on: 1994-04-05
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1994-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
21
22
23 #include <Bisector_FunctionH.ixx>
24 #include <Geom2d_Curve.hxx>
25
26 //=============================================================================
27 //function :
28 // purpose :
29 //=============================================================================
30 Bisector_FunctionH::Bisector_FunctionH (const Handle(Geom2d_Curve)& C2,
31                                         const gp_Pnt2d&             P1,
32                                         const gp_Vec2d&             T1)
33      :p1(P1),t1(T1)
34 {
35   t1.Normalize();
36   curve2 = C2;
37 }
38
39 //=============================================================================
40 //function : Value
41 // purpose :
42 //                F = P1P2.(||T2||T1 + T2)
43 //=============================================================================
44 Standard_Boolean Bisector_FunctionH::Value (const Standard_Real  X,
45                                                   Standard_Real& F)
46 {
47   gp_Pnt2d P2  ;      // point sur C2. 
48   gp_Vec2d T2  ;      // tangente a C2 en V.
49   curve2->D1(X,P2,T2);  
50
51   Standard_Real NormT2 = T2.Magnitude();
52   Standard_Real Ax     = NormT2*t1.X() - T2.X();
53   Standard_Real Ay     = NormT2*t1.Y() - T2.Y();
54
55   F = (p1.X() - P2.X())*Ax + (p1.Y() - P2.Y())*Ay;
56
57   return Standard_True;
58 }
59
60 //=============================================================================
61 //function : Derivative
62 // purpose :
63 //=============================================================================
64 Standard_Boolean Bisector_FunctionH::Derivative(const Standard_Real  X,
65                                                       Standard_Real& D)
66 {
67   Standard_Real F;
68   return Values (X,F,D);
69 }
70
71 //=============================================================================
72 //function : Values
73 // purpose :
74 //=============================================================================
75 Standard_Boolean Bisector_FunctionH::Values (const Standard_Real  X,
76                                                    Standard_Real& F,
77                                                    Standard_Real& D)
78 {
79   gp_Pnt2d P2  ;      // point sur C2. 
80   gp_Vec2d T2  ;      // tangente a C2 en V.
81   gp_Vec2d T2v ;      // derivee seconde a C2 en V.
82
83   curve2->D2(X,P2,T2,T2v); 
84  
85   Standard_Real NormT2 = T2.Magnitude();
86   Standard_Real Ax     = NormT2*t1.X() - T2.X();
87   Standard_Real Ay     = NormT2*t1.Y() - T2.Y();
88
89   F = (p1.X() - P2.X())*Ax + (p1.Y() - P2.Y())*Ay;
90
91   Standard_Real Scal = T2.Dot(T2v)/NormT2;
92   Standard_Real dAx  = Scal*t1.X() - T2v.X();
93   Standard_Real dAy  = Scal*t1.Y() - T2v.Y();
94   
95   D = - T2.X()*Ax - T2.Y()*Ay + (p1.X() - P2.X())*dAx + (p1.Y() - P2.Y())*dAy;
96   
97
98   return Standard_True;
99
100 }
101