0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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-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 <Expr.hxx>
19 #include <Expr_ArgTanh.hxx>
20 #include <Expr_Difference.hxx>
21 #include <Expr_Division.hxx>
22 #include <Expr_GeneralExpression.hxx>
23 #include <Expr_NamedUnknown.hxx>
24 #include <Expr_NotEvaluable.hxx>
25 #include <Expr_NumericValue.hxx>
26 #include <Expr_Operators.hxx>
27 #include <Expr_Square.hxx>
28 #include <Expr_Tanh.hxx>
29 #include <Standard_NumericError.hxx>
30 #include <Standard_Type.hxx>
31 #include <TCollection_AsciiString.hxx>
32
33 IMPLEMENT_STANDARD_RTTIEXT(Expr_ArgTanh,Expr_UnaryExpression)
34
35 Expr_ArgTanh::Expr_ArgTanh (const Handle(Expr_GeneralExpression)& exp)
36 {
37   CreateOperand(exp);
38 }
39
40 Handle(Expr_GeneralExpression) Expr_ArgTanh::ShallowSimplified () const
41 {
42   Handle(Expr_GeneralExpression) op = Operand();
43   if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
44     Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
45     return new Expr_NumericValue(ATanh(valop->GetValue()));
46   }
47   if (op->IsKind(STANDARD_TYPE(Expr_Tanh))) {
48     return op->SubExpression(1);
49   }
50   Handle(Expr_ArgTanh) me = this;
51   return me;
52 }
53
54 Handle(Expr_GeneralExpression) Expr_ArgTanh::Copy () const 
55 {
56   return  new Expr_ArgTanh(Expr::CopyShare(Operand()));
57 }
58
59 Standard_Boolean Expr_ArgTanh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
60 {
61   if (!Other->IsKind(STANDARD_TYPE(Expr_ArgTanh))) {
62     return Standard_False;
63   }
64   Handle(Expr_GeneralExpression) op = Operand();
65   return op->IsIdentical(Other->SubExpression(1));
66 }
67
68 Standard_Boolean Expr_ArgTanh::IsLinear () const
69 {
70   if (ContainsUnknowns()) {
71     return Standard_False;
72   }
73   return Standard_True;
74 }
75
76 Handle(Expr_GeneralExpression) Expr_ArgTanh::Derivative (const Handle(Expr_NamedUnknown)& X) const
77 {
78   if (!Contains(X)) {
79     return new Expr_NumericValue(0.0);
80   }
81   Handle(Expr_GeneralExpression) op = Operand();
82   Handle(Expr_GeneralExpression) derop = op->Derivative(X);
83
84   Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
85
86   // 1 - X2
87
88   Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified(); 
89
90   // ArgTanh'(F(X)) = F'(X)/(1 - F(X)2) 
91   Handle(Expr_Division) thediv = derop / thedif->ShallowSimplified(); 
92
93   return thediv->ShallowSimplified();
94 }
95
96 Standard_Real Expr_ArgTanh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
97 {
98   Standard_Real val = Operand()->Evaluate(vars,vals);
99   return ::Log((1.0+val)/(1.0-val))/2.0;
100 }
101
102 TCollection_AsciiString Expr_ArgTanh::String() const
103 {
104   TCollection_AsciiString str("ATanh(");
105   str += Operand()->String();
106   str += ")";
107   return str;
108 }