Linear.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "Linear.h"
00017 
00018 #include "FunctionHelper.h"
00019 
00020 #include <cassert>
00021 
00022 #ifdef ITERATOR_MEMBER_DEFECT
00023 using namespace std;
00024 #else
00025 using std::vector;
00026 #endif
00027 
00028 namespace hippodraw {
00029 
00030 Linear::Linear ( )
00031 {
00032   initialize ();
00033 }
00034 
00035 Linear::Linear ( double intercept, double slope )
00036 {
00037   initialize ();
00038 
00039   m_parms[0] = intercept;
00040   m_parms[1] = slope;
00041 }
00042 
00043 void Linear::initialize ()
00044 {
00045   m_name = "Linear";
00046   m_parm_names.push_back ( "Intercept" );
00047   m_parm_names.push_back ( "Slope" );
00048 
00049   resize ();
00050 }
00051 
00052 FunctionBase * Linear::clone () const
00053 {
00054   return new Linear ( *this );
00055 }
00056 
00057 double Linear::operator () ( double x ) const
00058 {
00059   return x * m_parms[1] + m_parms[0];
00060 }
00061 
00062 /* virtual */
00063 void 
00064 Linear::
00065 initialParameters ( const FunctionHelper * helper )
00066 {
00067   double min_x = helper->minCoord ();
00068   double max_x = helper->maxCoord ();
00069 
00070   double min_y = helper->minValue ();
00071   double max_y = helper->maxValue ();
00072 
00073   m_parms[1] = ( max_y - min_y ) / ( max_x - min_x );
00074   m_parms[0] = max_y - m_parms[1] * max_x;
00075 }
00076 
00077 double Linear::derivByParm ( int i, double x ) const
00078 {
00079   switch ( i ) {
00080   case 0 :
00081     return 1.0;
00082     break;
00083 
00084   case 1 :
00085     return x;
00086     break;
00087 
00088   default:
00089     assert ( false );
00090     break;
00091   }
00092   return 0.0;
00093 }
00094 
00095 } // namespace hippodraw
00096 

Generated for HippoDraw Class Library by doxygen