0032806: Coding - get rid of unused headers [Contap to Extrema]
[occt.git] / src / Expr / Expr_ArcSine.cxx
1 // Created on: 1991-05-27
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Expr.hxx>
19 #include <Expr_ArcSine.hxx>
20 #include <Expr_GeneralExpression.hxx>
21 #include <Expr_NamedUnknown.hxx>
22 #include <Expr_Operators.hxx>
23 #include <Expr_Sine.hxx>
24 #include <Expr_Square.hxx>
25 #include <Expr_SquareRoot.hxx>
26 #include <Standard_Type.hxx>
27 #include <TCollection_AsciiString.hxx>
28
29 IMPLEMENT_STANDARD_RTTIEXT(Expr_ArcSine,Expr_UnaryExpression)
30
31 Expr_ArcSine::Expr_ArcSine (const Handle(Expr_GeneralExpression)& exp)
32 {
33   CreateOperand(exp);
34 }
35
36 Handle(Expr_GeneralExpression) Expr_ArcSine::ShallowSimplified () const
37 {
38   Handle(Expr_GeneralExpression) op = Operand();
39   if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
40     Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
41     return new Expr_NumericValue(ASin(valop->GetValue()));
42   }
43   if (op->IsKind(STANDARD_TYPE(Expr_Sine))) {
44     return op->SubExpression(1);
45   }
46   Handle(Expr_ArcSine) me = this;
47   return me;
48 }
49
50 Handle(Expr_GeneralExpression) Expr_ArcSine::Copy () const 
51 {
52   return  new Expr_ArcSine(Expr::CopyShare(Operand()));
53 }
54
55 Standard_Boolean Expr_ArcSine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
56 {
57   if (!Other->IsKind(STANDARD_TYPE(Expr_ArcSine))) {
58     return Standard_False;
59   }
60   Handle(Expr_GeneralExpression) op = Operand();
61   return op->IsIdentical(Other->SubExpression(1));
62 }
63
64 Standard_Boolean Expr_ArcSine::IsLinear () const
65 {
66   if (ContainsUnknowns()) {
67     return Standard_False;
68   }
69   return Standard_True;
70 }
71
72 Handle(Expr_GeneralExpression) Expr_ArcSine::Derivative (const Handle(Expr_NamedUnknown)& X) const
73 {
74   if (!Contains(X)) {
75     return new Expr_NumericValue(0.0);
76   }
77   Handle(Expr_GeneralExpression) op = Operand();
78   Handle(Expr_GeneralExpression) derop = op->Derivative(X);
79
80   Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
81   // 1 - X2
82   Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified(); 
83
84   // sqrt(1-X2)
85   Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thedif->ShallowSimplified());
86
87   // ArcSine'(F(X)) = F'(X)/sqrt(1-F(X)2) 
88   Handle(Expr_Division) thediv = derop / theroot->ShallowSimplified(); 
89
90   return thediv->ShallowSimplified();
91 }
92
93 Standard_Real Expr_ArcSine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
94 {
95   return ::ASin(Operand()->Evaluate(vars,vals));
96 }
97
98 TCollection_AsciiString Expr_ArcSine::String() const
99 {
100   TCollection_AsciiString str("ASin(");
101   str += Operand()->String();
102   str += ")";
103   return str;
104 }