Public Types | Public Member Functions | Static Public Member Functions | List of all members
util::quantities::concepts::Point< Q, Cat, IV > Struct Template Reference

A quantity point. More...

#include <intervals.h>

Inheritance diagram for util::quantities::concepts::Point< Q, Cat, IV >:
util::quantities::concepts::details::WithCategory< Cat >

Public Types

using category_base_t = details::WithCategory< Cat >
 
using traits_t = typename category_base_t::traits_t
 Traits of the category. More...
 
template<typename OC , typename Type = void>
using enable_if_compatible_t = std::enable_if_t< category_base_t::template category_compatible_with< OC >(), Type >
 
using point_t = Point< Q, Cat, IV >
 This type. More...
 
Types from the base quantity
using quantity_t = Q
 Quantity the interval is based on. More...
 
using category_t = typename category_base_t::category_t
 The category this point belongs to. More...
 
using interval_t = IV
 The interval type corresponding to the unit of this point. More...
 
template<typename R >
using scaled_quantity_t = rescale< quantity_t, R >
 A quantity in the same unit, but possibly a different scale. More...
 
using value_t = typename quantity_t::value_t
 Type of the stored value. More...
 
using unit_t = typename quantity_t::unit_t
 Description of the scaled unit. More...
 
using baseunit_t = typename quantity_t::baseunit_t
 Description of the unscaled unit. More...
 
template<typename OQ , typename OI >
using other_point_t = Point< OQ, category_t, OI >
 A point based on a different quantity but with the same category. More...
 
- Public Types inherited from util::quantities::concepts::details::WithCategory< Cat >
using category_t = Cat
 The category of this object. More...
 
using traits_t = category_traits< category_t >
 Traits of this category. More...
 

Public Member Functions

 Point ()=default
 Constructor: value is left uninitialized. More...
 
constexpr Point (value_t v)
 Constructor: takes a value in the intended representation. More...
 
template<typename... Args>
constexpr Point (Quantity< Args... > const q)
 Constructor: converts from a quantity. More...
 
template<typename PT , typename std::enable_if_t< is_point_v< PT >> * = nullptr>
constexpr Point (PT const p)
 Constructor: converts from another point. More...
 
constexpr quantity_t const & quantity () const
 Returns the value of the interval as a quantity. More...
 
constexpr operator value_t () const
 Conversion to the base quantity. More...
 
template<typename PT >
constexpr std::enable_if_t< is_point_v< PT >, PT > convertInto () const
 Convert this interval into the specified one. More...
 
Asymmetric operand arithmetic operations

These arithmetic operations take care of preserving the point unit through them. Not all possible (or reasonable) operations are supported yet. Some operations that may be symmetric (like addition of interval) are implemented as free functions rather than methods.

Note
These operations are essentially provided by convenience. There are many cases (corner and not) where the implicit conversion to the base type kicks in. This implementation does not aim to prevent that from happening, but requests are welcome to add features to allow that not to happen, with some care of the user.
Differently from Interval, the addition and subtraction of interval to points is not symmetric, i.e. adding an interval to a point is supported (resulting in another point) but adding a point to an interval is not. Another difference is that since the result is unmistakably associated with the one operand of point type, the result has the same unit and type as that operand and the other operand, the interval, can be converted from a different unit scale.
template<typename R >
constexpr point_t operator+ (scaled_quantity_t< R > const delta) const
 
template<typename OQ , typename OC >
constexpr enable_if_compatible_t< Interval< OQ, OC >, point_toperator+ (Interval< OQ, OC > const delta) const
 
template<typename R >
constexpr point_t operator- (scaled_quantity_t< R > const delta) const
 Returns the value of this point after subtraction of an interval. More...
 
template<typename OQ , typename OC >
constexpr enable_if_compatible_t< Interval< OQ, OC >, point_toperator- (Interval< OQ, OC > const delta) const
 Returns the value of this point after subtraction of an interval. More...
 
template<typename R >
point_toperator+= (scaled_quantity_t< R > const other)
 Add a quantity (possibly converted) to this one. More...
 
template<typename OQ , typename OC >
enable_if_compatible_t< Interval< OQ, OC >, point_t & > operator+= (Interval< OQ, OC > const other)
 Add the other interval (possibly converted) to this point. More...
 
