Range.h

Go to the documentation of this file.
00001 /* -*- mode: c++ -*- */
00002 
00014 #ifndef _RANGE_H_
00015 #define _RANGE_H_
00016 
00017 #include "pattern/libhippo.h"
00018 
00019 #include <vector>
00020 
00021 #include <cfloat> // for DBL_MAX
00022 
00023 namespace hippodraw {
00024 
00033 class MDL_HIPPOPLOT_API Range {
00034 
00035 private:
00036 
00039   double m_min;
00040 
00043   double m_max;
00044 
00047   double m_pos;
00048 
00052   bool m_empty;
00053   
00054  public:
00055 
00059   Range ( );
00060 
00064   Range ( double x,
00065           double y,
00066           double p = DBL_MAX );
00067 
00071   Range ( const std::vector < double > & array );
00072 
00075   double low() const;
00076 
00079   void setLow(double x);
00080 
00083   double high() const;
00084 
00087   void setHigh(double x);
00088 
00091   double pos() const;
00092 
00095   void setPos(double x);
00096 
00099   void setRange ( double low, double high, double pos );
00100 
00103   template < class Iterator >
00104   void setRange ( Iterator first, Iterator end );
00105 
00108   inline double length() const;
00109 
00113   void setLength ( double val, bool high_hold = false );
00114   
00119   bool includes ( double value ) const;
00120 
00125   bool excludes ( double value ) const;
00126 
00129   double fraction ( double value ) const;
00130 
00133   void setIntersect ( const Range & range );
00134 
00140   void setUnion ( const Range & range );
00141 
00144   void setEmpty ( bool yes = true );
00145 
00149   int numberOfBins ( double width ) const;
00150 
00151 };
00152 
00153 inline
00154 double
00155 Range::
00156 length () const
00157 {
00158   return (m_max - m_min);
00159 }
00160 
00161 template < class Iterator >
00162 void
00163 Range::
00164 setRange ( Iterator first, Iterator end )
00165 {
00166   m_min = DBL_MAX;
00167   m_max = -DBL_MAX;
00168   m_pos = DBL_MAX;
00169 
00170   while ( first != end ) {
00171     double test = *first; // input might be pointer to float.
00172     m_min = std::min ( m_min, test );
00173     m_max = std::max ( m_max, test );
00174     if ( test > 0.0 ) m_pos = std::min ( m_pos, test );
00175     ++first;
00176   }
00177 }
00178 
00179 } // namespace hippodraw
00180 
00181 #endif // _RANGE_H_

Generated for HippoDraw Class Library by doxygen