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  

maximumfunction.cpp

00001 /***************************************************************************
00002                           maximumfunction.cpp  -  description
00003                              -------------------
00004     begin                : Tue Nov 12 2002
00005     copyright            : (C) 2002 by Fungmeista
00006     email                : mizunoami44@users.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 "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() ) //bounds check
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 }