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_Tangent.ixx> |
23 | #include <Expr_NumericValue.hxx> |
24 | #include <Expr_ArcTangent.hxx> |
25 | #include <Expr_Cosine.hxx> |
26 | #include <Expr_Square.hxx> |
27 | #include <Expr_Division.hxx> |
28 | #include <Expr_Operators.hxx> |
29 | #include <Expr.hxx> |
30 | |
31 | Expr_Tangent::Expr_Tangent(const Handle(Expr_GeneralExpression)& exp) |
32 | { |
33 | CreateOperand(exp); |
34 | } |
35 | |
36 | Handle(Expr_GeneralExpression) Expr_Tangent::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(Tan(myNVexp->GetValue())); |
42 | } |
43 | if (myexp->IsKind(STANDARD_TYPE(Expr_ArcTangent))) { |
44 | return myexp->SubExpression(1); |
45 | } |
46 | Handle(Expr_Tangent) me = this; |
47 | return me; |
48 | } |
49 | |
50 | Handle(Expr_GeneralExpression) Expr_Tangent::Copy () const |
51 | { |
52 | return new Expr_Tangent(Expr::CopyShare(Operand())); |
53 | } |
54 | |
55 | Standard_Boolean Expr_Tangent::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
56 | { |
57 | if (Other->IsKind(STANDARD_TYPE(Expr_Tangent))) { |
58 | Handle(Expr_GeneralExpression) myexp = Operand(); |
59 | return myexp->IsIdentical(Other->SubExpression(1)); |
60 | } |
61 | return Standard_False; |
62 | } |
63 | |
64 | Standard_Boolean Expr_Tangent::IsLinear () const |
65 | { |
66 | return !ContainsUnknowns(); |
67 | } |
68 | |
69 | Handle(Expr_GeneralExpression) Expr_Tangent::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_Cosine) firstder = new Expr_Cosine(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 | |
82 | Standard_Real Expr_Tangent::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
83 | { |
84 | return ::Tan(Operand()->Evaluate(vars,vals)); |
85 | } |
86 | |
87 | TCollection_AsciiString Expr_Tangent::String() const |
88 | { |
89 | TCollection_AsciiString str("Tan("); |
90 | str += Operand()->String(); |
91 | str +=")"; |
92 | return str; |
93 | } |