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  

minimumfunction.cpp

00001 /***************************************************************************
00002                           minimumfunction.cpp  -  description
00003                              -------------------
00004     begin                : Tue Nov 12 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 "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() ) //bounds check
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 }