0022904: Clean up sccsid variables
[occt.git] / src / Expr / Expr_FunctionDerivative.cxx
CommitLineData
7fd59977 1// Copyright: Matra-Datavision 1991
2// File: Expr_FunctionDerivative.cxx
3// Created: Thu Jun 27 09:40:36 1991
4// Author: Arnaud BOUZY
5// <adn>
6
7#include <Expr_FunctionDerivative.ixx>
8#include <Expr_NumericValue.hxx>
9#include <Expr_NamedFunction.hxx>
10#include <Standard_OutOfRange.hxx>
11#include <Standard_NotImplemented.hxx>
12
13Expr_FunctionDerivative::Expr_FunctionDerivative (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_NamedUnknown)& withX, const Standard_Integer deg)
14{
15 myFunction = func;
16 myDerivate = withX;
17 if (deg <= 0) {
18 Standard_OutOfRange::Raise();
19 }
20 myDegree = deg;
21 UpdateExpression();
22}
23
24Standard_Integer Expr_FunctionDerivative::NbOfVariables () const
25{
26 return myFunction->NbOfVariables();
27}
28
29Handle(Expr_NamedUnknown) Expr_FunctionDerivative::Variable (const Standard_Integer index) const
30{
31 return myFunction->Variable(index);
32}
33
34Standard_Real Expr_FunctionDerivative::Evaluate (const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& values) const
35{
36 if (vars.Length() != values.Length()) {
37 Standard_OutOfRange::Raise();
38 }
39 return myExp->Evaluate(vars,values);
40}
41
42Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Copy () const
43{
44 return new Expr_FunctionDerivative(myFunction->Copy(),myDerivate,myDegree);
45}
46
47Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Derivative(const Handle(Expr_NamedUnknown)& var) const
48{
49 return Derivative(var,1);
50}
51
52Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Derivative(const Handle(Expr_NamedUnknown)& var, const Standard_Integer deg) const
53{
54 if (var == myDerivate) {
55 return new Expr_FunctionDerivative(myFunction,var,myDegree+deg);
56 }
57 Handle(Expr_FunctionDerivative) me = this;
58 return new Expr_FunctionDerivative(me,var,deg);
59}
60
61Standard_Boolean Expr_FunctionDerivative::IsIdentical (const Handle(Expr_GeneralFunction)& func) const
62{
63 if (!func->IsKind(STANDARD_TYPE(Expr_FunctionDerivative))) {
64 return Standard_False;
65 }
66 Handle(Expr_FunctionDerivative) dfunc = Handle(Expr_FunctionDerivative)::DownCast(func);
67 if (myDegree != dfunc->Degree()) {
68 return Standard_False;
69 }
70 if (!myDerivate->IsIdentical(dfunc->DerivVariable())) {
71 return Standard_False;
72 }
73 if (!myFunction->IsIdentical(dfunc->Function())) {
74 return Standard_False;
75 }
76 return Standard_True;
77}
78
79Standard_Boolean Expr_FunctionDerivative::IsLinearOnVariable(const Standard_Integer) const
80{
81 // should be improved
82 return myExp->IsLinear();
83}
84
85Handle(Expr_GeneralFunction) Expr_FunctionDerivative::Function () const
86{
87 return myFunction;
88}
89
90Standard_Integer Expr_FunctionDerivative::Degree () const
91{
92 return myDegree;
93}
94
95Handle(Expr_NamedUnknown) Expr_FunctionDerivative::DerivVariable () const
96{
97 return myDerivate;
98}
99
100
101TCollection_AsciiString Expr_FunctionDerivative::GetStringName() const
102{
103 TCollection_AsciiString res;
104 if (NbOfVariables() ==1) {
105 res = myFunction->GetStringName();
106 char c = 39;
107 TCollection_AsciiString diff(myDegree,c);
108 res += diff;
109 return res;
110 }
111 TCollection_AsciiString diff("@");
112 if (myDegree > 1) {
113 TCollection_AsciiString deg(myDegree);
114 diff += deg;
115 }
116 res = diff;
117 res += myFunction->GetStringName();
118 res += "/";
119 Standard_Integer index=0;
120 for (Standard_Integer i=1; (i<= NbOfVariables()) && (index ==0) ; i++) {
121 if (Variable(i) == myDerivate) {
122 index =i;
123 }
124 }
125 res += diff;
126 res += "X";
127 TCollection_AsciiString rank(index);
128 res += rank;
129 return res;
130}
131
132
133Handle(Expr_GeneralExpression) Expr_FunctionDerivative::Expression() const
134{
135 return myExp;
136}
137
138void Expr_FunctionDerivative::UpdateExpression()
139{
140 if (myFunction->IsKind(STANDARD_TYPE(Expr_FunctionDerivative))) {
141 Handle(Expr_FunctionDerivative) defunc = Handle(Expr_FunctionDerivative)::DownCast(myFunction);
142 defunc->UpdateExpression();
143 myExp = defunc->Expression()->NDerivative(myDerivate,myDegree);
144 }
145 else {
146 Handle(Expr_NamedFunction) nafunc = Handle(Expr_NamedFunction)::DownCast(myFunction);
147 myExp = nafunc->Expression()->NDerivative(myDerivate,myDegree);
148 }
149}