Blame view

build4/epsilon-master/apps/graph/cartesian_function.cpp 2.89 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  #include "cartesian_function.h"
  #include "../shared/poincare_helpers.h"
  #include <float.h>
  #include <cmath>
  
  using namespace Poincare;
  using namespace Shared;
  
  namespace Graph {
  
  CartesianFunction::CartesianFunction(const char * text, KDColor color) :
    Shared::Function(text, color),
    m_displayDerivative(false)
  {
  }
  
  bool CartesianFunction::displayDerivative() {
    return m_displayDerivative;
  }
  
  void CartesianFunction::setDisplayDerivative(bool display) {
    m_displayDerivative = display;
  }
  
  double CartesianFunction::approximateDerivative(double x, Poincare::Context * context) const {
    Poincare::Expression * abscissa = new Poincare::Approximation<double>(x);
    Poincare::Expression * args[2] = {expression(context)->clone(), abscissa};
    Poincare::Derivative derivative(args, false); // derivative takes ownership of abscissa and the clone of expression
    /* TODO: when we will simplify derivative, we might want to simplify the
     * derivative here. However, we might want to do it once for all x (to avoid
     * lagging in the derivative table. */
    return PoincareHelpers::ApproximateToScalar<double>(&derivative, *context);
  }
  
  double CartesianFunction::sumBetweenBounds(double start, double end, Poincare::Context * context) const {
    Poincare::Expression * x = new Poincare::Approximation<double>(start);
    Poincare::Expression * y = new Poincare::Approximation<double>(end);
    Poincare::Expression * args[3] = {expression(context)->clone(), x, y};
    Poincare::Integral integral(args, false); // Integral takes ownership of args
    /* TODO: when we will simplify integral, we might want to simplify the
     * integral here. However, we might want to do it once for all x (to avoid
     * lagging in the derivative table. */
    return PoincareHelpers::ApproximateToScalar<double>(&integral, *context);
  }
  
  Expression::Coordinate2D CartesianFunction::nextMinimumFrom(double start, double step, double max, Context * context) const {
    return expression(context)->nextMinimum(symbol(), start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
  }
  
  Expression::Coordinate2D CartesianFunction::nextMaximumFrom(double start, double step, double max, Context * context) const {
    return expression(context)->nextMaximum(symbol(), start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
  }
  
  double CartesianFunction::nextRootFrom(double start, double step, double max, Context * context) const {
    return expression(context)->nextRoot(symbol(), start, step, max, *context, Preferences::sharedPreferences()->angleUnit());
  }
  
  Expression::Coordinate2D CartesianFunction::nextIntersectionFrom(double start, double step, double max, Poincare::Context * context, const Shared::Function * function) const {
    return expression(context)->nextIntersection(symbol(), start, step, max, *context, Preferences::sharedPreferences()->angleUnit(), function->expression(context));
  }
  
  char CartesianFunction::symbol() const {
    return 'x';
  }
  
  }