Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BinnerAxisLinear.cxx

Go to the documentation of this file.
00001 
00012 #ifdef HAVE_CONFIG_H
00013 #include "config.h"
00014 #endif
00015 
00016 #include "BinnerAxisLinear.h"
00017 
00018 #include <algorithm>
00019 
00020 #include <cmath> // for ciel()
00021 
00022 #include <cassert>
00023 
00024 
00025 BinnerAxisLinear::BinnerAxisLinear ()
00026   : BinnerAxis ( "BinnerLinear" )
00027 {
00028   m_width = m_range.length() / m_num_bins;
00029 }
00030 
00032 BinnerAxisLinear::BinnerAxisLinear ( const BinnerAxisLinear & binner )
00033   : BinnerAxis ( binner )
00034 {
00035 }
00036 
00037 BinnerAxisLinear::~BinnerAxisLinear()
00038 {
00039 }
00040 
00041 BinnerAxis *
00042 BinnerAxisLinear::clone()
00043 {
00044   return new BinnerAxisLinear( *this );
00045 }
00046 
00047 bool
00048 BinnerAxisLinear::hasEqualWidths () const
00049 {
00050   return true;
00051 }
00052 
00053 void
00054 BinnerAxisLinear::axisSetNumberOfBins ( int nb )
00055 {
00056   m_num_bins = nb;
00057   m_width = m_range.length() / m_num_bins;
00058 }
00059 
00064 int
00065 BinnerAxisLinear::axisBinNumber ( double x ) const
00066 {
00067   double lo = m_range.low ();
00068   double width = axisBinWidth ( 1 );
00069   double f = 1.0 + ( x - lo ) / width;
00070   int i = static_cast < int > ( f );
00071   i = std::max ( i, 0 );
00072   i = std::min ( i, m_num_bins + 1 );
00073 
00074   return i;
00075 }
00076 
00077 double
00078 BinnerAxisLinear::
00079 getCoordinate ( int i ) const
00080 {
00081   return m_range.low() + i * ( m_range.length () / m_num_bins );
00082 }
00083 
00084 double
00085 BinnerAxisLinear::axisBinWidth ( int ) const
00086 {
00087   double width = m_range.length() / m_num_bins;
00088 
00089   return width;
00090 }
00091 
00092 const Range &
00093 BinnerAxisLinear::setBinWidth ( double width )
00094 {
00095   assert ( width > 0.0 );
00096   
00097   m_width = width;
00098 
00099   m_num_bins = getNob ( width );
00100   m_range.setLength ( m_num_bins * width );
00101 
00102   return m_range;
00103 }
00104 
00105 /* virtual */
00106 double
00107 BinnerAxisLinear::calcBinWidth ( int parm, bool dragging ) const
00108 {
00109   setStartWidth ( dragging );
00110 
00111   double multiplier = ( parm - 50 ) / 50.0;
00112   double new_width 
00113     = m_width_start + s_bin_factor * multiplier * m_width_start;
00114 
00115   return new_width;
00116 }
00117 
00118 double
00119 BinnerAxisLinear::calcOffset ( int parm, bool dragging ) const
00120 {
00121   setStartRange ( dragging );
00122 
00123   return ( parm - 50 ) / 50.0;
00124 }
00125 
00126 double
00127 BinnerAxisLinear::getOffset () const
00128 {
00129   return m_offset;
00130 }
00131 
00132 const void
00133 BinnerAxisLinear::setOffset ( double offset )
00134 {
00135   double oldoff = m_offset;
00136   m_offset = offset;
00137   double change = offset - oldoff;
00138 
00139   if( offset == 0.0 ) return; // resetting...
00140   Range r( m_range.low() + change * m_width,
00141            m_range.high() + change * m_width );
00142 
00143   m_range = r;
00144 }
00145 
00148 const Range &
00149 BinnerAxisLinear::
00150 setRange ( const Range & range, bool hold_width )
00151 {
00152   m_range = range;
00153 
00154   if ( hold_width ) {
00155 #ifdef MATH_DEFECT
00156     double number = std::ceil ( m_range.length() / m_width );
00157 #else
00158     double number = ceil ( m_range.length() / m_width );
00159 #endif
00160     m_num_bins = static_cast< int > ( number  );
00161     m_range.setLength ( m_num_bins * m_width );
00162   }
00163   else { // calc new wieth.
00164     m_width = m_range.length() / m_num_bins;
00165   }
00166   return m_range;
00167 }
00168 
00169 /* virtual */
00170 double 
00171 BinnerAxisLinear::getConstWid ( ) const
00172 {
00173   return axisBinWidth( 1 );
00174   //This should really return the const width variable... but this
00175   //raises issues with when the variable needs to be recalculated.
00176   //return m_const_wid;
00177 }
00178 
00179 /* virtual */
00180 double 
00181 BinnerAxisLinear::
00182 getBinWidth ( ) const
00183 {
00184   return getConstWid ();
00185 }
00186 
00187 void
00188 BinnerAxisLinear::setConstWid ( )
00189 {
00190   m_width = axisBinWidth( 1 );
00191 }
00192 
00193 double
00194 BinnerAxisLinear::scaleFactorWid ( )
00195 {
00196   return getConstWid();
00197 }
00198 
00199 int BinnerAxisLinear::getNob ( const Range & range ) const 
00200 {
00201   double width = getConstWid ();
00202 #ifdef MATH_DEFECT
00203   int tmp 
00204     = static_cast < int > ( std::floor ( range.length () / width + 0.5 ) );
00205 #else
00206   int tmp 
00207     = static_cast < int > ( floor ( range.length() / width + 0.5 ) );
00208 #endif
00209 
00210   return tmp ? tmp : 1;
00211 }
00212 
00213 int BinnerAxisLinear::getNob ( double wid ) const
00214 {
00215   int tmp = m_range.numberOfBins( wid );
00216 
00217   return tmp ? tmp : 1;
00218 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3