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

AtkinsSJ has just created a new issue for https://github.com/w3c/css-houdini-drafts:

== [css-typed-om] "Add two types" algorithm seems overly complicated? ==
Hi, I'm just starting to implement `CSSNumericValue` and this algorithm seems to be described in a way that is a lot more complicated and verbose than it needs to be.

Step 3 of "[add two types](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-add-two-types)" (which currently is displaying incorrectly as step 6) says:

> **If all the [entries](https://infra.spec.whatwg.org/#map-entry) of type1 with non-zero values are [contained](https://infra.spec.whatwg.org/#map-exists) in type2 with the same value, and vice-versa**
>    Copy all of type1’s [entries](https://infra.spec.whatwg.org/#map-entry) to finalType, and then copy all of type2’s [entries](https://infra.spec.whatwg.org/#map-entry) to finalType that finalType doesn’t already [contain](https://infra.spec.whatwg.org/#map-exists). Set finalType’s [percent hint](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-percent-hint) to type1’s [percent hint](https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-percent-hint). Return finalType.

I'm struggling a bit to understand this. The "if" sounds like it checks all the "BaseType -> exponent" values are the same in type1 and type2. But if that's the case, then we don't need to copy values from both type1 and type2 into finalType, because there can't be anything in type2 that isn't in type1. In fact, finalType just becomes a copy of type1 (which is already a copy of the original in step 1) so we could return type1 directly.

So it should be equivalent to:

> **If all the [entries](https://infra.spec.whatwg.org/#map-entry) of type1 with non-zero values are [contained](https://infra.spec.whatwg.org/#map-exists) in type2 with the same value, and vice-versa**
>    Return type1.

Later in that same step, we do the same "compare type1 and type2 and then copy and return" procedure, which could likewise be "Return type1". Then, we're no longer using finalType at all, and can remove it from step 1.

There may be nuances here that I'm missing, so do correct me if I'm wrong! (It wouldn't be the first time. :sweat_smile:)

Please view or discuss this issue at https://github.com/w3c/css-houdini-drafts/issues/1097 using your GitHub account


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

Received on Monday, 19 June 2023 20:30:07 UTC