Skip to content

Commit f3f00b2

Browse files
committed
[css-values-4] Make hypot() take 1+ arguments, to match JS behavior. Fixes #3765.
1 parent 3ed7e84 commit f3f00b2

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

css-values-4/Overview.bs

+49-7
Original file line numberDiff line numberDiff line change
@@ -2574,11 +2574,11 @@ Exponential Functions: ''pow()'', ''sqrt()'', ''hypot()''</h3>
25742574
''sqrt()'' is a common enough function
25752575
that it is provided as a convenience.)
25762576

2577-
The <dfn lt="hypot()">hypot(A,B)</dfn> function
2578-
contains two comma-separated [=calculations=] A and B,
2579-
and returns the length of the hypotenuse of a right-angled triangle
2580-
with legs equal to A and B.
2581-
A and B can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
2577+
The <dfn lt="hypot()">hypot(A,)</dfn> function
2578+
contains one or more comma-separated [=calculations=],
2579+
and returns the length of an N-dimensional vector
2580+
with components equal to each of the [=calculations=].
2581+
The argument [=calculations=] can resolve to any <<number>>, <<dimension>>, or <<percentage>>,
25822582
but must have the <em>same</em> [=determine the type of a calculation|type=],
25832583
or else the function is invalid;
25842584
the result will have the same [=CSSNumericValue/type=] as the arguments.
@@ -2661,6 +2661,48 @@ Exponential Functions: ''pow()'', ''sqrt()'', ''hypot()''</h3>
26612661
Thus it's fine to let author use dimensions directly in ''hypot()''.
26622662
</details>
26632663

2664+
<div class=example>
2665+
The ''pow()'' function can be useful for strategies like <a href="https://www.modularscale.com/">CSS Modular Scale</a>,
2666+
which relates all the font-sizes on a page to each other by a fixed ratio.
2667+
2668+
These sizes can be easily written into custom properties like:
2669+
2670+
<pre class=lang-css>
2671+
:root {
2672+
--h6: calc(1rem * pow(1.5, -1);
2673+
--h5: 1rem;
2674+
--h4: calc(1rem * pow(1.5, 2);
2675+
--h3: calc(1rem * pow(1.5, 3);
2676+
--h2: calc(1rem * pow(1.5, 4);
2677+
--h1: calc(1rem * pow(1.5, 5);
2678+
}
2679+
</pre>
2680+
2681+
...rather than writing out the values in pre-calculated numbers like ''7.6rem''
2682+
(what ''calc(1rem * pow(1.5, 5))'' resolves to)
2683+
which have less clear provenance when encountered in a stylesheet.
2684+
</div>
2685+
2686+
<div class=example>
2687+
With a single argument,
2688+
''hypot()'' gives the absolute value of its input;
2689+
''hypot(2em)'' and ''hypot(-2em)'' both resolve to ''2em''.
2690+
2691+
With more arguments,
2692+
it gives the size of the main diagonal of a box
2693+
whose side lengths are given by the arguments.
2694+
This can be useful for transform-related things,
2695+
giving the distance that an element will actually travel
2696+
when it's translated by a particular X, Y, and Z amount.
2697+
2698+
For example, ''hypot(30px, 40px)'' resolves to ''50px'',
2699+
which is indeed the distance between an element's starting and ending positions
2700+
when it's translated by a ''translate(30px, 40px)'' transform.
2701+
If an author wanted elements to get smaller as they moved further away from their starting point
2702+
(drawing some sort of word cloud, for example),
2703+
they could then use this distance in their scaling factor calculations.
2704+
</div>
2705+
26642706
<h4 id="exponent-infinities">
26652707
Argument Ranges</h4>
26662708

@@ -2699,8 +2741,8 @@ Argument Ranges</h4>
26992741
If A is less than 0,
27002742
the result is NaN.
27012743

2702-
In ''hypot(A, B)'',
2703-
if either or both values are infinite,
2744+
In ''hypot(A, )'',
2745+
if any of the inputs are infinite,
27042746
the result is +∞.
27052747

27062748
(See [[#calc-type-checking]] for details on how [=math functions=] handle NaN and infinities.)

0 commit comments

Comments
 (0)