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