0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Expr / Expr_Sine.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_ArcSine.hxx>
20#include <Expr_Cosine.hxx>
42cf5bc1 21#include <Expr_GeneralExpression.hxx>
22#include <Expr_NamedUnknown.hxx>
23#include <Expr_NotEvaluable.hxx>
24#include <Expr_NumericValue.hxx>
7fd59977 25#include <Expr_Operators.hxx>
42cf5bc1 26#include <Expr_Product.hxx>
27#include <Expr_Sine.hxx>
28#include <Standard_NumericError.hxx>
29#include <Standard_Type.hxx>
30#include <TCollection_AsciiString.hxx>
7fd59977 31
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(Expr_Sine,Expr_UnaryExpression)
33
7fd59977 34Expr_Sine::Expr_Sine(const Handle(Expr_GeneralExpression)& exp)
35{
36 CreateOperand(exp);
37}
38
39Handle(Expr_GeneralExpression) Expr_Sine::ShallowSimplified () const
40{
41 Handle(Expr_GeneralExpression) myexp = Operand();
42 if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
43 Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
44 return new Expr_NumericValue(Sin(myNVexp->GetValue()));
45 }
46 if (myexp->IsKind(STANDARD_TYPE(Expr_ArcSine))) {
47 return myexp->SubExpression(1);
48 }
49 Handle(Expr_Sine) me = this;
50 return me;
51}
52
53Handle(Expr_GeneralExpression) Expr_Sine::Copy () const
54{
55 return new Expr_Sine(Expr::CopyShare(Operand()));
56}
57
58Standard_Boolean Expr_Sine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
59{
60 if (Other->IsKind(STANDARD_TYPE(Expr_Sine))) {
61 Handle(Expr_GeneralExpression) myexp = Operand();
62 return myexp->IsIdentical(Other->SubExpression(1));
63 }
64 return Standard_False;
65}
66
67Standard_Boolean Expr_Sine::IsLinear () const
68{
69 return !ContainsUnknowns();
70}
71
72Handle(Expr_GeneralExpression) Expr_Sine::Derivative (const Handle(Expr_NamedUnknown)& X) const
73{
74 if (!Contains(X)) {
75 return new Expr_NumericValue(0.0);
76 }
77 Handle(Expr_GeneralExpression) myexp = Operand();
78 Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
79 Handle(Expr_Cosine) firstder = new Expr_Cosine(Expr::CopyShare(myexp));
80 Handle(Expr_Product) resu = firstder->ShallowSimplified() * myder;
81 return resu->ShallowSimplified();
82}
83
84Standard_Real Expr_Sine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
85{
86 return ::Sin(Operand()->Evaluate(vars,vals));
87}
88
89TCollection_AsciiString Expr_Sine::String() const
90{
91 TCollection_AsciiString str("Sin(");
92 str += Operand()->String();
93 str += ")";
94 return str;
95}