CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
npstat::Interval< Numeric > Class Template Reference

#include <Interval.h>

Public Member Functions

void getBounds (Numeric *pmin, Numeric *pmax) const
 
 Interval ()
 
 Interval (const Numeric max)
 
 Interval (const Numeric min, const Numeric max, const bool swapIfOutOfOrder=false)
 
bool isInside (const Numeric value) const
 
bool isInsideLower (const Numeric value) const
 
bool isInsideUpper (const Numeric value) const
 
bool isInsideWithBounds (const Numeric value) const
 
Numeric length () const
 
template<typename Num2 >
void linearMap (const Interval< Num2 > &r, double *a, double *b) const
 
const Numeric max () const
 
Numeric midpoint () const
 
const Numeric min () const
 
IntervalmoveMidpointTo0 ()
 
Interval overlap (const Interval &r) const
 
double overlapFraction (const Interval &r) const
 
Numeric overlapLength (const Interval &r) const
 
void setBounds (const Numeric minval, const Numeric maxval, const bool swapIfOutOfOrder=false)
 
void setMax (const Numeric value)
 
void setMin (const Numeric value)
 
Intervaloperator*= (double r)
 
Intervaloperator/= (double r)
 
Intervaloperator+= (const Numeric value)
 
Intervaloperator-= (const Numeric value)
 
Intervalexpand (double r)
 

Private Attributes

Numeric max_
 
Numeric min_
 

Detailed Description

template<typename Numeric>
class npstat::Interval< Numeric >

Representation of 1-d intervals. The following invariant is maintained: min() will not exceed max().

See BoxND class for rectangles, boxes, and hyperboxes.

Definition at line 25 of file Interval.h.

Constructor & Destructor Documentation

template<typename Numeric>
npstat::Interval< Numeric >::Interval ( )
inline

Both lower and upper interval bounds are set to Numeric()

Definition at line 28 of file Interval.h.

28 : min_(Numeric()), max_(Numeric()) {}
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
npstat::Interval< Numeric >::Interval ( const Numeric  max)
inlineexplicit

Minimum is set to Numeric(), maximum to the given argument. An exception is thrown if the argument is smaller than Numeric().

Definition at line 34 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

34  : min_(Numeric()), max_(max) {
35  if (min_ > max_)
36  throw npstat::NpstatInvalidArgument("In npstat::Interval constructor: invalid limits");
37  }
Numeric min_
Definition: Interval.h:160
const Numeric max() const
Definition: Interval.h:81
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
npstat::Interval< Numeric >::Interval ( const Numeric  min,
const Numeric  max,
const bool  swapIfOutOfOrder = false 
)
inline

Constructor from both bounds. Set "swapIfOutOfOrder" argument to "true" if the minimum can be larger than the maximum (in this case the bounds will be swapped internally).

Definition at line 44 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and std::swap().

44  : min_(min), max_(max) {
45  if (min_ > max_) {
46  if (swapIfOutOfOrder)
48  else
49  throw npstat::NpstatInvalidArgument("In npstat::Interval constructor: invalid limits");
50  }
51  }
Numeric min_
Definition: Interval.h:160
const Numeric max() const
Definition: Interval.h:81
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:161
const Numeric min() const
Definition: Interval.h:78

Member Function Documentation

template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::expand ( double  r)
inline

Scaling the bounds by a constant in such a way that the midpoint remains unchanged

Definition at line 230 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and alignCSCRings::r.

Referenced by npstat::Interval< Numeric >::isInside().

