Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
maximumfunction.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "maximumfunction.h"
00019
00020 #include <qobject.h>
00021 #include <qpoint.h>
00022
00023 #include "fungparser.h"
00024
00025 MaximumFunction::MaximumFunction(BasicGraph *graph, int expressions) : MathFunction(graph,expressions)
00026 {
00027 }
00028
00029 MaximumFunction::~MaximumFunction()
00030 {
00031 }
00032
00033 void MaximumFunction::calculate_and_draw(QPainter *painter)
00034 {
00035 if ( lowerBounds.x() > upperBounds.x() )
00036 {
00037 QString s( QObject::tr("Invalid bounds") );
00038 setResult( s );
00039 return;
00040 }
00041
00042 double x = toGraphXCoord(lowerBounds.x());
00043 double d[] = {x,animatorValue()};
00044 double y = expression->Eval(d);
00045
00046 max_x_point = x;
00047 max_y_point = y;
00048
00049 for (int i=lowerBounds.x()+1; i<=upperBounds.x(); i++)
00050 {
00051 x = toGraphXCoord(i);
00052 d[0]=x;
00053 y = expression->Eval(d);
00054 if (y > max_y_point)
00055 {
00056 max_y_point = y;
00057 max_x_point = x;
00058 }
00059 }
00060 QString s = QString(QObject::tr("Maximum = %1")).arg(max_y_point);
00061 setResult(s);
00062
00063 draw_stored(painter);
00064 }
00065
00066 void MaximumFunction::draw_stored(QPainter *painter)
00067 {
00068 drawSelectedPoint(max_x_point,max_y_point, painter);
00069 }
|