convert method

num convert(
  1. num value,
  2. Unit<T> from,
  3. Unit<T> to
)

Implementation

num convert(num value, Unit<T> from, Unit<T> to) {
  num result = value;

  List<ConversionNode<T>> rootFromUnitPath = [];
  List<ConversionNode<T>> rootToUnitPath = [];

  if (_hasPath(tree.data, from, rootFromUnitPath) &&
      _hasPath(tree.data, to, rootToUnitPath)) {
    _trimToLowestCommonAncestor(rootFromUnitPath, rootToUnitPath);
    result = count(result, rootFromUnitPath.reversed.toList());
    result = count(result, rootToUnitPath);
  }

  return result;
}