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

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 <iosfwd>
00020 #include <vector>
00021 
00022 #include <cfloat> // for DBL_MAX
00023 
00032 class MDL_HIPPOPLOT_API Range {
00033 
00034 private:
00035 
00038   double m_min;
00039 
00042   double m_max;
00043 
00046   double m_pos;
00047 
00051   bool m_empty;
00052   
00053  public:
00054 
00058   Range ( );
00059 
00063   Range ( double x,
00064           double y,
00065           double p = DBL_MAX );
00066 
00070   Range ( const std::vector < double > & array );
00071 
00074   double low() const;
00075 
00078   void setLow(double x);
00079 
00082   double high() const;
00083 
00086   void setHigh(double x);
00087 
00090   double pos() const;
00091 
00094   void setPos(double x);
00095 
00098   void setRange ( double low, double high, double pos );
00099 
00102   template < class Iterator >
00103   void setRange ( Iterator first, Iterator end );
00104 
00107   inline double length() const;
00108 
00112   void setLength ( double val, bool high_hold = false );
00113   
00118   bool includes ( double value ) const;
00119 
00124   bool excludes ( double value ) const;
00125 
00128   double fraction ( double value ) const;
00129 
00132   void setIntersect ( const Range & range );
00133 
00139   void setUnion ( const Range & range );
00140 
00143   void setEmpty ( bool yes = true );
00144 
00148   int numberOfBins ( double width ) const;
00149 
00152   friend std::ostream & operator << ( std::ostream &, const Range & );
00153 
00154 };
00155 
00156 inline
00157 double
00158 Range::
00159 length () const
00160 {
00161   return (m_max - m_min);
00162 }
00163 
00164 
00165 template < class Iterator >
00166 void
00167 Range::
00168 setRange ( Iterator first, Iterator end )
00169 {
00170   m_min = DBL_MAX;
00171   m_max = -DBL_MAX;
00172   m_pos = DBL_MAX;
00173 
00174   while ( first != end ) {
00175     double test = *first; // input might be pointer to float.
00176     m_min = std::min ( m_min, test );
00177     m_max = std::max ( m_max, test );
00178     if ( test > 0.0 ) m_pos = std::min ( m_pos, test );
00179     ++first;
00180   }
00181 }
00182 
00183 #endif // _RANGE_H_

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3