Test for 0022778: Bug in BRepMesh
[occt.git] / src / Expr / Expr_ArgTanh.cxx
1 // Created on: 1991-05-27
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-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 #include <Expr_ArgTanh.ixx>
23 #include <Expr_NumericValue.hxx>
24 #include <Expr_Tanh.hxx>
25 #include <Expr_Division.hxx>
26 #include <Expr_Square.hxx>
27 #include <Expr_Difference.hxx>
28 #include <Expr_Operators.hxx>
29 #include <Expr.hxx>
30
31 Expr_ArgTanh::Expr_ArgTanh (const Handle(Expr_GeneralExpression)& exp)
32 {
33   CreateOperand(exp);
34 }
35
36 Handle(Expr_GeneralExpression) Expr_ArgTanh::ShallowSimplified () const
37 {
38   Handle(Expr_GeneralExpression) op = Operand();
39   if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
40     Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
41     return new Expr_NumericValue(ATanh(valop->GetValue()));
42   }
43   if (op->IsKind(STANDARD_TYPE(Expr_Tanh))) {
44     return op->SubExpression(1);
45   }
46   Handle(Expr_ArgTanh) me = this;
47   return me;
48 }
49
50 Handle(Expr_GeneralExpression) Expr_ArgTanh::Copy () const 
51 {
52   return  new Expr_ArgTanh(Expr::CopyShare(Operand()));
53 }
54
55 Standard_Boolean Expr_ArgTanh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
56 {
57   if (!Other->IsKind(STANDARD_TYPE(Expr_ArgTanh))) {
58     return Standard_False;
59   }
60   Handle(Expr_GeneralExpression) op = Operand();
61   return op->IsIdentical(Other->SubExpression(1));
62 }
63
64 Standard_Boolean Expr_ArgTanh::IsLinear () const
65 {
66   if (ContainsUnknowns()) {
67     return Standard_False;
68   }
69   return Standard_True;
70 }
71
72 Handle(Expr_GeneralExpression) Expr_ArgTanh::Derivative (const Handle(Expr_NamedUnknown)& X) const
73 {
74   if (!Contains(X)) {
75     return new Expr_NumericValue(0.0);
76   }
77   Handle(Expr_GeneralExpression) op = Operand();
78   Handle(Expr_GeneralExpression) derop = op->Derivative(X);
79
80   Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
81
82   // 1 - X2
83
84   Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified(); 
85
86   // ArgTanh'(F(X)) = F'(X)/(1 - F(X)2) 
87   Handle(Expr_Division) thediv = derop / thedif->ShallowSimplified(); 
88
89   return thediv->ShallowSimplified();
90 }
91
92 Standard_Real Expr_ArgTanh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
93 {
94   Standard_Real val = Operand()->Evaluate(vars,vals);
95   return ::Log((1.0+val)/(1.0-val))/2.0;
96 }
97
98 TCollection_AsciiString Expr_ArgTanh::String() const
99 {
100   TCollection_AsciiString str("ATanh(");
101   str += Operand()->String();
102   str += ")";
103   return str;
104 }