Implementation
@override
Quantity get quantity {
var unit = standardUnit;
if (unit is ProductUnit) unit = unit._simplifyDeep();
if (unit == this) {
if (_elements.isEmpty) return Quantities.dimensionless;
// Find the quantity that has this unit as definition
var q = Quantities.values.where(
(q) =>
(q.siUnit is UnitForQuantity
? (q.siUnit as UnitForQuantity).parent
: q.siUnit) ==
unit,
);
if (q.length == 1) return q.first;
// Find the quantity that has the same base unit
var b = baseUnit;
q = Quantities.values.where((q) => q.siUnit.baseUnit == b);
if (q.isEmpty) throw StateError('No quantity found for $b');
if (q.length > 1) {
throw StateError('Multiple quantities found for $b: $q');
}
return q.first;
}
return unit.quantity;
}