@@ -3284,11 +3284,16 @@ Internal Representation</h3>
32843284
32853285 The [=internal representation=] of a [=math function=]
32863286 is a <dfn export>calculation tree</dfn> :
3287- a tree of operator nodes,
3288- such as Sum, Product, Min, or Cos,
3289- with plain values
3290- (numeric values, such as numbers, dimensions, and percentages,
3291- and non-math functions that resolve to a numeric type) at the leaves.
3287+ a tree where the branch nodes are <dfn export for="calculation tree">operator nodes</dfn>
3288+ corresponding either to [=math functions=]
3289+ (such as Min, Cos, Sqrt, etc)
3290+ or to operators in a [=calculation=]
3291+ (Sum, Product, Negate, and Invert, the <dfn for="calculation tree">calc-operator nodes</dfn> ),
3292+ and the leaf nodes
3293+ are either numeric values
3294+ (such as numbers, dimensions, and percentages)
3295+ or non-[=math functions=] that resolve to a numeric type.
3296+
32923297 [=Math functions=] are turned into [=calculation trees=]
32933298 depending on the function:
32943299
@@ -3298,7 +3303,7 @@ Internal Representation</h3>
32983303 is the result of [=parsing a calculation=] from its argument.
32993304 : any other [=math function=]
33003305 :: The [=internal representation=]
3301- is an operator node with the same name as the function,
3306+ is an [= operator node=] with the same name as the function,
33023307 whose children are the result of [=parsing a calculation=]
33033308 from each of the function's arguments,
33043309 in the order they appear.
@@ -3308,7 +3313,7 @@ Internal Representation</h3>
33083313 To <dfn export lt="parse a calculation|parsing a calculation">parse a calculation</dfn> ,
33093314 given a [=calculation=] |values|
33103315 represented as a list of [=component values=] ,
3311- and returning a tree of operator nodes :
3316+ and returning a [=calculation tree=] :
33123317
33133318 1. Discard any <<whitespace-token>> s from |values|.
33143319
@@ -3397,14 +3402,11 @@ Simplification</h4>
33973402 expressed in the value's [=canonical unit=] .
33983403 2. Otherwise, return |root|.
33993404
3400- 2. At this point, |root| is an operator node.
3405+ 2. At this point, |root| is an [= operator node=] .
34013406 [=Simplify=] all the children of |root|.
34023407
3403- 3. If |root| is a
3404- Min, Max, Clamp,
3405- Sin, Cos, Tan,
3406- Asin, Acos, Atan, Atan2,
3407- Pow, Sqrt, or Hypot node,
3408+ 3. If |root| is an [=operator node=]
3409+ that's not one of the [=calc-operator nodes=] ,
34083410 and all of its children are numeric values
34093411 with enough information to computed the operation |root| represents,
34103412 return the result of running |root|'s operation
@@ -3584,8 +3586,7 @@ Serialization</h3>
35843586 <div algorithm>
35853587 To <dfn export>serialize a math function</dfn> |fn|:
35863588
3587- 1. If |fn| is a ''calc()'' function,
3588- and the root of the [=calculation tree=] it represents
3589+ 1. If the root of the [=calculation tree=] |fn| represents
35893590 is a numeric value
35903591 (number, percentage, or dimension),
35913592 and the serialization being produced is of a [=computed value=] or later,
@@ -3607,14 +3608,19 @@ Serialization</h3>
36073608 3. Append " / 0)" to |s|,
36083609 and return |s|.
36093610
3610- 3. Let |s| be a [=string=] that initially contains
3611- the |fn|'s name
3612- (such as "calc", "sin", etc)
3611+ 3. If the [=calculation tree’s=] root node is a numeric value,
3612+ or a [=calc-operator node=] ,
3613+ let |s| be a string initially containing "calc(".
3614+
3615+ Otherwise,
3616+ let |s| be a string initially containing the name of the root node,
3617+ lowercased
3618+ (such as "sin" or "max"),
36133619 followed by a "(" (open parenthesis).
36143620
3615- 4. For each comma-separated [=calculation=] argument of |fn| ,
3621+ 4. For each child of the root node ,
36163622 [=serialize the calculation tree=] .
3617- If a result of this starts with a "(" (open parenthesis)
3623+ If a result of this serialization starts with a "(" (open parenthesis)
36183624 and ends with a ")" (close parenthesis),
36193625 remove those characters from the result.
36203626 [=string/Concatenate=] all of the results
0 commit comments