10 #ifndef LARDATAALG_UTILITIES_INTERVALS_H 11 #define LARDATAALG_UTILITIES_INTERVALS_H 18 #include <type_traits> 31 template <
typename Cat,
typename =
void>
34 template <
typename Cat>
39 template <
typename Cat>
50 static std::string name() =
delete;
57 template <
typename IV>
61 template <
typename IV>
66 template <
typename PT>
70 template <
typename PT>
105 template <
typename Q,
typename Cat = NoCategory>
113 template <
typename OC,
typename Type =
void>
115 std::enable_if_t<category_base_t::template category_compatible_with<OC>(), Type>;
130 template <
typename R>
137 using unit_t =
typename quantity_t::unit_t;
143 template <
typename OQ,
typename OI>
167 template <
typename... Args>
180 template <
typename IV,
typename std::enable_if_t<is_
interval_v<IV>>* =
nullptr>
197 using quantity_t::baseUnit;
198 using quantity_t::unit;
199 using quantity_t::unitName;
200 using quantity_t::unitSymbol;
213 template <
typename OU>
216 return quantity_t::template sameBaseUnitAs<OU>();
220 template <
typename OU>
223 return quantity_t::template sameUnitAs<OU>();
276 template <
typename OQ,
typename OC>
280 return quantity() / denom.
quantity();
284 template <
typename R>
292 template <
typename OQ,
typename OC>
299 template <
typename R>
302 quantity_t::operator-=(other);
307 template <
typename OQ,
typename OC>
310 return operator-=(other.
quantity());
314 template <
typename T>
317 quantity_t::operator*=(factor);
322 template <
typename T>
325 quantity_t::operator/=(factor);
359 template <
typename OQ,
typename OC>
360 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator==(
366 template <
typename OQ,
typename OC>
367 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator!=(
373 template <
typename OQ,
typename OC>
374 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator>=(
380 template <
typename OQ,
typename OC>
381 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator>(
387 template <
typename OQ,
typename OC>
388 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator<=(
394 template <
typename OQ,
typename OC>
395 constexpr enable_if_compatible_t<Interval<OQ, OC>,
bool>
operator<(
405 template <
typename IV>
419 template <
typename U>
427 template <
typename... Args>
446 template <
typename Q,
typename Cat,
typename... Args>
449 return a.quantity() == b;
452 template <
typename Q,
typename Cat,
typename... Args>
458 template <
typename Q,
typename Cat,
typename... Args>
461 return a.quantity() != b;
464 template <
typename Q,
typename Cat,
typename... Args>
470 template <
typename Q,
typename Cat,
typename... Args>
471 constexpr
bool operator<=(Interval<Q, Cat>
const a,
Quantity<Args...>
const b) noexcept
473 return a.quantity() <= b;
476 template <
typename Q,
typename Cat,
typename... Args>
482 template <
typename Q,
typename Cat,
typename... Args>
483 constexpr
bool operator<(Interval<Q, Cat>
const a,
Quantity<Args...>
const b) noexcept
485 return a.quantity() < b;
488 template <
typename Q,
typename Cat,
typename... Args>
494 template <
typename Q,
typename Cat,
typename... Args>
497 return a.quantity() >= b;
500 template <
typename Q,
typename Cat,
typename... Args>
506 template <
typename Q,
typename Cat,
typename... Args>
509 return a.quantity() > b;
512 template <
typename Q,
typename Cat,
typename... Args>
535 template <
typename Q,
typename Cat,
typename T>
543 template <
typename Q,
typename Cat,
typename T>
553 template <
typename AQ,
typename AC,
typename BQ,
typename BC>
559 template <
typename Q,
typename Cat,
typename T>
572 template <
typename IV,
typename R,
typename T =
typename IV::value_t>
577 template <
typename Q,
typename Cat>
604 template <
typename Q,
typename Cat = NoCategory,
typename IV = Interval<Q, Cat>>
612 template <
typename OC,
typename Type =
void>
614 std::enable_if_t<category_base_t::template category_compatible_with<OC>(), Type>;
632 template <
typename R>
639 using unit_t =
typename quantity_t::unit_t;
645 template <
typename OQ,
typename OI>
654 explicit Point() =
default;
669 template <
typename... Args>
682 template <
typename PT,
typename std::enable_if_t<is_po
int_v<PT>>* =
nullptr>
725 template <
typename R>
728 return point_t(quantity().plus(delta));
733 template <
typename OQ,
typename OC>
741 template <
typename R>
744 return point_t(quantity().minus(delta));
748 template <
typename OQ,
typename OC>
756 template <
typename R>
764 template <
typename OQ,
typename OC>
771 template <
typename R>
774 quantity_t::operator-=(other);
779 template <
typename OQ,
typename OC>
782 return operator-=(other.
quantity());
814 template <
typename OQ,
typename OI>
821 template <
typename OQ,
typename OI>
822 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
operator!=(
828 template <
typename OQ,
typename OI>
829 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
operator>=(
835 template <
typename OQ,
typename OI>
836 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
operator>(
842 template <
typename OQ,
typename OI>
843 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
operator<=(
849 template <
typename OQ,
typename OI>
850 constexpr enable_if_compatible_t<other_point_t<OQ, OI>,
bool>
operator<(
863 using quantity_t::baseUnit;
864 using quantity_t::unit;
865 using quantity_t::unitName;
866 using quantity_t::unitSymbol;
872 template <
typename PT>
873 constexpr std::enable_if_t<is_point_v<PT>, PT>
convertInto()
const 886 template <
typename U>
894 template <
typename... Args>
913 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
916 return a.quantity() == b;
919 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
925 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
928 return a.quantity() != b;
931 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
937 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
938 constexpr
bool operator<=(Point<Q, Cat, IV>
const a,
Quantity<Args...>
const b) noexcept
940 return a.quantity() <= b;
943 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
949 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
950 constexpr
bool operator<(Point<Q, Cat, IV>
const a,
Quantity<Args...>
const b) noexcept
952 return a.quantity() < b;
955 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
961 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
964 return a.quantity() >= b;
967 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
973 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
976 return a.quantity() > b;
979 template <
typename Q,
typename Cat,
typename IV,
typename... Args>
1001 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
1005 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OC>
1010 template <
typename Q,
typename Cat,
typename IV,
typename OQ,
typename OCat>
1022 template <
typename PT,
typename R,
typename T =
typename PT::value_t>
1026 template <
typename Q,
typename Cat,
typename IV>
1039 static std::string
name() {
return "generic"; }
1058 template <
typename IV>
1059 IV
makeInterval(std::string_view s,
bool unitOptional =
false);
1061 template <
typename IV>
1062 IV
makeInterval(std::string
const& s,
bool unitOptional =
false);
1064 template <
typename IV>
1065 IV
makeInterval(
char const* s,
bool unitOptional =
false);
1083 template <
typename PT>
1084 PT
makePoint(std::string_view s,
bool unitOptional =
false);
1086 template <
typename PT>
1087 PT
makePoint(std::string
const& s,
bool unitOptional =
false);
1089 template <
typename PT>
1090 PT
makePoint(
char const* s,
bool unitOptional =
false);
1104 template <
typename,
typename = std::
void_t<>>
1107 template <
typename Obj>
1110 template <
typename Obj>
1114 template <
typename,
typename = std::
void_t<>>
1117 template <
typename Cat>
1120 template <
typename Cat>
1129 template <
typename OC>
1132 return util::is_any_of_v<OC, NoCategory, category_t>;
1138 template <
typename Cat,
typename >
1143 template <
typename Cat>
1145 using type =
typename Cat::category_t;
1149 template <
typename Cat>
1162 template <
typename OC>
1163 static constexpr
bool same_category_as();
1165 template <
typename OC>
1166 static constexpr
bool same_category_as(OC
const&);
1171 template <
typename OC>
1172 static constexpr
bool category_compatible_with();
1174 template <
typename OC>
1175 static constexpr
bool category_compatible_with(OC
const&);
1179 static constexpr
bool hasCategoryName();
1182 static std::string categoryName();
1189 template <
typename Cat>
1196 template <
typename Cat>
1197 template <
typename OC>
1200 return details::has_category_v<OC> && std::is_same_v<typename OC::category_t, category_t>;
1203 template <
typename Cat>
1204 template <
typename OC>
1207 return same_category_as<OC>();
1211 template <
typename Cat>
1212 template <
typename OC>
1215 return traits_t::template compatible_with<category_of<OC>>();
1218 template <
typename Cat>
1219 template <
typename OC>
1222 return category_compatible_with<OC>();
1226 template <
typename Cat>
1233 template <
typename Cat>
1252 template <
typename... Args>
1257 struct is_point :
public std::false_type {};
1259 template <
typename... Args>
1269 template <
typename IV>
1272 using quantity_t =
typename IV::quantity_t;
1273 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1277 template <
typename IV>
1280 using quantity_t =
typename IV::quantity_t;
1281 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1285 template <
typename IV>
1288 using quantity_t =
typename IV::quantity_t;
1289 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1293 template <
typename PT>
1296 using quantity_t =
typename PT::quantity_t;
1297 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1301 template <
typename PT>
1304 using quantity_t =
typename PT::quantity_t;
1305 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1309 template <
typename PT>
1312 using quantity_t =
typename PT::quantity_t;
1313 return {util::quantities::makeQuantity<quantity_t>(s, unitOptional)};
1323 template <
typename Q,
typename Cat>
1324 struct hash<
util::quantities::concepts::Interval<Q, Cat>> {
1326 noexcept(noexcept(std::hash(key.quantity())))
1328 return std::hash(key.quantity());
1332 template <
typename Q,
typename Cat,
typename IV>
1335 noexcept(noexcept(std::hash(key.quantity())))
1337 return std::hash(key.quantity());
1344 template <
typename Q,
typename Cat>
1345 class numeric_limits<
util::quantities::concepts::Interval<Q, Cat>>
1347 util::quantities::concepts::Interval<Q, Cat>> {};
1349 template <
typename Q,
typename Cat>
1350 class numeric_limits<util::quantities::concepts::Interval<Q, Cat> const>
1352 util::quantities::concepts::Interval<Q, Cat> const> {};
1354 template <
typename Q,
typename Cat>
1355 class numeric_limits<util::quantities::concepts::Interval<Q, Cat> volatile>
1357 util::quantities::concepts::Interval<Q, Cat> volatile> {};
1359 template <
typename Q,
typename Cat>
1360 class numeric_limits<util::quantities::concepts::Interval<Q, Cat> const volatile>
1362 util::quantities::concepts::Interval<Q, Cat> const volatile> {};
1364 template <
typename Q,
typename Cat,
typename IV>
1367 util::quantities::concepts::Point<Q, Cat, IV>> {};
1369 template <
typename Q,
typename Cat,
typename IV>
1372 util::quantities::concepts::Point<Q, Cat, IV> const> {};
1374 template <
typename Q,
typename Cat,
typename IV>
1377 util::quantities::concepts::Point<Q, Cat, IV> volatile> {};
1379 template <
typename Q,
typename Cat,
typename IV>
1382 util::quantities::concepts::Point<Q, Cat, IV> const volatile> {};
1390 #endif // LARDATAALG_UTILITIES_INTERVALS_H point_t & operator+=(scaled_quantity_t< R > const other)
Add a quantity (possibly converted) to this one.
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.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator<(other_point_t< OQ, OI > const other) const
Namespace for general, non-LArSoft-specific utilities.
constexpr enable_if_compatible_t< Interval< OQ, OC >, point_t > operator+(Interval< OQ, OC > const delta) const
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)
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 bool operator<=(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
constexpr enable_if_compatible_t< Interval< OQ, OC >, value_t > operator/(Interval< OQ, OC > const denom) const
Division by an interval, returns a pure number.
constexpr interval_t operator-(interval_t const other) const
constexpr bool operator>(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
Q quantity_t
Quantity the interval is based on.
constexpr point_t operator+(scaled_quantity_t< R > const delta) const
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.
enable_if_compatible_t< Interval< OQ, OC >, point_t & > operator+=(Interval< OQ, OC > const other)
Add the other interval (possibly converted) to this point.
constexpr Point< Q, Cat, IV > operator+(Interval< OQ, OC > const delta, Point< Q, Cat, IV > const p)=delete
Multiplication with a scalar.
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
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator<(Interval< OQ, OC > const other) const
constexpr bool operator<(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
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.
constexpr auto operator()(util::quantities::concepts::Interval< Q, Cat > key) const noexcept(noexcept(std::hash(key.quantity())))
typename category_of_type< Cat >::type category_of
constexpr enable_if_compatible_t< Interval< OQ, OC >, bool > operator<=(Interval< OQ, OC > const other) const
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.
constexpr point_t operator-(scaled_quantity_t< R > const delta) const
Returns the value of this point after subtraction of an interval.
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 auto operator()(util::quantities::concepts::Point< Q, Cat, IV > key) const noexcept(noexcept(std::hash(key.quantity())))
constexpr Interval(Quantity< Args... > const &q)
Constructor: converts from a quantity.
constexpr bool is_interval_v
Trait: true if IV is a Interval specialization.
enable_if_compatible_t< Interval< OQ, OC >, interval_t & > operator+=(Interval< OQ, OC > const other)
Add the other interval (possibly converted) to this one.
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.
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, bool > operator<=(other_point_t< OQ, OI > const other) const
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
constexpr bool operator>=(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
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.
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
point_t & operator-=(scaled_quantity_t< R > const other)
Subtract a quantity (possibly converted) from this one.
constexpr bool operator==(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
enable_if_compatible_t< Interval< OQ, OC >, interval_t & > operator-=(Interval< OQ, OC > const other)
Subtract the other interval (possibly converted) from this one.
typename quantity_t::baseunit_t baseunit_t
Description of the unscaled unit.
String & operator+=(String &s, VectorDumper< Vector > const &manip)
Appends a string rendering of a vector to the specified string.
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
constexpr bool operator!=(Interval< Q, Cat > const a, Quantity< Args... > const b) noexcept
An interval (duration, length, distance) between two quantity points.
interval_t & operator-=(scaled_quantity_t< R > const other)
Subtract a quantity (possibly converted) from this one.
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
enable_if_compatible_t< Interval< OQ, OC >, point_t & > operator-=(Interval< OQ, OC > const other)
Subtract the other interval (possibly converted) from this point.
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
Multiplication with a scalar.
An non-mandatory base class for interval and point categories.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type > enable_if_compatible_t
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.
Q quantity_t
Quantity the interval is based on.
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 enable_if_compatible_t< Interval< OQ, OC >, point_t > operator-(Interval< OQ, OC > const delta) const
Returns the value of this point after subtraction of an interval.
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
interval_t & operator+=(scaled_quantity_t< R > const other)
Add a quantity (possibly converted) to this one.
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.