0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / Expr / Expr_Absolute.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_Absolute.hxx>
20 #include <Expr_GeneralExpression.hxx>
21 #include <Expr_NamedUnknown.hxx>
22 #include <Expr_NotEvaluable.hxx>
23 #include <Expr_NumericValue.hxx>
24 #include <Expr_Operators.hxx>
25 #include <Expr_Product.hxx>
26 #include <Expr_Sign.hxx>
27 #include <Expr_UnaryMinus.hxx>
28 #include <Standard_NumericError.hxx>
29 #include <Standard_Type.hxx>
30 #include <TCollection_AsciiString.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(Expr_Absolute,Expr_UnaryExpression)
33
34 Expr_Absolute::Expr_Absolute (const Handle(Expr_GeneralExpression)& exp)
35 {
36   CreateOperand(exp);
37 }
38
39 Handle(Expr_GeneralExpression) Expr_Absolute::ShallowSimplified () const
40 {
41   Handle(Expr_GeneralExpression) op = Operand();
42   if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
43     Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
44     return new Expr_NumericValue(Abs(valop->GetValue()));
45   }
46   if (op->IsKind(STANDARD_TYPE(Expr_UnaryMinus))) {
47     return new Expr_Absolute(op->SubExpression(1));
48   }
49   Handle(Expr_Absolute) me = this;
50   return me;
51 }
52
53 Handle(Expr_GeneralExpression) Expr_Absolute::Copy () const 
54 {
55   return  new Expr_Absolute(Expr::CopyShare(Operand()));
56 }
57
58 Standard_Boolean Expr_Absolute::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
59 {
60   if (!Other->IsKind(STANDARD_TYPE(Expr_Absolute))) {
61     return Standard_False;
62   }
63   Handle(Expr_GeneralExpression) op = Operand();
64   return op->IsIdentical(Other->SubExpression(1));
65 }
66
67 Standard_Boolean Expr_Absolute::IsLinear () const
68 {
69   return !ContainsUnknowns();
70 }
71
72 Handle(Expr_GeneralExpression) Expr_Absolute::Derivative (const Handle(Expr_NamedUnknown)& X) const
73 {
74   Handle(Expr_GeneralExpression) op = Operand();
75   Handle(Expr_GeneralExpression) derop = op->Derivative(X);
76   Handle(Expr_Sign) myder = new Expr_Sign(Expr::CopyShare(op));
77   Handle(Expr_Product) resul = myder->ShallowSimplified() * derop;
78   return resul->ShallowSimplified();
79 }
80
81
82 Standard_Real Expr_Absolute::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
83 {
84   return ::Abs(Operand()->Evaluate(vars,vals));
85 }
86
87 TCollection_AsciiString Expr_Absolute::String() const
88 {
89   TCollection_AsciiString str("Abs(");
90   str += Operand()->String();
91   str += ")";
92   return str;
93 }