template<typename R >
point_toperator-= (scaled_quantity_t< R > const other)
 Subtract a quantity (possibly converted) from this one. More...
 
template<typename OQ , typename OC >
enable_if_compatible_t< Interval< OQ, OC >, point_t & > operator-= (Interval< OQ, OC > const other)
 Subtract the other interval (possibly converted) from this point. More...
 
constexpr point_t operator+ () const
 Returns a point with same value. More...
 
constexpr point_t operator- () const
 Returns a parity-changed point. More...
 
Comparisons.

Comparisons with plain numbers are managed by implicit conversion. More care is needed for quantities. Comparisons between two point instances a and b work this way:

  • if a and b belong to different categories, they are not comparable
  • if a and b do not have the same unit, they are not comparable
  • if a and b have the same unit, one is converted to the other and the comparison is performed there
  • if a and b have the same scaled unit, their values are compared directly

Value storage types are compared according to C++ rules.

template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator== (other_point_t< OQ, OI > const other) const
 
template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator!= (other_point_t< OQ, OI > const other) const
 
template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator>= (other_point_t< OQ, OI > const other) const
 
template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator> (other_point_t< OQ, OI > const other) const
 
template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator<= (other_point_t< OQ, OI > const other) const
 
template<typename OQ , typename OI >
constexpr enable_if_compatible_t< other_point_t< OQ, OI >, booloperator< (other_point_t< OQ, OI > const other) const
 

Static Public Member Functions

template<typename U >
static point_t castFrom (U value)
 Returns a new point initialized with the specified value. More...
 
- Static Public Member Functions inherited from util::quantities::concepts::details::WithCategory< Cat >
static constexpr category_t category ()
 Returns an instance of the category of this object. More...
 
static constexpr bool hasCategoryName ()
 Returns whether this category has a name. More...
 
static std::string categoryName ()
 Returns the name of the category of this object. More...
 
template<typename OC >
static constexpr bool same_category_as ()
 Returns whether the type OC belongs to category_t. More...
 
template<typename OC >
static constexpr bool same_category_as (OC const &)
 
template<typename OC >
static constexpr bool category_compatible_with ()
 Returns whether OC has a category compatible with this one. More...
 
template<typename OC >
static constexpr bool category_compatible_with (OC const &)
 

Detailed Description

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
struct util::quantities::concepts::Point< Q, Cat, IV >

A quantity point.


Template Parameters
Qquantity the interval is based on
Catcategory this point belongs to (NoCategory by default)

A point shares most of the concepts of a Quantity, but it interacts only with other points rather than with bare Quantity objects, with the exception of construction. In this sense, the relation between Point and Quantity is similar to the one between Quantity and its base type (Quantity::value_t).

In addition, Point has some interaction with the corresponding Interval: an interval can be seen as the distance, or difference, between two quantity points.

The point belongs to a category, which is just a tag that prevents different points from being mixed up. Note that intervals do not have a category.

Definition at line 566 of file intervals.h.

Member Typedef Documentation

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::baseunit_t = typename quantity_t::baseunit_t

Description of the unscaled unit.

Definition at line 608 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::category_base_t = details::WithCategory<Cat>

Definition at line 568 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::category_t = typename category_base_t::category_t

The category this point belongs to.

Definition at line 592 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OC , typename Type = void>
using util::quantities::concepts::Point< Q, Cat, IV >::enable_if_compatible_t = std::enable_if_t <category_base_t::template category_compatible_with<OC>(), Type>

Definition at line 577 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::interval_t = IV

The interval type corresponding to the unit of this point.

Definition at line 595 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
using util::quantities::concepts::Point< Q, Cat, IV >::other_point_t = Point<OQ, category_t, OI>

A point based on a different quantity but with the same category.

Definition at line 612 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::point_t = Point<Q, Cat, IV>

This type.

Definition at line 582 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::quantity_t = Q

Quantity the interval is based on.

Definition at line 589 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename R >
using util::quantities::concepts::Point< Q, Cat, IV >::scaled_quantity_t = rescale<quantity_t, R>

A quantity in the same unit, but possibly a different scale.

Definition at line 599 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::traits_t = typename category_base_t::traits_t

Traits of the category.

Definition at line 571 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::unit_t = typename quantity_t::unit_t

Description of the scaled unit.

Definition at line 605 of file intervals.h.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
using util::quantities::concepts::Point< Q, Cat, IV >::value_t = typename quantity_t::value_t

