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