0022923: The command 'intersect' throws an exception.
[occt.git] / src / Expr / Expr_Cosine.cxx
1 //static const char* sccsid = "@(#)Expr_Cosine.cxx      3.2 95/01/10"; // Do not delete this line. Used by sccs.
2 // Copyright:   Matra-Datavision 1991
3 // File:        Expr_Cosine.cxx
4 // Created:     Mon May 27 17:24:38 1991
5 // Author:      Arnaud BOUZY
6 //              <adn>
7
8 #include <Expr_Cosine.ixx>
9 #include <Expr_NumericValue.hxx>
10 #include <Expr_ArcCosine.hxx>
11 #include <Expr_Sine.hxx>
12 #include <Expr_UnaryMinus.hxx>
13 #include <Expr_Product.hxx>
14 #include <Expr_Operators.hxx>
15 #include <Expr.hxx>
16
17 Expr_Cosine::Expr_Cosine(const Handle(Expr_GeneralExpression)& exp)
18 {
19   CreateOperand(exp);
20 }
21
22 Handle(Expr_GeneralExpression) Expr_Cosine::ShallowSimplified () const
23 {
24   Handle(Expr_GeneralExpression) myexp = Operand();
25   if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
26     Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
27     return new Expr_NumericValue(Cos(myNVexp->GetValue()));
28   }
29   if (myexp->IsKind(STANDARD_TYPE(Expr_ArcCosine))) {
30     return myexp->SubExpression(1);
31   }
32   Handle(Expr_Cosine) me = this;
33   return me;
34 }
35
36 Handle(Expr_GeneralExpression) Expr_Cosine::Copy () const
37 {
38   return new Expr_Cosine(Expr::CopyShare(Operand()));
39 }
40
41 Standard_Boolean Expr_Cosine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
42 {
43   if (Other->IsKind(STANDARD_TYPE(Expr_Cosine))) {
44     Handle(Expr_GeneralExpression) myexp = Operand();
45     return myexp->IsIdentical(Other->SubExpression(1));
46   }
47   return Standard_False;
48 }
49
50 Standard_Boolean Expr_Cosine::IsLinear () const
51 {
52   return !ContainsUnknowns();
53 }
54
55 Handle(Expr_GeneralExpression) Expr_Cosine::Derivative (const Handle(Expr_NamedUnknown)& X) const
56 {
57   if (!Contains(X)) {
58     return new Expr_NumericValue(0.0);
59   }
60   Handle(Expr_GeneralExpression) myexp = Operand();
61   Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
62   Handle(Expr_Sine) firstder = new Expr_Sine(Expr::CopyShare(myexp));
63   Handle(Expr_UnaryMinus) fder = - (firstder->ShallowSimplified());
64   Handle(Expr_Product) resu = fder->ShallowSimplified() * myder;
65   return resu->ShallowSimplified();
66 }
67
68 Standard_Real Expr_Cosine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
69 {
70   return ::Cos(Operand()->Evaluate(vars,vals));
71 }
72
73 TCollection_AsciiString Expr_Cosine::String() const
74 {
75   TCollection_AsciiString str("Cos(");
76   str += Operand()->String();
77   str += ")";
78   return str;
79 }