aurora-opensource/au

Try reducing new units when incorporating into common units

Closed this issue · 1 comments

See this example:

int main(int, char**) {
    std::cout << "1) " << (1 * cm + 1 * mi + 1 * m) << std::endl;
    std::cout << "2) " << (1 * cm + 1 * m + 1 * mi) << std::endl;
}

Output:

1) 805177 COM[m, cm, mi]
2) 805177 COM[cm, mi]

In (2), the first addition does not create a common unit, because cm divides m. In (1), by contrast, we start with COM[cm, mi], and then incorporate m. It would be nice if we could check m against each of cm and mi in turn, and simply avoid adding it if it's already taken care of.

We could go even further, and produce COM[cm, mi] when adding COM[m, mi] and cm, effectively replacing m with cm.

Ideas for test cases:

  • Include km + mi + mm --- the first addition creates a common unit, but the second one should "wipe it out" (because mm is the new common unit).
  • Phrase each test in terms of "order independence of the resulting unit type" --- that's what we're really after.