operator * method
Returns the product of this Dimensions object and other Dimensions.
Dimension multiplication (as occurs when two physical quantities are multiplied) is accomplished by adding component exponents. For example, a time (time +1) multiplied by a frequency (time -1) yields a scalar (1 + (-1) = 0).
Implementation
Dimensions operator *(Dimensions other) {
// Return self if other is Scalar.
if (other._dimensionMap.isNotEmpty != true) return this;
// Copy. Clear the type hint.
final result = Dimensions.copy(this, includeTypeHint: false);
// Add other's dimensions to my dimensions.
num otherValue = 0;
num myValue = 0;
num newValue = 0;
for (final key in other._dimensionMap.keys) {
otherValue = other._dimensionMap[key] as num;
myValue =
_dimensionMap.containsKey(key) ? result._dimensionMap[key] as num : 0;
newValue = otherValue + myValue;
if (newValue != 0.0) {
result._dimensionMap[key] = newValue;
} else {
result._dimensionMap.remove(key); // remove 0's
}
}
return result;
}