Re: [css-houdini-drafts] [css-typed-om] "Add two types" algorithm seems overly complicated? (#1097)

> The "if" sounds like it checks all the "BaseType -> exponent" values are the same in type1 and type2. 

The `if` checks that the *non-zero* entries of `type1` and `type2` are identical; the final type contains *all* the entries, including zero-valued entries from either input type.

Zero-valued entries are important to maintain because they indicate that the type is still necessary for the *input* even if it doesn't show up in the output. `calc(20deg * (1px / 1em))` has the type `{angle: 1, length: 0}`, and can't, for example, be represented as a CSSUnitValue (until it's simplified as a computed or used value, at which point it will be just `{angle: 1}`). A few of the methods care about this, like `.to()`.

But it's perfectly valid to *add* a `calc(20deg * (1px / 1em))` to a `calc(30deg)`; they have compatible types for this purpose (they'll both resolve to angles, eventually). The result will again have the type `{angle: 1, length: 0}`, preserving the complexity of the inputs.

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/1097#issuecomment-1599633314 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Tuesday, 20 June 2023 22:02:36 UTC