0022904: Clean up sccsid variables
[occt.git] / src / Expr / Expr_SquareRoot.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1991
2// File: Expr_Root.cxx
3// Created: Tue May 28 12:39:37 1991
4// Author: Arnaud BOUZY
5// <adn>
6
7#include <Expr_SquareRoot.ixx>
8#include <Expr_NumericValue.hxx>
9#include <Expr_Square.hxx>
10#include <Expr_Product.hxx>
11#include <Expr_Division.hxx>
12#include <Expr_Operators.hxx>
13#include <Expr.hxx>
14
15Expr_SquareRoot::Expr_SquareRoot (const Handle(Expr_GeneralExpression)& exp)
16{
17 CreateOperand(exp);
18}
19
20Handle(Expr_GeneralExpression) Expr_SquareRoot::ShallowSimplified () const
21{
22 Handle(Expr_GeneralExpression) myexp = Operand();
23 if (myexp->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
24 Handle(Expr_NumericValue) myNVexp = Handle(Expr_NumericValue)::DownCast(myexp);
25 return new Expr_NumericValue(Sqrt(myNVexp->GetValue()));
26 }
27 if (myexp->IsKind(STANDARD_TYPE(Expr_Square))) {
28 return myexp->SubExpression(1);
29 }
30 Handle(Expr_SquareRoot) me = this;
31 return me;
32}
33
34Handle(Expr_GeneralExpression) Expr_SquareRoot::Copy () const
35{
36 return new Expr_SquareRoot(Expr::CopyShare(Operand()));
37}
38
39Standard_Boolean Expr_SquareRoot::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
40{
41 if (Other->IsKind(STANDARD_TYPE(Expr_SquareRoot))) {
42 return Operand()->IsIdentical(Other->SubExpression(1));
43 }
44 return Standard_False;
45}
46
47Standard_Boolean Expr_SquareRoot::IsLinear () const
48{
49 return !ContainsUnknowns();
50}
51
52Handle(Expr_GeneralExpression) Expr_SquareRoot::Derivative (const Handle(Expr_NamedUnknown)& X) const
53{
54 if (!Contains(X)) {
55 return new Expr_NumericValue(0.0);
56 }
57 Handle(Expr_GeneralExpression) myexp = Operand();
58 Handle(Expr_GeneralExpression) myder = myexp->Derivative(X);
59 Handle(Expr_SquareRoot) sq = new Expr_SquareRoot(Expr::CopyShare(myexp));
60 Handle(Expr_Product) theprod = 2.0 * sq;
61 Handle(Expr_Division) resu = myder / theprod->ShallowSimplified();
62 return resu->ShallowSimplified();
63}
64
65
66Standard_Real Expr_SquareRoot::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
67{
68 return ::Sqrt(Operand()->Evaluate(vars,vals));
69}
70
71TCollection_AsciiString Expr_SquareRoot::String() const
72{
73 TCollection_AsciiString str("Sqrt(");
74 str += Operand()->String();
75 str += ")";
76 return str;
77}