Home

Download

Features

Screenshots

Handbook

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

zerofunction.cpp

00001 /***************************************************************************
00002                           zerofunction.cpp  -  description
00003                              -------------------
00004     begin                : Tue Nov 19 2002
00005     copyright            : (C) 2002 by Fungmeista
00006     email                : mizunoami44@sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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 }