AffineUnit

An affine unit – the most common case being a unit that is related to other units representing the same physical quantity not by a scale factor, but by a shift in the zero point.

This is not a fundamentally new concept, adding a constant offset could just be implemented in a custom conversion function as well (see the UnitImpl documentation). However, Quantity is specialized on affine units such as to only provide operations which make sense for them:

Informally speaking, an affine space is a vector space which »forgot« its origin, its elements are points, not vectors. Thus, a quantity of an affine unit cannot be added to another (as it makes no sense to add two points), but like vectors can be added to points to yield a new point, a quantity of the underlying base unit can be. Also, two affine quantities can be substracted to yield a quantity of the base unit (just as two points can be substracted to get a vector pointing from one to another).

The most common example for this are units of temperature like degrees Celsius or Fahrenheit, as demonstrated below.

Members

Aliases

Conversions
alias Conversions = AliasSeq!(Conversion!(BaseUnit, toBase, fromBase))
Undocumented in source.
LinearBaseUnit
alias LinearBaseUnit = BaseUnit
Undocumented in source.

Mixins

__anonymous
mixin UnitImpl
Undocumented in source.

Static functions

fromBase
V fromBase(V v)
Undocumented in source. Be warned that the author may not have intended to support it.
toBase
V toBase(V v)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString(UnitString type)
Undocumented in source. Be warned that the author may not have intended to support it.

Mixed In Members

From mixin UnitImpl

opBinary
auto opBinary(Rhs rhs)

Multiplication/division of two unit instances, yielding a unit instance representing the product/quotient unit.

opBinary
auto opBinary(V rhs)
opBinaryRight
auto opBinaryRight(V lhs)

Multiplication/division of an unit and a value type, constructing a Quantity instance.

SuperSecretAliasToMarkThisAsUnit
alias SuperSecretAliasToMarkThisAsUnit = void
Undocumented in source.

Examples

enum celsius = affine!(273.15, "degrees Celsius", "°C")(kelvin);
auto t = 3.0 * celsius;
t += 1.0 * kelvin; // adding Kelvin is okay
assert(!__traits(compiles, t += 2.0 * celsius)); // adding Celsius is not
writeln(t - 0.0 * celsius); // 4 Kelvin, not degrees Celsius

Meta