CLAM-Development  1.4.0
RangeView.hxx
Go to the documentation of this file.
1 #ifndef RangeView_hxx
2 #define RangeView_hxx
3 
4 #include <cmath>
5 #include <algorithm>
6 #include "Assert.hxx"
7 namespace CLAM
8 {
9 
10 /*
11  Implements the logic to navigate along a Range.
12  @todo out of place centering
13 */
14 class RangeView
15 {
16  public:
17  static double zoomExcentricity(double low, double high, double stiked)
18  {
19  if (stiked<low) return 0.;
20  if (stiked>high) return 1.;
21  return (stiked-low)/(high-low);
22  }
23  static void zoom(double &low, double &high, double factor, double centering)
24  {
25  CLAM_ASSERT(centering>=0. && centering<=1.,
26  "RangeView: zooming using a centering factor not in the [0,1] interval.");
27  double span = high-low;
28  double midPoint = low + (high-low)*centering;
29  low = midPoint - span*factor*centering;
30  high = midPoint + span*factor*(1-centering);
31  }
32  static void keepWithinInterval(double & low, double & high, double lowest, double highest)
33  {
34  double span = high-low;
35  if (high>highest)
36  {
37  high=highest;
38  low=high-span;
39  }
40  if (low<lowest)
41  {
42  low=lowest;
43  high=std::min(highest,low+span);
44  }
45  }
46 };
47 
48 } // namespace CLAM
49 
50 #endif//RangeView_hxx
51