Type of the stored value.

Definition at line 602 of file intervals.h.

Constructor & Destructor Documentation

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
util::quantities::concepts::Point< Q, Cat, IV >::Point ( )
explicitdefault

Constructor: value is left uninitialized.

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
constexpr util::quantities::concepts::Point< Q, Cat, IV >::Point ( value_t  v)
inlineexplicit

Constructor: takes a value in the intended representation.

Definition at line 623 of file intervals.h.

623 : Point(quantity_t{ v }) {}
Point()=default
Constructor: value is left uninitialized.
Q quantity_t
Quantity the interval is based on.
Definition: intervals.h:589
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename... Args>
constexpr util::quantities::concepts::Point< Q, Cat, IV >::Point ( Quantity< Args... > const  q)
inline

Constructor: converts from a quantity.

Template Parameters
OQtype of the quantity
Parameters
qquantity to be converted from

The quantity is required to be in the same unit as this point (unit scale may differ). The value in q is converted from its native scale into the one of this point.

Definition at line 636 of file intervals.h.

637  : quantity_t(quantity_t{ q }) {}
Q quantity_t
Quantity the interval is based on.
Definition: intervals.h:589
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename PT , typename std::enable_if_t< is_point_v< PT >> * = nullptr>
constexpr util::quantities::concepts::Point< Q, Cat, IV >::Point ( PT const  p)
inline

Constructor: converts from another point.

Template Parameters
PTtype of the other point
Parameters
ppoint to be converted from

Points are required to be in the same unit (unit scale may differ). The value in p is converted from its native scale into the one of this point.

Definition at line 650 of file intervals.h.

650 : Point(quantity_t{ p.quantity() }) {}
Point()=default
Constructor: value is left uninitialized.
Q quantity_t
Quantity the interval is based on.
Definition: intervals.h:589
p
Definition: test.py:223

Member Function Documentation

template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename U >
static point_t util::quantities::concepts::Point< Q, Cat, IV >::castFrom ( value)
inlinestatic

Returns a new point initialized with the specified value.

Template Parameters
Utype to initialize the quantity with
Parameters
valuethe value to initialize the point with
Returns
a new Point object initialized with value

The value is cast into value_t via static_cast().

Definition at line 827 of file intervals.h.

828  { return point_t{ static_cast<value_t>(value) }; }
typename quantity_t::value_t value_t
Type of the stored value.
Definition: intervals.h:602
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename PT >
constexpr std::enable_if_t<is_point_v<PT>, PT> util::quantities::concepts::Point< Q, Cat, IV >::convertInto ( ) const
inline

Convert this interval into the specified one.

Definition at line 816 of file intervals.h.

816 { return PT(*this); }
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
constexpr util::quantities::concepts::Point< Q, Cat, IV >::operator value_t ( ) const
inlineexplicit

Conversion to the base quantity.

Definition at line 659 of file intervals.h.

660  { return value(); }
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator!= ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 774 of file intervals.h.

775  { return quantity_t::operator!=(other.quantity()); }
constexpr bool operator!=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:869
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename R >
constexpr point_t util::quantities::concepts::Point< Q, Cat, IV >::operator+ ( scaled_quantity_t< R > const  delta) const
inline

Returns the sum of this point plus an interval (from quantity) (note that addition is not symmetric).

Definition at line 695 of file intervals.h.

696  { return point_t(quantity().plus(delta)); }
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Definition: intervals.h:653
Point< Q, Cat, IV > point_t
This type.
Definition: intervals.h:582
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OC >
constexpr enable_if_compatible_t<Interval<OQ, OC>, point_t> util::quantities::concepts::Point< Q, Cat, IV >::operator+ ( Interval< OQ, OC > const  delta) const
inline

Returns the sum of this point plus an interval (note that addition is not symmetric).

Definition at line 702 of file intervals.h.

703  { return operator+ (delta.quantity()); }
constexpr point_t operator+() const
Returns a point with same value.
Definition: intervals.h:739
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
constexpr point_t util::quantities::concepts::Point< Q, Cat, IV >::operator+ ( ) const
inline

Returns a point with same value.

Definition at line 739 of file intervals.h.

