Length constructor
Class for length conversions, e.g. if you want to convert 1 meter in inches:
var length = Length(removeTrailingZeros: false);
length.convert(Unit(LENGTH.meters, value: 1));
print(length.inches);
Implementation
Length({this.significantFigures = 10, this.removeTrailingZeros = true, name}) {
size = LENGTH.values.length;
this.name = name ?? PROPERTY.length;
for (LENGTH val in LENGTH.values) {
unitList.add(Unit(val, symbol: mapSymbols[val]));
}
unitConversion = Node(name: LENGTH.meters, leafNodes: [
Node(coefficientProduct: 0.01, name: LENGTH.centimeters, leafNodes: [
Node(coefficientProduct: 2.54, name: LENGTH.inches, leafNodes: [
Node(
coefficientProduct: 12.0,
name: LENGTH.feet,
),
Node(
coefficientProduct: 1e-3,
name: LENGTH.mils,
),
]),
]),
Node(
coefficientProduct: 1852.0,
name: LENGTH.nauticalMiles,
),
Node(coefficientProduct: 0.9144, name: LENGTH.yards, leafNodes: [
Node(
coefficientProduct: 1760.0,
name: LENGTH.miles,
),
]),
Node(
coefficientProduct: 1e-3,
name: LENGTH.millimeters,
),
Node(
coefficientProduct: 1e-6,
name: LENGTH.micrometers,
),
Node(
coefficientProduct: 1e-9,
name: LENGTH.nanometers,
),
Node(
coefficientProduct: 1e-10,
name: LENGTH.angstroms,
),
Node(
coefficientProduct: 1e-12,
name: LENGTH.picometers,
),
Node(coefficientProduct: 1000.0, name: LENGTH.kilometers, leafNodes: [
Node(coefficientProduct: 149597870.7, name: LENGTH.astronomicalUnits, leafNodes: [
Node(coefficientProduct: 63241.1, name: LENGTH.lightYears, leafNodes: [
Node(
coefficientProduct: 3.26,
name: LENGTH.parsec,
),
]),
]),
]),
]);
}