Add negate node to calc tree to replace the mul_by in sum nodes
Categories
(Core :: CSS Parsing and Computation, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox114 | --- | fixed |
People
(Reporter: tlouw, Assigned: tlouw)
References
Details
Attachments
(1 file)
Assumption in calc(): x - y == x + (-1y))
This used to work, because multiply and divide was always evaluated at parse time before add and subtract, but the plan is to add a product node so that evaluation happens at "simplify/evaluate" time. Adding the product node avoids us from violating distributivity in newer nodes like sign(). (see bug 1815448)
Example in old code:
// multiply happens at parse time
calc(40px + 10% - 20% / 2) == calc(40px + 10% - 10%)
// multiply now creates a new node
calc(40px + 10% - 20% / 2) == calc(40px + 10% - (20% / 2)) != calc(40px + 10% - 20% / -2)
To fix this we can't *-1 for subtractions any more, so each node in a +/- should keep track of it's own operation. This makes storing the terms in a list very ugly, so the plan is to convert the node into a single operation node. E.g.
Sum(vec<Node>)
changes to:
Sum { left: Node, right: Node, op: AddOrSubtract }
Initially this will cause some additional allocations and deeper stack, but we should be able to inline some operations if they have the same unit/type, etc.
| Assignee | ||
Updated•3 years ago
|
| Assignee | ||
Comment 1•3 years ago
|
||
Original plan to create binary sum nodes is not needed as adding negate nodes as suggested by the spec works as well.
| Assignee | ||
Comment 2•3 years ago
|
||
Sum nodes would use mul_by to negate nodes to do subtraction, but some
nodes are not distributive. This patch adds a negate node, so that the
operations inside these negate nodes can be resolved first and then the
"subtraction" can be applied.
Updated•3 years ago
|
Comment 4•3 years ago
|
||
| bugherder | ||
Description
•