RangeView.hxx

Go to the documentation of this file.
00001 #ifndef RangeView_hxx
00002 #define RangeView_hxx
00003 
00004 #include <cmath>
00005 #include <algorithm>
00006 #include "Assert.hxx"
00007 namespace CLAM
00008 {
00009 
00010 /*
00011         Implements the logic to navigate along a Range.
00012         @todo out of place centering
00013 */
00014 class RangeView
00015 {
00016         public:
00017                 static double zoomExcentricity(double low, double high, double stiked)
00018                 {
00019                         if (stiked<low) return 0.;
00020                         if (stiked>high) return 1.;
00021                         return (stiked-low)/(high-low);
00022                 }
00023                 static void zoom(double &low, double &high, double factor, double centering)
00024                 {
00025                         CLAM_ASSERT(centering>=0. && centering<=1.,
00026                                 "RangeView: zooming using a centering factor not in the [0,1] interval.");
00027                         double span = high-low;
00028                         double midPoint = low + (high-low)*centering;
00029                         low = midPoint - span*factor*centering;
00030                         high = midPoint + span*factor*(1-centering);
00031                 }
00032                 static void keepWithinInterval(double & low, double & high, double lowest, double highest)
00033                 {
00034                         double span = high-low;
00035                         if (high>highest)
00036                         {
00037                                 high=highest;
00038                                 low=high-span;
00039                         }
00040                         if (low<lowest)
00041                         {
00042                                 low=lowest;
00043                                 high=std::min(highest,low+span);
00044                         }
00045                 }
00046 };
00047 
00048 } // namespace CLAM
00049 
00050 #endif//RangeView_hxx
00051 
Generated by  doxygen 1.6.3