Warnings on vc14 were eliminated
[occt.git] / src / Expr / Expr_Tangent.cxx
CommitLineData
b311480e 1// Created on: 1991-05-28
2// Created by: Arnaud BOUZY
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Expr.hxx>
7fd59977 19#include <Expr_ArcTangent.hxx>
20#include <Expr_Cosine.hxx>
7fd59977 21#include <Expr_Division.hxx>
42cf5bc1 22#include <Expr_GeneralExpression.hxx>
23#include <Expr_NamedUnknown.hxx>
24#include <Expr_NotEvaluable.hxx>
25#include <Expr_NumericValue.hxx>
7fd59977 26#include <Expr_Operators.hxx>
42cf5bc1 27#include <Expr_Square.hxx>
28#include <Expr_Tangent.hxx>
29#include <Standard_NumericError.hxx>
30#include <Standard_Type.hxx>
31#include <TCollection_AsciiString.hxx>
7fd59977 32
92efcf78 33IMPLEMENT_STANDARD_RTTIEXT(Expr_Tangent,Expr_UnaryExpression)
34
7fd59977 35Expr_Tangent::Expr_Tangent(const Handle(Expr_GeneralExpression)& exp)
36{
37 CreateOperand(exp);
38}
39
40Handle(Expr_GeneralExpression) Expr_Tangent::ShallowSimplified () const
41{
42 Handle(Expr_GeneralExpression) myexp = Operand();
43 if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
44 Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
45 return new Expr_NumericValue(Tan(myNVexp->GetValue()));
46 }
47 if (myexp->IsKind(STANDARD_TYPE(Expr_ArcTangent))) {
48 return myexp->SubExpression(1);
49 }
50 Handle(Expr_Tangent) me = this;
51 return me;
52}
53
54Handle(Expr_GeneralExpression) Expr_Tangent::Copy () const
55{
56 return new Expr_Tangent(Expr::CopyShare(Operand()));
57}
58
59Standard_Boolean Expr_Tangent::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
60{
61 if (Other->IsKind(STANDARD_TYPE(Expr_Tangent))) {
62 Handle(Expr_GeneralExpression) myexp = Operand();
63 return myexp->IsIdentical(Other->SubExpression(1));
64 }
65 return Standard_False;
66}
67
68Standard_Boolean Expr_Tangent::IsLinear () const
69{
70 return !ContainsUnknowns();
71}
72
73Handle(Expr_GeneralExpression) Expr_Tangent::Derivative (const Handle(Expr_NamedUnknown)& X) const
74{
75 if (!Contains(X)) {
76 return new Expr_NumericValue(0.0);
77 }
78 Handle(Expr_GeneralExpression) myexp = Operand();
79 Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
80 Handle(Expr_Cosine) firstder = new Expr_Cosine(Expr::CopyShare(myexp));
81 Handle(Expr_Square) sq = new Expr_Square(firstder->ShallowSimplified());
82 Handle(Expr_Division) resu = myder / sq->ShallowSimplified();
83 return resu->ShallowSimplified();
84}
85
86Standard_Real Expr_Tangent::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
87{
88 return ::Tan(Operand()->Evaluate(vars,vals));
89}
90
91TCollection_AsciiString Expr_Tangent::String() const
92{
93 TCollection_AsciiString str("Tan(");
94 str += Operand()->String();
95 str +=")";
96 return str;
97}