dip::PhysicalQuantity struct

Encapsulates a quantity with physical units.

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 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.

Functions

static auto Nanometer() -> dip::PhysicalQuantity constexpr
One nanometer.
static auto Micrometer() -> dip::PhysicalQuantity constexpr
One micrometer.
static auto Millimeter() -> dip::PhysicalQuantity constexpr
One millimeter.
static auto Centimeter() -> dip::PhysicalQuantity constexpr
One centimeter.
static auto Meter() -> dip::PhysicalQuantity constexpr
One meter.
static auto Kilometer() -> dip::PhysicalQuantity constexpr
One kilometer.
static auto Inch() -> dip::PhysicalQuantity constexpr
One inch.
static auto Mile() -> dip::PhysicalQuantity constexpr
One mile.
static auto Millisecond() -> dip::PhysicalQuantity constexpr
One millisecond
static auto Second() -> dip::PhysicalQuantity constexpr
One second
static auto Minute() -> dip::PhysicalQuantity constexpr
One minute
static auto Hour() -> dip::PhysicalQuantity constexpr
One hour
static auto Day() -> dip::PhysicalQuantity constexpr
One day
static auto Radian() -> dip::PhysicalQuantity constexpr
One radian
static auto Degree() -> dip::PhysicalQuantity constexpr
One degree
static auto Pixel() -> dip::PhysicalQuantity constexpr
One pixel
static auto SquarePixel() -> dip::PhysicalQuantity constexpr
One square pixel
static auto CubicPixel() -> dip::PhysicalQuantity constexpr
One cubic pixel
auto Power(dip::sint8 p) const -> dip::PhysicalQuantity
Computes a physical quantity to the power of p.
auto Invert() const -> dip::PhysicalQuantity constexpr
Computes a physical quantity to the power of -1.
auto ApproximatelyEquals(dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const -> bool constexpr
Approximate equality comparison of two physical quantities.
auto NotApproximatelyEquals(dip::PhysicalQuantity const& rhs, dip::dfloat tolerance = 1e-6) const -> bool constexpr
Exact inequality comparison of two physical quantities
auto HasSameDimensions(dip::PhysicalQuantity const& other) const -> bool constexpr
Test to see if the physical quantities can be added together.
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.
auto Normalize() -> dip::PhysicalQuantity& constexpr
Adjusts the SI prefix such that the magnitude of the quantity is readable.
auto RemovePrefix() -> dip::PhysicalQuantity& 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.

Operators

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
Divides two physical quantities.
auto operator/=(dip::dfloat other) -> dip::PhysicalQuantity& constexpr
Scaling of a physical quantity.
auto operator-() const -> dip::PhysicalQuantity constexpr
Unary negation.
auto operator+=(dip::PhysicalQuantity const& other) -> dip::PhysicalQuantity& constexpr
Addition of two physical quantities.
auto operator-=(dip::PhysicalQuantity other) -> dip::PhysicalQuantity& constexpr
Subtraction of two physical quantities.
auto operator==(dip::PhysicalQuantity const& rhs) const -> bool constexpr
Exact equality comparison of two physical quantities.
auto operator!=(dip::PhysicalQuantity const& rhs) const -> bool constexpr
Exact inequality comparison of two physical quantities
auto operator dip::dfloat() const -> dip::dfloat explicit constexpr
Retrieve the magnitude, discarding units.
auto operator bool() const -> bool explicit constexpr
A physical quantity tests true if it is different from 0.

Variables

dip::dfloat magnitude
The magnitude
dip::Units units
The units