739 { return point_t(quantity()); }
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Definition: intervals.h:653
Point< Q, Cat, IV > point_t
This type.
Definition: intervals.h:582
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename R >
point_t& util::quantities::concepts::Point< Q, Cat, IV >::operator+= ( scaled_quantity_t< R > const  other)
inline

Add a quantity (possibly converted) to this one.

Definition at line 718 of file intervals.h.

719  { quantity_t::operator+= (other); return *this; }
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OC >
enable_if_compatible_t<Interval<OQ, OC>, point_t&> util::quantities::concepts::Point< Q, Cat, IV >::operator+= ( Interval< OQ, OC > const  other)
inline

Add the other interval (possibly converted) to this point.

Definition at line 724 of file intervals.h.

725  { return operator+= (other.quantity()); }
point_t & operator+=(scaled_quantity_t< R > const other)
Add a quantity (possibly converted) to this one.
Definition: intervals.h:718
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename R >
constexpr point_t util::quantities::concepts::Point< Q, Cat, IV >::operator- ( scaled_quantity_t< R > const  delta) const
inline

Returns the value of this point after subtraction of an interval.

Definition at line 707 of file intervals.h.

708  { return point_t(quantity().minus(delta)); }
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Definition: intervals.h:653
Point< Q, Cat, IV > point_t
This type.
Definition: intervals.h:582
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OC >
constexpr enable_if_compatible_t<Interval<OQ, OC>, point_t> util::quantities::concepts::Point< Q, Cat, IV >::operator- ( Interval< OQ, OC > const  delta) const
inline

Returns the value of this point after subtraction of an interval.

Definition at line 713 of file intervals.h.

714  { return operator- (delta.quantity()); }
constexpr point_t operator-() const
Returns a parity-changed point.
Definition: intervals.h:742
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
constexpr point_t util::quantities::concepts::Point< Q, Cat, IV >::operator- ( ) const
inline

Returns a parity-changed point.

Definition at line 742 of file intervals.h.

742 { return point_t(-quantity()); }
constexpr quantity_t const & quantity() const
Returns the value of the interval as a quantity.
Definition: intervals.h:653
Point< Q, Cat, IV > point_t
This type.
Definition: intervals.h:582
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename R >
point_t& util::quantities::concepts::Point< Q, Cat, IV >::operator-= ( scaled_quantity_t< R > const  other)
inline

Subtract a quantity (possibly converted) from this one.

Definition at line 729 of file intervals.h.

730  { quantity_t::operator-= (other); return *this; }
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OC >
enable_if_compatible_t<Interval<OQ, OC>, point_t&> util::quantities::concepts::Point< Q, Cat, IV >::operator-= ( Interval< OQ, OC > const  other)
inline

Subtract the other interval (possibly converted) from this point.

Definition at line 735 of file intervals.h.

736  { return operator-= (other.quantity()); }
point_t & operator-=(scaled_quantity_t< R > const other)
Subtract a quantity (possibly converted) from this one.
Definition: intervals.h:729
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator< ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 794 of file intervals.h.

795  { return quantity_t::operator<(other.quantity()); }
constexpr bool operator<(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:889
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator<= ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 789 of file intervals.h.

790  { return quantity_t::operator<=(other.quantity()); }
constexpr bool operator<=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:879
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator== ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 769 of file intervals.h.

770  { return quantity_t::operator==(other.quantity()); }
constexpr bool operator==(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:859
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator> ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 784 of file intervals.h.

785  { return quantity_t::operator>(other.quantity()); }
constexpr bool operator>(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:909
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
template<typename OQ , typename OI >
constexpr enable_if_compatible_t<other_point_t<OQ, OI>, bool> util::quantities::concepts::Point< Q, Cat, IV >::operator>= ( other_point_t< OQ, OI > const  other) const
inline

Definition at line 779 of file intervals.h.

780  { return quantity_t::operator>=(other.quantity()); }
constexpr bool operator>=(Quantity< Args... > const a, Point< Q, Cat, IV > const b) noexcept
Definition: intervals.h:899
template<typename Q, typename Cat = NoCategory, typename IV = Interval<Q, Cat>>
constexpr quantity_t const& util::quantities::concepts::Point< Q, Cat, IV >::quantity ( ) const
inline

Returns the value of the interval as a quantity.

Definition at line 653 of file intervals.h.

653 { return *this; }

The documentation for this struct was generated from the following file: