10 #ifndef LARDATAALG_UTILITIES_INTERVALS_H 11 #define LARDATAALG_UTILITIES_INTERVALS_H 18 #include <type_traits> 32 template <
typename Cat,
typename =
void>
35 template <
typename Cat>
41 template <
typename Cat>
62 template <
typename IV>
66 template <
typename IV>
72 template <
typename PT>
76 template <
typename PT>
113 template <
typename Q,
typename Cat = NoCategory>
121 template <
typename OC,
typename Type =
void>
124 <category_base_t::template category_compatible_with<OC>(),
Type>
142 template <
typename R>
149 using unit_t =
typename quantity_t::unit_t;
155 template <
typename OQ,
typename OI>
179 template <
typename... Args>
194 <
typename IV,
typename std::enable_if_t<is_interval_v<IV>>* =
nullptr>
212 using quantity_t::unit;
213 using quantity_t::unitName;
214 using quantity_t::unitSymbol;
215 using quantity_t::baseUnit;
228 template <
typename OU>
230 {
return quantity_t::template sameBaseUnitAs<OU>(); }
233 template <
typename OU>
235 {
return quantity_t::template sameUnitAs<OU>(); }
285 template <
typename OQ,
typename OC>
291 template <
typename R>
296 template <
typename OQ,
typename OC>
297 enable_if_compatible_t<Interval<OQ, OC>,
interval_t&>
302 template <
typename R>
304 { quantity_t::operator-= (other);
return *
this; }
307 template <
typename OQ,
typename OC>
308 enable_if_compatible_t<Interval<OQ, OC>,
interval_t&>
310 {
return operator-= (other.
quantity()); }
313 template <
typename T>
315 { quantity_t::operator*= (factor);
return *
this; }
318 template <
typename T>
320 { quantity_t::operator/= (factor);
return *
this; }
353 template <
typename OQ,
typename OC>
354 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
358 template <
typename OQ,
typename OC>
359 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
363 template <
typename OQ,
typename OC>
364 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
368 template <
typename OQ,
typename OC>
369 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
373 template <
typename OQ,
typename OC>
374 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
375 operator<=(Interval<OQ, OC>
const other)
const 378 template <
typename OQ,
typename OC>
379 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
380 operator<(Interval<OQ, OC>
const other)
const 388 template <
typename IV>
399 template <
typename U>
406 template <
typename... Args>
424 template <
typename Q,
typename Cat,
typename... Args>
425 constexpr
bool operator==
429 template <
typename Q,
typename Cat,
typename... Args>
430 constexpr
bool operator==
434 template <
typename Q,
typename Cat,
typename... Args>
435 constexpr
bool operator!=
439 template <
typename Q,
typename Cat,
typename... Args>
440 constexpr
bool operator!=
444 template <
typename Q,
typename Cat,
typename... Args>
445 constexpr
bool operator<=
449 template <
typename Q,
typename Cat,
typename... Args>
450 constexpr
bool operator<=
454 template <
typename Q,
typename Cat,
typename... Args>
455 constexpr
bool operator<
459 template <
typename Q,
typename Cat,
typename... Args>
460 constexpr
bool operator<
464 template <
typename Q,
typename Cat,
typename... Args>
465 constexpr
bool operator>=
469 template <
typename Q,
typename Cat,
typename... Args>
470 constexpr
bool operator>=
474 template <
typename Q,
typename Cat,
typename... Args>
475 constexpr
bool operator>
479 template <
typename Q,
typename Cat,
typename... Args>
480 constexpr
bool operator>
503 template <
typename Q,
typename Cat,
typename T>
507 template <
typename Q,
typename Cat,
typename T>
513 template <
typename AQ,
typename AC,
typename BQ,
typename BC>
519 template <
typename Q,
typename Cat,
typename T>
530 template <
typename IV,
typename R,
typename T =
typename IV::value_t>
536 template <
typename Q,
typename Cat>
573 template <
typename OC,
typename Type =
void>
576 <category_base_t::template category_compatible_with<OC>(),
Type>
598 template <
typename R>
605 using unit_t =
typename quantity_t::unit_t;
611 template <
typename OQ,
typename OI>
620 explicit Point() =
default;
635 template <
typename... Args>
649 <
typename PT,
typename std::enable_if_t<is_point_v<PT>>* =
nullptr>
694 template <
typename R>
700 template <
typename OQ,
typename OC>
706 template <
typename R>
711 template <
typename OQ,
typename OC>
712 constexpr enable_if_compatible_t<Interval<OQ, OC>,
point_t>
717 template <
typename R>
722 template <
typename OQ,
typename OC>
723 enable_if_compatible_t<Interval<OQ, OC>,
point_t&>
operator+=
728 template <
typename R>
730 { quantity_t::operator-= (other);
return *
this; }
733 template <
typename OQ,
typename OC>
734 enable_if_compatible_t<Interval<OQ, OC>, point_t&>
operator-=
736 {
return operator-= (
other.quantity()); }
768 template <
typename OQ,
typename OI>
772 template <
typename OQ,
typename OI>
773 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
777 template <
typename OQ,
typename OI>
778 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
782 template <
typename OQ,
typename OI>
783 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
787 template <
typename OQ,
typename OI>
788 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
789 operator<=(other_point_t<OQ, OI>
const other)
const 792 template <
typename OQ,
typename OI>
793 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
794 operator<(other_point_t<OQ, OI>
const other)
const 806 using quantity_t::unit;
807 using quantity_t::baseUnit;
808 using quantity_t::unitName;
809 using quantity_t::unitSymbol;
815 template <
typename PT>
816 constexpr std::enable_if_t<is_point_v<PT>, PT>
convertInto()
const {
return PT(*
this); }
826 template <
typename U>
833 template <
typename... Args>
852 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
853 constexpr
bool operator==
857 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
858 constexpr
bool operator==
862 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
863 constexpr
bool operator!=
867 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
868 constexpr
bool operator!=
872 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
873 constexpr
bool operator<=
877 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
878 constexpr
bool operator<=
882 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
883 constexpr
bool operator<
887 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
888 constexpr
bool operator<
892 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
893 constexpr
bool operator>=
897 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
898 constexpr
bool operator>=
902 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
903 constexpr
bool operator>
907 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
908 constexpr
bool operator>
928 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
933 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
940 <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OCat>
943 ::template enable_if_compatible_t<Point<OQ, OCat, IV>, IV>
953 template <
typename PT,
typename R,
typename T =
typename PT::value_t>
959 template <
typename Q,
typename Cat,
typename IV>
991 template <
typename IV>
992 IV
makeInterval(std::string_view
s,
bool unitOptional =
false);
994 template <
typename IV>
997 template <
typename IV>
998 IV
makeInterval(
char const* s,
bool unitOptional =
false);
1017 template <
typename PT>
1018 PT
makePoint(std::string_view s,
bool unitOptional =
false);
1020 template <
typename PT>
1023 template <
typename PT>
1024 PT
makePoint(
char const* s,
bool unitOptional =
false);
1040 template <
typename,
typename = std::
void_t<>>
1043 template <
typename Obj>
1048 template <
typename Obj>
1052 template <
typename,
typename = std::
void_t<>>
1055 template <
typename Cat>
1057 : std::true_type {};
1059 template <
typename Cat>
1068 template <
typename OC>
1070 {
return util::is_any_of_v<OC, NoCategory, category_t>; }
1076 template <
typename Cat,
typename >
1079 template <
typename Cat>
1081 {
using type =
typename Cat::category_t; };
1085 template <
typename Cat>
1098 template <
typename OC>
1099 static constexpr
bool same_category_as();
1101 template <
typename OC>
1102 static constexpr
bool same_category_as(OC
const&);
1107 template <
typename OC>
1108 static constexpr
bool category_compatible_with();
1110 template <
typename OC>
1111 static constexpr
bool category_compatible_with(OC
const&);
1116 static constexpr
bool hasCategoryName();
1127 template <
typename Cat>
1132 template <
typename Cat>
1133 template <
typename OC>
1135 return details::has_category_v<OC>
1136 && std::is_same_v<typename OC::category_t, category_t>;
1139 template <
typename Cat>
1140 template <
typename OC>
1142 {
return same_category_as<OC>(); }
1146 template <
typename Cat>
1147 template <
typename OC>
1149 {
return traits_t::template compatible_with<category_of<OC>>(); }
1152 template <
typename Cat>
1153 template <
typename OC>
1155 {
return category_compatible_with<OC>(); }
1158 template <
typename Cat>
1164 template <
typename Cat>
1183 template <
typename... Args>
1189 struct is_point:
public std::false_type {};
1191 template <
typename... Args>
1203 template <
typename IV>
1205 (std::string_view
s,
bool unitOptional )
1207 using quantity_t =
typename IV::quantity_t;
1208 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1213 template <
typename IV>
1217 using quantity_t =
typename IV::quantity_t;
1218 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1223 template <
typename IV>
1225 (
char const* s,
bool unitOptional )
1227 using quantity_t =
typename IV::quantity_t;
1228 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1233 template <
typename PT>
1235 (std::string_view s,
bool unitOptional )
1237 using quantity_t =
typename PT::quantity_t;
1238 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1243 template <
typename PT>
1247 using quantity_t =
typename PT::quantity_t;
1248 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1253 template <
typename PT>
1255 (
char const* s,
bool unitOptional )
1257 using quantity_t =
typename PT::quantity_t;
1258 return { util::quantities::makeQuantity<quantity_t>(
s, unitOptional) };
1269 template <
typename Q,
typename Cat>
1270 struct hash<
util::quantities::concepts::Interval<Q, Cat>> {
1271 constexpr
auto operator()
1273 noexcept(noexcept(std::hash(
key.quantity())))
1274 {
return std::hash(
key.quantity()); }
1277 template <
typename Q,
typename Cat,
typename IV>
1279 constexpr
auto operator()
1281 noexcept(noexcept(std::hash(
key.quantity())))
1282 {
return std::hash(
key.quantity()); }
1289 template <
typename Q,
typename Cat>
1290 class numeric_limits<
util::quantities::concepts::Interval<Q, Cat>>
1292 <util::quantities::concepts::Interval<Q, Cat>>
1295 template <
typename Q,
typename Cat>
1296 class numeric_limits<util::quantities::concepts::Interval<Q, Cat>
const>
1298 <util::quantities::concepts::Interval<Q, Cat> const>
1301 template <
typename Q,
typename Cat>
1302 class numeric_limits<util::quantities::concepts::Interval<Q, Cat> volatile>
1304 <util::quantities::concepts::Interval<Q, Cat> volatile>
1307 template <
typename Q,
typename Cat>
1308 class numeric_limits
1309 <util::quantities::concepts::Interval<Q, Cat>
const volatile>
1311 <util::quantities::concepts::Interval<Q, Cat> const volatile>
1315 template <
typename Q,
typename Cat,
typename IV>
1318 <util::quantities::concepts::Point<Q, Cat, IV>>
1321 template <
typename Q,
typename Cat,
typename IV>
1324 <util::quantities::concepts::Point<Q, Cat, IV> const>
1327 template <
typename Q,
typename Cat,
typename IV>
1330 <util::quantities::concepts::Point<Q, Cat, IV> volatile>
1333 template <
typename Q,
typename Cat,
typename IV>
1334 class numeric_limits
1337 <util::quantities::concepts::Point<Q, Cat, IV> const volatile>
1348 #endif // LARDATAALG_UTILITIES_INTERVALS_H
constexpr interval_t operator+() const
Returns an interval with same value.
typename category_base_t::category_t category_t
Quantity the interval is based on.
Namespace for general, non-LArSoft-specific utilities.
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator==(Interval< OQ, OC > const other) const
constexpr std::enable_if_t< std::is_arithmetic_v< T >, Interval< Q, Cat > > operator/(Interval< Q, Cat > const iv, T const quot)
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
constexpr Interval(IV iv)
Constructor: converts from another interval.
static constexpr bool sameBaseUnitAs()
Returns whether objects of type OU have the same base unit as this.
constexpr interval_t operator-(interval_t const other) const
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Q quantity_t
Quantity the interval is based on.
constexpr Interval(value_t v)
Constructor: takes a value in the intended representation.
interval_t & operator*=(T factor)
Scale this interval by a factor.
static interval_t castFrom(U value)
Returns a new interval initialized with the specified value.
typename T::interval_t interval_of
Type of interval contained in specified type T.
constexpr Point< Q, Cat, IV > operator+(Interval< OQ, OC > const delta, Point< Q, Cat, IV > const p)=delete
interval_t & operator/=(T factor)
Scale the interval dividing it by a quotient.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator>=(other_point_t< OQ, OI > const other) const
PT makePoint(std::string_view s, bool unitOptional=false)
Returns a point of the specified type parsed from a string.
Trait: true_type if IV is a Interval specialization.
typename category_of_type< Cat >::type category_of
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator>=(Interval< OQ, OC > const other) const
static constexpr category_t category()
Returns an instance of the category of this object.
std::string to_string(Interval< Q, Cat > const &iv)
typename quantity_t::baseunit_t baseunit_t
Description of the unscaled unit.
constexpr bool operator<(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
typename category_base_t::traits_t traits_t
Traits of the category.
typename category_base_t::category_t category_t
The category this point belongs to.
constexpr Interval(Quantity< Args... > const &q)
Constructor: converts from a quantity.
constexpr bool is_interval_v
Trait: true if IV is a Interval specialization.
An object belonging to a category Cat.
Infrastructure for the quantities library.
static std::string categoryName()
Returns the name of the category of this object.
static point_t castFrom(U value)
Returns a new point initialized with the specified value.
static constexpr bool sameUnitAs()
Returns whether objects of type OU have same unit and scale as this.
static constexpr bool same_category_as()
Returns whether the type OC belongs to category_t.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
static constexpr bool category_compatible_with()
Returns whether OC has a category compatible with this one.
constexpr point_t operator-() const
Returns a parity-changed point.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
constexpr bool operator==(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
A value measured in the specified unit.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator>(other_point_t< OQ, OI > const other) const
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
typename quantity_t::baseunit_t baseunit_t
Description of the unscaled unit.
constexpr interval_t operator+(interval_t const other) const
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Cat category_t
The categories the traits are about.
constexpr IV convertInto() const
Convert this interval into the specified one.
constexpr bool operator!=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
constexpr bool operator<=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
An interval (duration, length, distance) between two quantity points.
IV interval_t
The interval type corresponding to the unit of this point.
constexpr std::enable_if_t< is_point_v< PT >, PT > convertInto() const
Convert this interval into the specified one.
static constexpr bool compatible_with()
Returns whether the category OC is "compatible" with this one.
constexpr bool operator>(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
constexpr bool has_category_v
Trait: true_type if PT is a Point specialization.
constexpr Point(Quantity< Args... > const q)
Constructor: converts from a quantity.
Numeric variable proxies with embedded unit of measurement.
constexpr Point(PT const p)
Constructor: converts from another point.
static std::string name()
constexpr bool operator>=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator!=(other_point_t< OQ, OI > const other) const
Cat category_t
The category of this object.
std::ostream & operator<<(std::ostream &out, Interval< Args... > const iv)
constexpr Point< Q, Cat, IV > operator-(Interval< OQ, OC > const delta, Point< Q, Cat, IV > const p)=delete
An non-mandatory base class for interval and point categories.
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator>(Interval< OQ, OC > const other) const
constexpr interval_t abs() const
Returns an interval with the absolute value of this one.
typename quantity_t::value_t value_t
Type of the stored value.
constexpr std::enable_if_t< std::is_arithmetic_v< T >, Interval< Q, Cat > > operator*(Interval< Q, Cat > const iv, T const factor)
Multiplication with a scalar.
typename quantity_t::value_t value_t
Type of the stored value.
constexpr interval_t operator-() const
Returns an interval with same value but the sign flipped.
Limits of a quantity are the same as the underlying type.
IV makeInterval(std::string_view s, bool unitOptional=false)
Returns an interval of the specified type parsed from a string.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator==(other_point_t< OQ, OI > const other) const
constexpr bool is_interval_or_point_v
Trait: true if PT is a specialization of Interval or Point.
Types of variables with a unit.
typename category_base_t::traits_t traits_t
Traits of the category.
constexpr point_t operator+() const
Returns a point with same value.
constexpr bool is_point_v
Trait: true if PT is a Point specialization.
constexpr Point(value_t v)
Constructor: takes a value in the intended representation.
typename quantity_t::unit_t unit_t
Description of the scaled unit.
static constexpr bool hasCategoryName()
Returns whether this category has a name.
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator!=(Interval< OQ, OC > const other) const
typename quantity_t::unit_t unit_t
Description of the scaled unit.
std::disjunction< is_interval< T >, is_point< T >> is_interval_or_point
Trait: true_type if PT is a specialization of Interval or Point.