PhysicalQuantity struct
Encapsulates a quantity with physical units.
Contents
Multiplying a double by a
dip::Units object yields a PhysicalQuantity object. Numbers and units implicitly
convert to a PhysicalQuantity. It is possible to multiply and divide any physical
quantities, but adding and subtracting is only possible if the units match.
dip::PhysicalQuantity a = 50 * dip::Units( dip::Units::BaseUnits::LENGTH );
Constructors, destructors, assignment and conversion operators
- PhysicalQuantity() defaulted constexpr
- A default-constructed
PhysicalQuantityhas magnitude 0 and is unitless. - PhysicalQuantity(dip::dfloat m, dip::Units const& u = {}) constexpr
- Create an arbitrary physical quantity.
- PhysicalQuantity(dip::Units const& u) constexpr
- Create a unit-valued physical quantity.
Functions
- auto ApproximatelyEquals(dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const -> bool constexpr
- Approximate equality comparison of two physical quantities.
- static auto Centimeter() -> dip::PhysicalQuantity constexpr
- One centimeter.
- static auto CubicPixel() -> dip::PhysicalQuantity constexpr
- One cubic pixel
- static auto Day() -> dip::PhysicalQuantity constexpr
- One day
- static auto Degree() -> dip::PhysicalQuantity constexpr
- One degree
- auto HasSameDimensions(dip::PhysicalQuantity const& other) const -> bool constexpr
- Test to see if the physical quantities can be added together.
- static auto Hour() -> dip::PhysicalQuantity constexpr
- One hour
- static auto Inch() -> dip::PhysicalQuantity constexpr
- One inch.
- auto Invert() const -> dip::PhysicalQuantity constexpr
- Computes a physical quantity to the power of -1.
- auto IsDimensionless() const -> bool constexpr
- Test to see if the physical quantity is dimensionless (has no units).
- auto IsPhysical() const -> bool constexpr
- Test to see if the physical quantity is actually physical. If pixels are used as units, it’s not a physical quantity, and dimensionless quantities are not physical either.
- static auto Kilometer() -> dip::PhysicalQuantity constexpr
- One kilometer.
- static auto Meter() -> dip::PhysicalQuantity constexpr
- One meter.
- static auto Micrometer() -> dip::PhysicalQuantity constexpr
- One micrometer.
- static auto Mile() -> dip::PhysicalQuantity constexpr
- One mile.
- static auto Millimeter() -> dip::PhysicalQuantity constexpr
- One millimeter.
- static auto Millisecond() -> dip::PhysicalQuantity constexpr
- One millisecond
- static auto Minute() -> dip::PhysicalQuantity constexpr
- One minute
- static auto Nanometer() -> dip::PhysicalQuantity constexpr
- One nanometer.
- auto Normalize() -> dip::PhysicalQuantity& constexpr
- Adjusts the SI prefix such that the magnitude of the quantity is readable.
- auto NotApproximatelyEquals(dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const -> bool constexpr
- Exact inequality comparison of two physical quantities
- static auto Pixel() -> dip::PhysicalQuantity constexpr
- One pixel
- auto Power(dip::sint8 p) const -> dip::PhysicalQuantity
- Computes a physical quantity to the power of
p. - static auto Radian() -> dip::PhysicalQuantity constexpr
- One radian
- auto RemovePrefix() -> dip::PhysicalQuantity& constexpr
- Removes the SI prefix, such that the quantity is in base units (i.e. m rather than nm).
- static auto Second() -> dip::PhysicalQuantity constexpr
- One second
- static auto SquarePixel() -> dip::PhysicalQuantity constexpr
- One square pixel
- void swap(dip::PhysicalQuantity& other) noexcept
- Swaps the values of
thisandother.
Operators
- auto operator bool() const -> bool explicit constexpr
- A physical quantity tests true if it is different from 0.
- auto operator dip::dfloat() const -> dip::dfloat explicit constexpr
- Retrieve the magnitude, discarding units.
- auto operator!=(dip::PhysicalQuantity const& rhs) const -> bool constexpr
- Exact inequality comparison of two physical quantities
- auto operator*=(dip::PhysicalQuantity const& other) -> dip::PhysicalQuantity& constexpr
- Multiplies two physical quantities.
- auto operator*=(dip::dfloat other) -> dip::PhysicalQuantity& constexpr
- Scaling of a physical quantity.
- auto operator+=(dip::PhysicalQuantity const& other) -> dip::PhysicalQuantity& constexpr
- Addition of two physical quantities.
- auto operator-() const -> dip::PhysicalQuantity constexpr
- Unary negation.
- auto operator-=(dip::PhysicalQuantity other) -> dip::PhysicalQuantity& constexpr
- Subtraction of two physical quantities.
- auto operator/=(dip::PhysicalQuantity const& other) -> dip::PhysicalQuantity& constexpr
- Divides two physical quantities.
- auto operator/=(dip::dfloat other) -> dip::PhysicalQuantity& constexpr
- Scaling of a physical quantity.
- auto operator==(dip::PhysicalQuantity const& rhs) const -> bool constexpr
- Exact equality comparison of two physical quantities.
Variables
- dip::dfloat magnitude = 0
- The magnitude
- dip::Units units
- The units
Alias documentation
using dip:: PhysicalQuantityArray = dip::DimensionArray
An array to hold physical quantities, such as a pixel’s size.
Function documentation
PhysicalQuantity( ) defaulted constexpr
A default-constructed PhysicalQuantity has magnitude 0 and is unitless.
PhysicalQuantity( dip::dfloat m, dip::Units const& u = {}) constexpr
Create an arbitrary physical quantity.
PhysicalQuantity( dip::Units const& u) constexpr
Create a unit-valued physical quantity.
static dip::PhysicalQuantity Nanometer( ) constexpr
One nanometer.
static dip::PhysicalQuantity Micrometer( ) constexpr
One micrometer.
static dip::PhysicalQuantity Millimeter( ) constexpr
One millimeter.
static dip::PhysicalQuantity Centimeter( ) constexpr
One centimeter.
static dip::PhysicalQuantity Meter( ) constexpr
One meter.
static dip::PhysicalQuantity Kilometer( ) constexpr
One kilometer.
static dip::PhysicalQuantity Inch( ) constexpr
One inch.
static dip::PhysicalQuantity Mile( ) constexpr
One mile.
static dip::PhysicalQuantity Millisecond( ) constexpr
One millisecond
static dip::PhysicalQuantity Second( ) constexpr
One second
static dip::PhysicalQuantity Minute( ) constexpr
One minute
static dip::PhysicalQuantity Hour( ) constexpr
One hour
static dip::PhysicalQuantity Day( ) constexpr
One day
static dip::PhysicalQuantity Radian( ) constexpr
One radian
static dip::PhysicalQuantity Degree( ) constexpr
One degree
static dip::PhysicalQuantity Pixel( ) constexpr
One pixel
static dip::PhysicalQuantity SquarePixel( ) constexpr
One square pixel
static dip::PhysicalQuantity CubicPixel( ) constexpr
One cubic pixel
dip::PhysicalQuantity Power( dip::sint8 p) const
Computes a physical quantity to the power of p.
dip::PhysicalQuantity Invert( ) const constexpr
Computes a physical quantity to the power of -1.
bool ApproximatelyEquals( dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const constexpr
Approximate equality comparison of two physical quantities.
bool NotApproximatelyEquals( dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const constexpr
Exact inequality comparison of two physical quantities
bool HasSameDimensions( dip::PhysicalQuantity const& other) const constexpr
Test to see if the physical quantities can be added together.
bool IsDimensionless( ) const constexpr
Test to see if the physical quantity is dimensionless (has no units).
bool IsPhysical( ) const constexpr
Test to see if the physical quantity is actually physical. If pixels are used as units, it’s not a physical quantity, and dimensionless quantities are not physical either.
dip::PhysicalQuantity& Normalize( ) constexpr
Adjusts the SI prefix such that the magnitude of the quantity is readable.
dip::PhysicalQuantity& RemovePrefix( ) constexpr
Removes the SI prefix, such that the quantity is in base units (i.e. m rather than nm).
void swap( dip::PhysicalQuantity& other) noexcept
Swaps the values of this and other.
dip::PhysicalQuantity& operator*=( dip::PhysicalQuantity const& other) constexpr
Multiplies two physical quantities.
dip::PhysicalQuantity& operator*=( dip::dfloat other) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity& operator/=( dip::PhysicalQuantity const& other) constexpr
Divides two physical quantities.
dip::PhysicalQuantity& operator/=( dip::dfloat other) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity operator-( ) const constexpr
Unary negation.
dip::PhysicalQuantity& operator+=( dip::PhysicalQuantity const& other) constexpr
Addition of two physical quantities.
dip::PhysicalQuantity& operator-=( dip::PhysicalQuantity other) constexpr
Subtraction of two physical quantities.
bool operator==( dip::PhysicalQuantity const& rhs) const constexpr
Exact equality comparison of two physical quantities.
bool operator!=( dip::PhysicalQuantity const& rhs) const constexpr
Exact inequality comparison of two physical quantities
dip::dfloat operator dip::dfloat( ) const explicit constexpr
Retrieve the magnitude, discarding units.
bool operator bool( ) const explicit constexpr
A physical quantity tests true if it is different from 0.
dip::PhysicalQuantity
dip:: operator*(
dip::PhysicalQuantity lhs, dip::PhysicalQuantity const& rhs) constexpr
Multiplies two physical quantities.
dip::PhysicalQuantity
dip:: operator*(
dip::PhysicalQuantity lhs, dip::dfloat rhs) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity
dip:: operator*(
dip::dfloat lhs, dip::PhysicalQuantity rhs) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity
dip:: operator/(
dip::PhysicalQuantity lhs, dip::PhysicalQuantity const& rhs) constexpr
Divides two physical quantities.
dip::PhysicalQuantity
dip:: operator/(
dip::PhysicalQuantity lhs, dip::dfloat rhs) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity
dip:: operator/(
dip::dfloat lhs, dip::PhysicalQuantity rhs) constexpr
Scaling of a physical quantity.
dip::PhysicalQuantity
dip:: operator+(
dip::PhysicalQuantity lhs, dip::PhysicalQuantity const& rhs) constexpr
Addition of two physical quantities.
dip::PhysicalQuantity
dip:: operator-(
dip::PhysicalQuantity lhs, dip::PhysicalQuantity const& rhs) constexpr
Subtraction of two physical quantities.
std::ostream&
dip:: operator<<(
std::ostream& os, dip::PhysicalQuantity const& pq)
Insert physical quantity to an output stream.
dip::PhysicalQuantity
dip:: operator*(
dip::dfloat magnitude, dip::Units const& units) constexpr
Create an arbitrary physical quantity by multiplying a magnitude with units.
dip::PhysicalQuantity
dip:: operator*(
dip::Units const& units, dip::dfloat magnitude) constexpr
Create an arbitrary physical quantity by multiplying a magnitude with units.
Variable documentation
dip::dfloat magnitude = 0
The magnitude
dip::Units units
The units