LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
NumericUtils.cxx
Go to the documentation of this file.
3 
4 #include <cmath>
5 
6 namespace lar::util {
7  bool ValueInRange(double value, double min, double max)
8  {
9  if (min > max) std::swap(min, max); //protect against funny business due to wire angles
10  if (std::abs(value - min) < 1e-6 || std::abs(value - max) < 1e-6) return true;
11  return (value >= min) && (value <= max);
12  }
13 
14  //--------------------------------------------------------------------
16  bool PointWithinSegments(double A_start_x,
17  double A_start_y,
18  double A_end_x,
19  double A_end_y,
20  double B_start_x,
21  double B_start_y,
22  double B_end_x,
23  double B_end_y,
24  double x,
25  double y)
26  {
27  constexpr RealComparisons<double> coordIs{1e-8};
28  return coordIs.withinSorted(x, A_start_x, A_end_x) &&
29  coordIs.withinSorted(y, A_start_y, A_end_y) &&
30  coordIs.withinSorted(x, B_start_x, B_end_x) &&
31  coordIs.withinSorted(y, B_start_y, B_end_y);
32  }
33 
34 }
Float_t x
Definition: compare.C:6
Functions to help with numbers.
Provides simple real number checks.
Float_t y
Definition: compare.C:6
constexpr auto abs(T v)
Returns the absolute value of the argument.
bool PointWithinSegments(double A_start_x, double A_start_y, double A_end_x, double A_end_y, double B_start_x, double B_start_y, double B_end_x, double B_end_y, double x, double y)
Returns whether x and y are within both specified ranges (A and B).
Class for approximate comparisons.
LArSoft utility namespace.
Definition: NumericUtils.cxx:6
double value
Definition: spectrum.C:18
bool ValueInRange(double value, double min, double max)
Returns whether a value is within the specified range.
Definition: NumericUtils.cxx:7
Float_t e
Definition: plot.C:35