0022904: Clean up sccsid variables
[occt.git] / src / Expr / Expr_BinaryFunction.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1991
2// File: Expr_BinaryFunction.cxx
3// Created: Thu May 30 09:15:26 1991
4// Author: Arnaud BOUZY
5// <adn>
6
7#ifndef DEB
8#define No_Standard_RangeError
9#define No_Standard_OutOfRange
10#endif
11
12#include <Expr_BinaryFunction.ixx>
13#include <Expr_InvalidFunction.hxx>
14#include <Expr_Array1OfNamedUnknown.hxx>
15#include <Expr_Array1OfGeneralExpression.hxx>
16#include <Expr_FunctionDerivative.hxx>
17#include <Expr_Product.hxx>
18#include <Expr_Sum.hxx>
19#include <Expr_Operators.hxx>
20#include <Expr.hxx>
21
22Expr_BinaryFunction::Expr_BinaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp1, const Handle(Expr_GeneralExpression)& exp2)
23{
24 if (func->NbOfVariables() != 2) {
25 Expr_InvalidFunction::Raise();
26 }
27 myFunction = func;
28 CreateFirstOperand(exp1);
29 CreateSecondOperand(exp2);
30}
31
32Handle(Expr_GeneralExpression) Expr_BinaryFunction::ShallowSimplified () const
33{
34 if (FirstOperand()->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
35 if (SecondOperand()->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
36 TColStd_Array1OfReal tabval(1,2);
37 tabval(1) = Handle(Expr_NumericValue)::DownCast(FirstOperand())->GetValue();
38 tabval(2) = Handle(Expr_NumericValue)::DownCast(SecondOperand())->GetValue();
39 Expr_Array1OfNamedUnknown vars(1,2);
40 vars(1) = myFunction->Variable(1);
41 vars(2) = myFunction->Variable(2);
42 Standard_Real res = myFunction->Evaluate(vars,tabval);
43 return new Expr_NumericValue(res);
44 }
45 }
46 Handle(Expr_BinaryFunction) me = this;
47 return me;
48}
49
50Handle(Expr_GeneralExpression) Expr_BinaryFunction::Copy () const
51{
52 return new Expr_BinaryFunction(myFunction,
53 Expr::CopyShare(FirstOperand()),
54 Expr::CopyShare(SecondOperand()));
55}
56
57Standard_Boolean Expr_BinaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
58{
59 if (!Other->IsKind(STANDARD_TYPE(Expr_BinaryFunction))) {
60 return Standard_False;
61 }
62 Handle(Expr_BinaryFunction) fother = Handle(Expr_BinaryFunction)::DownCast(Other);
63 Handle(Expr_GeneralExpression) otherexp = fother->FirstOperand();
64 if (otherexp->IsIdentical(FirstOperand())) {
65 otherexp = fother->SecondOperand();
66 if (otherexp->IsIdentical(SecondOperand())) {
67 if (myFunction->IsIdentical(fother->Function())) {
68 return Standard_True;
69 }
70 }
71 }
72 return Standard_False;
73}
74
75Standard_Boolean Expr_BinaryFunction::IsLinear () const
76{
77 if (!ContainsUnknowns()) {
78 return Standard_True;
79 }
80 if (!FirstOperand()->IsLinear()) {
81 return Standard_False;
82 }
83 if (!SecondOperand()->IsLinear()) {
84 return Standard_False;
85 }
86 if (!myFunction->IsLinearOnVariable(1)) {
87 return Standard_False;
88 }
89 return myFunction->IsLinearOnVariable(2);
90}
91
92Handle(Expr_GeneralExpression) Expr_BinaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
93{
94 Handle(Expr_NamedUnknown) myvar1 = myFunction->Variable(1);
95 Handle(Expr_NamedUnknown) myvar2 = myFunction->Variable(2);
96 Handle(Expr_GeneralExpression) myfop = FirstOperand();
97 Handle(Expr_GeneralExpression) mysop = SecondOperand();
98 Handle(Expr_GeneralExpression) myexpder1 = myfop->Derivative(X);
99 Handle(Expr_GeneralExpression) myexpder2 = mysop->Derivative(X);
100
101 Handle(Expr_GeneralFunction) myfuncder1 = myFunction->Derivative(myvar1);
102 Handle(Expr_BinaryFunction) firstpart
103 = new Expr_BinaryFunction(myfuncder1,
104 Expr::CopyShare(myfop),
105 Expr::CopyShare(mysop));
106
107 Handle(Expr_GeneralExpression) fpart = firstpart->ShallowSimplified() * myexpder1;
108
109 Handle(Expr_GeneralFunction) myfuncder2 = myFunction->Derivative(myvar2);
110 Handle(Expr_BinaryFunction) secondpart
111 = new Expr_BinaryFunction(myfuncder2,
112 Expr::CopyShare(myfop),
113 Expr::CopyShare(mysop));
114
115 Handle(Expr_GeneralExpression) spart = secondpart->ShallowSimplified() * myexpder2;
116
117 fpart = fpart->ShallowSimplified();
118 spart = spart->ShallowSimplified();
119 return (fpart + spart)->ShallowSimplified();
120}
121
122Handle(Expr_GeneralFunction) Expr_BinaryFunction::Function () const
123{
124 return myFunction;
125}
126
127Standard_Real Expr_BinaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
128{
129 Expr_Array1OfNamedUnknown varsfunc(1,2);
130 varsfunc(1) = myFunction->Variable(1);
131 varsfunc(2) = myFunction->Variable(2);
132 TColStd_Array1OfReal valsfunc(1,2);
133 valsfunc(1) = FirstOperand()->Evaluate(vars,vals);
134 valsfunc(2) = SecondOperand()->Evaluate(vars,vals);
135 return myFunction->Evaluate(varsfunc,valsfunc);
136}
137
138TCollection_AsciiString Expr_BinaryFunction::String() const
139{
140 TCollection_AsciiString res = myFunction->GetStringName();
141 res += TCollection_AsciiString('(');
142 res += FirstOperand()->String();
143 res += ",";
144 res += SecondOperand()->String();
145 res += ")";
146 return res;
147}