Test for 0022778: Bug in BRepMesh
[occt.git] / src / Expr / Expr_Tanh.cxx
CommitLineData
b311480e 1// Created on: 1991-05-28
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
7fd59977 21
22#include <Expr_Tanh.ixx>
23#include <Expr_NumericValue.hxx>
24#include <Expr_ArgTanh.hxx>
25#include <Expr_Cosh.hxx>
26#include <Expr_Square.hxx>
27#include <Expr_Division.hxx>
28#include <Expr_Operators.hxx>
29#include <Expr.hxx>
30
31Expr_Tanh::Expr_Tanh(const Handle(Expr_GeneralExpression)& exp)
32{
33 CreateOperand(exp);
34}
35
36Handle(Expr_GeneralExpression) Expr_Tanh::ShallowSimplified () const
37{
38 Handle(Expr_GeneralExpression) myexp = Operand();
39 if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
40 Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
41 return new Expr_NumericValue(Tanh(myNVexp->GetValue()));
42 }
43 if (myexp->IsKind(STANDARD_TYPE(Expr_ArgTanh))) {
44 return myexp->SubExpression(1);
45 }
46 Handle(Expr_Tanh) me = this;
47 return me;
48}
49
50Handle(Expr_GeneralExpression) Expr_Tanh::Copy () const
51{
52 return new Expr_Tanh(Expr::CopyShare(Operand()));
53}
54
55Standard_Boolean Expr_Tanh::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
56{
57 if (Other->IsKind(STANDARD_TYPE(Expr_Tanh))) {
58 Handle(Expr_GeneralExpression) myexp = Operand();
59 return myexp->IsIdentical(Other->SubExpression(1));
60 }
61 return Standard_False;
62}
63
64Standard_Boolean Expr_Tanh::IsLinear () const
65{
66 return !ContainsUnknowns();
67}
68
69Handle(Expr_GeneralExpression) Expr_Tanh::Derivative (const Handle(Expr_NamedUnknown)& X) const
70{
71 if (!Contains(X)) {
72 return new Expr_NumericValue(0.0);
73 }
74 Handle(Expr_GeneralExpression) myexp = Operand();
75 Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
76 Handle(Expr_Cosh) firstder = new Expr_Cosh(Expr::CopyShare(myexp));
77 Handle(Expr_Square) sq = new Expr_Square(firstder->ShallowSimplified());
78 Handle(Expr_Division) resu = myder / sq->ShallowSimplified();
79 return resu->ShallowSimplified();
80}
81
82Standard_Real Expr_Tanh::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
83{
84 Standard_Real val = Operand()->Evaluate(vars,vals);
85 return (::Exp(val)-::Exp(-val))/(::Exp(val)+::Exp(-val));
86}
87
88TCollection_AsciiString Expr_Tanh::String() const
89{
90 TCollection_AsciiString str("Tanh(");
91 str += Operand()->String();
92 str += ")";
93 return str;
94}