1 #ifndef NPSTAT_INTERVAL_HH_ 2 #define NPSTAT_INTERVAL_HH_ 24 template <
typename Numeric>
68 inline void setBounds(
const Numeric minval,
const Numeric maxval,
const bool swapIfOutOfOrder =
false) {
69 if (maxval < minval && !swapIfOutOfOrder)
78 inline const Numeric
min()
const {
return min_; }
81 inline const Numeric
max()
const {
return max_; }
156 template <
typename Num2>
167 template <
typename Numeric>
170 template <
typename Numeric>
178 template <
typename Numeric>
183 else if (r.max_ == 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_;
192 template <
typename Numeric>
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_;
202 template <
typename Numeric>
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_);
212 template <
typename Numeric>
221 template <
typename Numeric>
223 const Numeric len = max_ - min_;
224 max_ = len /
static_cast<Numeric
>(2);
229 template <
typename Numeric>
231 const double r = fabs(ir);
233 const Numeric center(static_cast<Numeric>((max_ + min_) * 0.5));
234 min_ = center + (min_ - center) * r;
235 max_ = center + (max_ - center) * r;
240 template <
typename Numeric>
251 template <
typename Numeric>
258 template <
typename Numeric>
265 template <
typename Numeric>
266 template <
typename Num2>
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;
279 template <
typename Numeric>
281 return r.min() ==
l.min() &&
r.max() ==
l.max();
284 template <
typename Numeric>
289 #endif // NPSTAT_INTERVAL_HH_
Interval(const Numeric min, const Numeric max, const bool swapIfOutOfOrder=false)
Interval & moveMidpointTo0()
Interval & operator+=(const Numeric value)
Interval & operator-=(const Numeric value)
Numeric overlapLength(const Interval &r) const
bool isInside(const Numeric value) const
const Numeric max() const
void setBounds(const Numeric minval, const Numeric maxval, const bool swapIfOutOfOrder=false)
double overlapFraction(const Interval &r) const
void setMax(const Numeric value)
void swap(Association< C > &lhs, Association< C > &rhs)
Exceptions for the npstat namespace.
bool operator!=(const npstat::Interval< Numeric > &l, const npstat::Interval< Numeric > &r)
void getBounds(Numeric *pmin, Numeric *pmax) const
void setMin(const Numeric value)
Interval & expand(double r)
const Numeric min() const
Interval & operator*=(double r)
Interval(const Numeric max)
bool isInsideLower(const Numeric value) const
bool operator==(const npstat::Interval< Numeric > &l, const npstat::Interval< Numeric > &r)
void linearMap(const Interval< Num2 > &r, double *a, double *b) const
Interval & operator/=(double r)
bool isInsideUpper(const Numeric value) const
Interval overlap(const Interval &r) const
bool isInsideWithBounds(const Numeric value) const