BinnerAxisLinear.cxx
Go to the documentation of this file.
1 
11 // for math defect
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15 
16 #include "BinnerAxisLinear.h"
17 
18 #include <algorithm>
19 
20 #include <cmath> // for ciel()
21 
22 #include <cassert>
23 
24 
25 using namespace hippodraw;
26 
28  : BinnerAxis ( "BinnerLinear" )
29 {
31 }
32 
35  : BinnerAxis ( binner )
36 {
37 }
38 
40 {
41 }
42 
43 BinnerAxis *
45 {
46  return new BinnerAxisLinear( *this );
47 }
48 
49 bool
51 {
52  return true;
53 }
54 
55 void
57 {
58  m_num_bins = nb;
60 }
61 
66 int
68 {
69  double lo = m_range.low ();
70  double width = axisBinWidth ( 1 );
71  double f = 1.0 + ( x - lo ) / width;
72  int i = static_cast < int > ( f );
73  i = std::max ( i, 0 );
74  i = std::min ( i, m_num_bins + 1 );
75 
76  return i;
77 }
78 
79 double
81 getCoordinate ( int i ) const
82 {
83  return m_range.low() + i * ( m_range.length () / m_num_bins );
84 }
85 
86 double
88 {
89  double width = m_range.length() / m_num_bins;
90 
91  return width;
92 }
93 
94 const Range &
96 setBinWidth ( double width )
97 {
98  assert ( width > 0.0 );
99 
100  m_width = width;
101 
102  m_num_bins = getNob ( width );
103  m_range.setLength ( m_num_bins * width );
104  return m_range;
105 }
106 
107 double
109 calcWidthParm ( int number ) const
110 {
111  double new_width = ( m_range.high() - m_range.low () ) /
112  ( static_cast < double > ( number ) );
113 
114  return new_width;
115 }
116 
117 double
118 BinnerAxisLinear::calcOffset ( int parm, bool dragging ) const
119 {
120  setStartRange ( dragging );
121 
122  return ( parm - 50 ) / 50.0;
123 }
124 
125 double
127 {
128  return m_offset;
129 }
130 
131 const void
133 {
134  double oldoff = m_offset;
135  m_offset = offset;
136  double change = offset - oldoff;
137 
138  if( offset == 0.0 ) return; // resetting...
139  Range r( m_range.low() + change * m_width,
140  m_range.high() + change * m_width );
141 
142  m_range = r;
143 }
144 
151 const Range &
153 setRange ( const Range & range, bool hold_width )
154 {
155  m_range = range;
156 
157  if ( hold_width && m_width < m_range.length() ) {
158 #ifdef MATH_DEFECT
159  double number = std::ceil ( m_range.length() / m_width );
160 #else
161  double number = ceil ( m_range.length() / m_width );
162 #endif
163  m_num_bins = static_cast< int > ( number );
164  m_range.setLength ( m_num_bins * m_width );
165  }
166  else { // calc new width.
168  }
169  return m_range;
170 }
171 
172 double
174 {
175  return axisBinWidth( 1 );
176  //This should really return the const width variable... but this
177  //raises issues with when the variable needs to be recalculated.
178  //return m_const_wid;
179 }
180 
181 double
183 getBinWidth ( ) const
184 {
185  return getConstWid ();
186 }
187 
188 void
190 {
191  m_width = axisBinWidth( 1 );
192 }
193 
194 double
196 {
197  return getConstWid();
198 }
199 
200 int BinnerAxisLinear::getNob ( const Range & range ) const
201 {
202  double width = getConstWid ();
203 #ifdef MATH_DEFECT
204  int tmp
205  = static_cast < int > ( std::floor ( range.length () / width + 0.5 ) );
206 #else
207  int tmp
208  = static_cast < int > ( floor ( range.length() / width + 0.5 ) );
209 #endif
210 
211  return tmp ? tmp : 1;
212 }
213 
214 int BinnerAxisLinear::getNob ( double wid ) const
215 {
216  int tmp = m_range.numberOfBins( wid );
217 
218  return tmp ? tmp : 1;
219 }

Generated for HippoDraw Class Library by doxygen