LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
NumericUtils.h
Go to the documentation of this file.
1 
7 #ifndef LARCOREALG_COREUTILS_NUMERICUTILS_H
8 #define LARCOREALG_COREUTILS_NUMERICUTILS_H
9 
10 // C/C++ standard libraries
11 #include <type_traits>
12 
13 namespace lar::util {
14 
15  // @{
29  bool ValueInRange(double value, double min, double max);
30  // @}
31 
32  //--------------------------------------------------------------------
34  bool PointWithinSegments(double A_start_x,
35  double A_start_y,
36  double A_end_x,
37  double A_end_y,
38  double B_start_x,
39  double B_start_y,
40  double B_end_x,
41  double B_end_y,
42  double x,
43  double y);
44  // @{
68  template <typename A, typename B>
69  constexpr auto absDiff(A const& a, B const& b)
70  {
71  static_assert(std::is_same<std::decay_t<A>, std::decay_t<B>>{},
72  "Arguments of util::absDiff() have to be of the same type.");
73  return (b > a) ? (b - a) : (a - b);
74  }
75  // @}
76 
77 } // namespace lar::util
78 
79 #endif // LARCOREALG_COREUTILS_NUMERICUTILS_H
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
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).
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
constexpr auto absDiff(A const &a, B const &b)
Returns the absolute value of the difference between two values.
Definition: NumericUtils.h:69