230  {
231  const double r = fabs(ir);
232  if (r != 1.0) {
233  const Numeric center(static_cast<Numeric>((max_ + min_) * 0.5));
234  min_ = center + (min_ - center) * r;
235  max_ = center + (max_ - center) * r;
236  }
237  return *this;
238  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
void npstat::Interval< Numeric >::getBounds ( Numeric *  pmin,
Numeric *  pmax 
) const
inline

Return both bounds

Definition at line 84 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

84  {
85  *pmin = min_;
86  *pmax = max_;
87  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
bool npstat::Interval< Numeric >::isInside ( const Numeric  value) const
inline
template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideLower ( const Numeric  value) const
inline

Is the point inside the interval or on the lower boundary?

Definition at line 96 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

96 { return value >= min_ && value < max_; }
Numeric min_
Definition: Interval.h:160
Definition: value.py:1
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideUpper ( const Numeric  value) const
inline

Is the point inside the interval or on the upper boundary?

Definition at line 99 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

99 { return value > min_ && value <= max_; }
Numeric min_
Definition: Interval.h:160
Definition: value.py:1
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
bool npstat::Interval< Numeric >::isInsideWithBounds ( const Numeric  value) const
inline

Is the point inside the interval or on one of the boundaries?

Definition at line 102 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

102 { return value >= min_ && value <= max_; }
Numeric min_
Definition: Interval.h:160
Definition: value.py:1
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
Numeric npstat::Interval< Numeric >::length ( ) const
inline

Interval length

Definition at line 90 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

90 { return max_ - min_; }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
template<typename Num2 >
void npstat::Interval< Numeric >::linearMap ( const Interval< Num2 > &  r,
double *  a,
double *  b 
) const

Derive the coefficients a and b such that the linear mapping y = a*x + b maps the lower limit of this interval into the lower limit of the argument interval and the upper limit of this interval into the upper limit of the argument interval

Definition at line 267 of file Interval.h.

References npstat::Interval< Numeric >::max(), npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min(), and npstat::Interval< Numeric >::min_.

Referenced by npstat::Interval< Numeric >::isInside().

267  {
268  if (max_ == min_)
269  throw npstat::NpstatDomainError("In npstat::Interval::linearMap: zero length interval");
270  assert(a);
271  assert(b);
272  const Num2 rmax(r.max());
273  const Num2 rmin(r.min());
274  *a = static_cast<double>((rmax - rmin) * 1.0 / (max_ - min_));
275  *b = static_cast<double>((rmax + rmin) - *a * (max_ + min_)) / 2.0;
276  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
template<typename Numeric>
const Numeric npstat::Interval< Numeric >::max ( ) const
inline
template<typename Numeric>
Numeric npstat::Interval< Numeric >::midpoint ( ) const
inline

The middle point of the interval

Definition at line 93 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

93 { return static_cast<Numeric>((max_ + min_) * 0.5); }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
const Numeric npstat::Interval< Numeric >::min ( ) const
inline
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::moveMidpointTo0 ( )
inline

Move the interval so that the midpoint ends up at 0

Definition at line 222 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

Referenced by npstat::Interval< Numeric >::isInside().

222  {
223  const Numeric len = max_ - min_;
224  max_ = len / static_cast<Numeric>(2);
225  min_ = -max_;
226  return *this;
227  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator*= ( double  r)
inline

Scaling of both the minimum and the maximum by a constant. Minimum and maximum will be swapped internally in case the constant is negative.

Definition at line 213 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, alignCSCRings::r, and std::swap().

Referenced by npstat::Interval< Numeric >::isInside().

213  {
214  min_ *= r;
215  max_ *= r;
216  if (max_ < min_)
217  std::swap(min_, max_);
218  return *this;
219  }
Numeric min_
Definition: Interval.h:160
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator+= ( const Numeric  value)
inline

Shift both interval bounds by a constant

Definition at line 252 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and alignCSCRings::r.

Referenced by npstat::Interval< Numeric >::isInside().

252  {
253  min_ += r;
254  max_ += r;
255  return *this;
256  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator-= ( const Numeric  value)
inline

Definition at line 259 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and alignCSCRings::r.

Referenced by npstat::Interval< Numeric >::isInside().

259  {
260  min_ -= r;
261  max_ -= r;
262  return *this;
263  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Interval< Numeric > & npstat::Interval< Numeric >::operator/= ( double  r)
inline

Definition at line 241 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, alignCSCRings::r, and std::swap().

Referenced by npstat::Interval< Numeric >::isInside().

241  {
242  if (!r)
243  throw npstat::NpstatDomainError("In npstat::Interval::operator/=: division by zero");
244  min_ /= r;
245  max_ /= r;
246  if (max_ < min_)
247  std::swap(min_, max_);
248  return *this;
249  }
Numeric min_
Definition: Interval.h:160
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Interval< Numeric > npstat::Interval< Numeric >::overlap ( const Interval< Numeric > &  r) const
inline

The following function returns default-constructed empty interval in case this interval and the argument interval do not overlap

Definition at line 179 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and npstat::Interval< Numeric >::setBounds().

Referenced by npstat::Interval< Numeric >::isInside().

179  {
180  Interval<Numeric> over;
181  if (max_ == r.min_)
182  over.setBounds(max_, max_);
183  else if (r.max_ == min_)
184  over.setBounds(min_, min_);
185  else if (max_ > r.min_ && r.max_ > min_) {
186  over.min_ = min_ < r.min_ ? r.min_ : min_;
187  over.max_ = max_ < r.max_ ? max_ : r.max_;
188  }
189  return over;
190  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
double npstat::Interval< Numeric >::overlapFraction ( const Interval< Numeric > &  r) const
inline

Same as overlapLength(r)/length() but a tad faster

Definition at line 203 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

Referenced by npstat::Interval< Numeric >::isInside().

203  {
204  if (max_ > r.min_ && r.max_ > min_) {
205  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
206  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
207  return (mx - mn) * 1.0 / (max_ - min_);
208  } else
209  return 0.0;
210  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric >
Numeric npstat::Interval< Numeric >::overlapLength ( const Interval< Numeric > &  r) const
inline

Same as overlap.length() but a tad faster

Definition at line 193 of file Interval.h.

References npstat::Interval< Numeric >::max_, and npstat::Interval< Numeric >::min_.

Referenced by npstat::Interval< Numeric >::isInside().

193  {
194  if (max_ > r.min_ && r.max_ > min_) {
195  const Numeric mn = min_ < r.min_ ? r.min_ : min_;
196  const Numeric mx = max_ < r.max_ ? max_ : r.max_;
197  return mx - mn;
198  } else
199  return Numeric();
200  }
Numeric min_
Definition: Interval.h:160
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
void npstat::Interval< Numeric >::setBounds ( const Numeric  minval,
const Numeric  maxval,
const bool  swapIfOutOfOrder = false 
)
inline

Set both interval bounds

Definition at line 68 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and std::swap().

Referenced by npstat::Interval< Numeric >::overlap().

68  {
69  if (maxval < minval && !swapIfOutOfOrder)
70  throw npstat::NpstatInvalidArgument("In npstat::Interval::setBounds: invalid limits");
71  min_ = minval;
72  max_ = maxval;
73  if (swapIfOutOfOrder && min_ > max_)
75  }
Numeric min_
Definition: Interval.h:160
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
void npstat::Interval< Numeric >::setMax ( const Numeric  value)
inline

Set the upper interval bound

Definition at line 61 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and relativeConstraints::value.

61  {
62  if (value < min_)
63  throw npstat::NpstatInvalidArgument("In npstat::Interval::setMax: argument below min");
64  max_ = value;
65  }
Numeric min_
Definition: Interval.h:160
Definition: value.py:1
Numeric max_
Definition: Interval.h:161
template<typename Numeric>
void npstat::Interval< Numeric >::setMin ( const Numeric  value)
inline

Set the lower interval bound

Definition at line 54 of file Interval.h.

References npstat::Interval< Numeric >::max_, npstat::Interval< Numeric >::min_, and relativeConstraints::value.

Referenced by npstat::BoxND< Numeric >::allSpace().

54  {
55  if (value > max_)
56  throw npstat::NpstatInvalidArgument("In npstat::Interval::setMin: argument above max");
57  min_ = value;
58  }
Numeric min_
Definition: Interval.h:160
Definition: value.py:1
Numeric max_
Definition: Interval.h:161

Member Data Documentation

template<typename Numeric>
Numeric npstat::Interval< Numeric >::max_
private
template<typename Numeric>
Numeric npstat::Interval< Numeric >::min_
private