b311480e |
1 | // Created on: 1991-05-27 |
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_ArcCosine.hxx> |
42cf5bc1 |
20 | #include <Expr_Cosine.hxx> |
21 | #include <Expr_GeneralExpression.hxx> |
22 | #include <Expr_NamedUnknown.hxx> |
23 | #include <Expr_NotEvaluable.hxx> |
24 | #include <Expr_NumericValue.hxx> |
25 | #include <Expr_Operators.hxx> |
26 | #include <Expr_Product.hxx> |
7fd59977 |
27 | #include <Expr_Sine.hxx> |
28 | #include <Expr_UnaryMinus.hxx> |
42cf5bc1 |
29 | #include <Standard_NumericError.hxx> |
30 | #include <Standard_Type.hxx> |
31 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
32 | |
92efcf78 |
33 | IMPLEMENT_STANDARD_RTTIEXT(Expr_Cosine,Expr_UnaryExpression) |
34 | |
7fd59977 |
35 | Expr_Cosine::Expr_Cosine(const Handle(Expr_GeneralExpression)& exp) |
36 | { |
37 | CreateOperand(exp); |
38 | } |
39 | |
40 | Handle(Expr_GeneralExpression) Expr_Cosine::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(Cos(myNVexp->GetValue())); |
46 | } |
47 | if (myexp->IsKind(STANDARD_TYPE(Expr_ArcCosine))) { |
48 | return myexp->SubExpression(1); |
49 | } |
50 | Handle(Expr_Cosine) me = this; |
51 | return me; |
52 | } |
53 | |
54 | Handle(Expr_GeneralExpression) Expr_Cosine::Copy () const |
55 | { |
56 | return new Expr_Cosine(Expr::CopyShare(Operand())); |
57 | } |
58 | |
59 | Standard_Boolean Expr_Cosine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
60 | { |
61 | if (Other->IsKind(STANDARD_TYPE(Expr_Cosine))) { |
62 | Handle(Expr_GeneralExpression) myexp = Operand(); |
63 | return myexp->IsIdentical(Other->SubExpression(1)); |
64 | } |
65 | return Standard_False; |
66 | } |
67 | |
68 | Standard_Boolean Expr_Cosine::IsLinear () const |
69 | { |
70 | return !ContainsUnknowns(); |
71 | } |
72 | |
73 | Handle(Expr_GeneralExpression) Expr_Cosine::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_Sine) firstder = new Expr_Sine(Expr::CopyShare(myexp)); |
81 | Handle(Expr_UnaryMinus) fder = - (firstder->ShallowSimplified()); |
82 | Handle(Expr_Product) resu = fder->ShallowSimplified() * myder; |
83 | return resu->ShallowSimplified(); |
84 | } |
85 | |
86 | Standard_Real Expr_Cosine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
87 | { |
88 | return ::Cos(Operand()->Evaluate(vars,vals)); |
89 | } |
90 | |
91 | TCollection_AsciiString Expr_Cosine::String() const |
92 | { |
93 | TCollection_AsciiString str("Cos("); |
94 | str += Operand()->String(); |
95 | str += ")"; |
96 | return str; |
97 | } |