1 //static const char* sccsid = "@(#)Expr_Square.cxx 3.2 95/01/10"; // Do not delete this line. Used by sccs.
2 // Copyright: Matra-Datavision 1991
3 // File: Expr_Square.cxx
4 // Created: Fri Apr 19 10:05:26 1991
5 // Author: Arnaud BOUZY
8 #include <Expr_Square.ixx>
9 #include <Expr_NumericValue.hxx>
10 #include <Expr_SquareRoot.hxx>
11 #include <Expr_SequenceOfGeneralExpression.hxx>
12 #include <Expr_Product.hxx>
13 #include <Expr_Exponentiate.hxx>
14 #include <Expr_Operators.hxx>
17 Expr_Square::Expr_Square (const Handle(Expr_GeneralExpression)& exp)
22 Handle(Expr_GeneralExpression) Expr_Square::ShallowSimplified () const
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(Square(myNVexp->GetValue()));
29 if (myexp->IsKind(STANDARD_TYPE(Expr_SquareRoot))) {
30 return myexp->SubExpression(1);
32 if (myexp->IsKind(STANDARD_TYPE(Expr_Square))) {
33 Handle(Expr_GeneralExpression) op = myexp->SubExpression(1);
34 Handle(Expr_NumericValue) val4 = new Expr_NumericValue(4.0);
35 return new Expr_Exponentiate(op,val4);
37 if (myexp->IsKind(STANDARD_TYPE(Expr_Exponentiate))) {
38 Handle(Expr_GeneralExpression) op = myexp->SubExpression(1);
39 Handle(Expr_GeneralExpression) puis = myexp->SubExpression(2);
40 Handle(Expr_Product) newpuis = 2.0 * puis;
41 Handle(Expr_Exponentiate) res = new Expr_Exponentiate(op,newpuis->ShallowSimplified());
42 return res->ShallowSimplified();
44 Handle(Expr_Square) me = this;
48 Handle(Expr_GeneralExpression) Expr_Square::Copy () const
50 return new Expr_Square(Expr::CopyShare(Operand()));
53 Standard_Boolean Expr_Square::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
55 if (Other->IsKind(STANDARD_TYPE(Expr_Square))) {
56 return Operand()->IsIdentical(Other->SubExpression(1));
58 return Standard_False;
61 Standard_Boolean Expr_Square::IsLinear () const
63 return !ContainsUnknowns();
66 Handle(Expr_GeneralExpression) Expr_Square::Derivative (const Handle(Expr_NamedUnknown)& X) const
69 return new Expr_NumericValue(0.0);
71 Handle(Expr_GeneralExpression) myder = Operand();
72 myder = myder->Derivative(X);
73 Handle(Expr_NumericValue) coef = new Expr_NumericValue(2.0);
74 Expr_SequenceOfGeneralExpression ops;
77 Handle(Expr_GeneralExpression) usedop = Expr::CopyShare(Operand());
79 Handle(Expr_Product) resu = new Expr_Product(ops);
80 return resu->ShallowSimplified();
83 Standard_Real Expr_Square::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
85 Standard_Real val = Operand()->Evaluate(vars,vals);
89 TCollection_AsciiString Expr_Square::String() const
91 TCollection_AsciiString str;
92 Handle(Expr_GeneralExpression) op = Operand();
93 if (op->NbSubExpressions() > 1) {