0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / Expr / Expr_ArcCosine.cxx
CommitLineData
b311480e 1// Created on: 1991-05-27
2// Created by: Arnaud BOUZY
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Expr.hxx>
19#include <Expr_ArcCosine.hxx>
7fd59977 20#include <Expr_Cosine.hxx>
42cf5bc1 21#include <Expr_Difference.hxx>
7fd59977 22#include <Expr_Division.hxx>
42cf5bc1 23#include <Expr_GeneralExpression.hxx>
24#include <Expr_NamedUnknown.hxx>
25#include <Expr_NotEvaluable.hxx>
26#include <Expr_NumericValue.hxx>
27#include <Expr_Operators.hxx>
28#include <Expr_Product.hxx>
7fd59977 29#include <Expr_Square.hxx>
7fd59977 30#include <Expr_SquareRoot.hxx>
31#include <Expr_UnaryMinus.hxx>
42cf5bc1 32#include <Standard_NumericError.hxx>
33#include <Standard_Type.hxx>
34#include <TCollection_AsciiString.hxx>
7fd59977 35
92efcf78 36IMPLEMENT_STANDARD_RTTIEXT(Expr_ArcCosine,Expr_UnaryExpression)
37
7fd59977 38Expr_ArcCosine::Expr_ArcCosine (const Handle(Expr_GeneralExpression)& exp)
39{
40 CreateOperand(exp);
41}
42
43Handle(Expr_GeneralExpression) Expr_ArcCosine::ShallowSimplified () const
44{
45 Handle(Expr_GeneralExpression) op = Operand();
46 if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
47 Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op);
48 return new Expr_NumericValue(ACos(valop->GetValue()));
49 }
50 if (op->IsKind(STANDARD_TYPE(Expr_Cosine))) {
51 return op->SubExpression(1);
52 }
53 Handle(Expr_ArcCosine) me = this;
54 return me;
55}
56
57Handle(Expr_GeneralExpression) Expr_ArcCosine::Copy () const
58{
59 return new Expr_ArcCosine(Expr::CopyShare(Operand()));
60}
61
62Standard_Boolean Expr_ArcCosine::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
63{
64 if (!Other->IsKind(STANDARD_TYPE(Expr_ArcCosine))) {
65 return Standard_False;
66 }
67 Handle(Expr_GeneralExpression) op = Operand();
68 return op->IsIdentical(Other->SubExpression(1));
69}
70
71Standard_Boolean Expr_ArcCosine::IsLinear () const
72{
73 if (ContainsUnknowns()) {
74 return Standard_False;
75 }
76 return Standard_True;
77}
78
79Handle(Expr_GeneralExpression) Expr_ArcCosine::Derivative (const Handle(Expr_NamedUnknown)& X) const
80{
81 if (!Contains(X)) {
82 return new Expr_NumericValue(0.0);
83 }
84 Handle(Expr_GeneralExpression) op = Operand();
85 Handle(Expr_GeneralExpression) derop = op->Derivative(X);
86
87 Handle(Expr_Square) sq = new Expr_Square(Expr::CopyShare(op));
88 // 1 - X2
89 Handle(Expr_Difference) thedif = 1.0 - sq->ShallowSimplified();
90
91 Handle(Expr_SquareRoot) theroot = new Expr_SquareRoot(thedif->ShallowSimplified());
92 // 1/ sqrt(1-X2)
93 Handle(Expr_UnaryMinus) theder = - (1.0 / theroot->ShallowSimplified());
94
95 // ArcCosine'(F(X)) = -1/sqrt(1-F(X)2) * F'(X)
96
97 Handle(Expr_Product) result = theder->ShallowSimplified() * derop;
98
99 return result->ShallowSimplified();
100}
101
102Standard_Real Expr_ArcCosine::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
103{
104 return ::ACos(Operand()->Evaluate(vars,vals));
105}
106
107TCollection_AsciiString Expr_ArcCosine::String() const
108{
109 TCollection_AsciiString str("ACos(");
110 str += Operand()->String();
111 str += ")";
112 return str;
113}