|
5 | 5 | }, |
6 | 6 | "algorithms": [ |
7 | 7 | { |
8 | | - "name": "superellipse-exponent-to-interpolation-value", |
9 | | - "html": "To interpolate a <a class=\"production css\" data-link-type=\"type\" href=\"https://drafts.csswg.org/css-values-4/#number-value\" id=\"ref-for-number-value②\"><number [0,∞]></a> <var>exponent</var> to an interpolation value between 0 and 1:", |
10 | | - "rationale": ".algorithm", |
| 8 | + "name": "superellipse-param-to-interpolation-value", |
| 9 | + "html": "To interpolate a <a class=\"production css\" data-link-type=\"type\" href=\"https://drafts.csswg.org/css-values-4/#number-value\" id=\"ref-for-number-value②\"><number [-∞,∞]></a> <var>s</var> to an interpolation value between 0 and 1, return the first matching statement, switch on <var>s</var>:", |
| 10 | + "rationale": ".switch", |
11 | 11 | "steps": [ |
12 | 12 | { |
13 | | - "html": "<p>If <var>exponent</var> is 0, return 0.</p>" |
14 | | - }, |
15 | | - { |
16 | | - "html": "<p>If <var>exponent</var> is ∞, return 1.</p>" |
17 | | - }, |
18 | | - { |
19 | | - "html": "<p>Return <code>1/(2^(1/<var>exponent</var>))</code>.</p>" |
| 13 | + "operation": "switch", |
| 14 | + "steps": [ |
| 15 | + { |
| 16 | + "case": "-∞", |
| 17 | + "html": "<p>Return 0.</p>" |
| 18 | + }, |
| 19 | + { |
| 20 | + "case": "∞", |
| 21 | + "html": "<p>Return 1.</p>" |
| 22 | + }, |
| 23 | + { |
| 24 | + "case": "Otherwise", |
| 25 | + "html": "", |
| 26 | + "rationale": "let", |
| 27 | + "steps": [ |
| 28 | + { |
| 29 | + "html": "<p>Let <var>k</var> be <code>0.5<sup>abs(<var>s</var>)</sup></code>.</p>" |
| 30 | + }, |
| 31 | + { |
| 32 | + "html": "<p>Let <var>convexHalfCorner</var> be <code>0.5<sup><var>k</var></sup></code>.</p>" |
| 33 | + }, |
| 34 | + { |
| 35 | + "html": "<p>If <var>param</var> is less than 0, return <code>1 - <var>convexHalfCorner</var></code>.</p>" |
| 36 | + }, |
| 37 | + { |
| 38 | + "html": "<p>Return <var>convexHalfCorner</var>.</p>" |
| 39 | + } |
| 40 | + ] |
| 41 | + } |
| 42 | + ] |
20 | 43 | } |
21 | 44 | ] |
22 | 45 | }, |
23 | 46 | { |
24 | | - "name": "superellipse-exponent-to-interpolation-value", |
25 | | - "html": "To convert a <a class=\"production css\" data-link-type=\"type\" href=\"https://drafts.csswg.org/css-values-4/#number-value\" id=\"ref-for-number-value③\"><number [0,1]></a> <var>interpolationValue</var> back to a <a data-link-type=\"dfn\" href=\"https://drafts.csswg.org/css-borders-4/#superellipse-exponent\" id=\"ref-for-superellipse-exponent⑤\">superellipse exponent</a>:", |
26 | | - "rationale": "if", |
| 47 | + "name": "superellipse-param-to-interpolation-value", |
| 48 | + "html": "To convert a <a class=\"production css\" data-link-type=\"type\" href=\"https://drafts.csswg.org/css-values-4/#number-value\" id=\"ref-for-number-value③\"><number [0,1]></a> <var>interpolationValue</var> back to a <a data-link-type=\"dfn\" href=\"https://drafts.csswg.org/css-borders-4/#superellipse-parameter\" id=\"ref-for-superellipse-parameter⑥\">superellipse parameter</a>, switch on <var>interpolationValue</var>:", |
| 49 | + "rationale": ".switch", |
27 | 50 | "steps": [ |
28 | 51 | { |
29 | | - "html": "<p>If <var>interpolationValue</var> is 0, return 0.</p>" |
30 | | - }, |
31 | | - { |
32 | | - "html": "<p>If <var>interpolationValue</var> is 1, return ∞.</p>" |
33 | | - }, |
34 | | - { |
35 | | - "html": "<p>Return <code>ln(0.5)/ln(<var>interpolationValue</var>)</code>.</p>" |
| 52 | + "operation": "switch", |
| 53 | + "steps": [ |
| 54 | + { |
| 55 | + "case": "0", |
| 56 | + "html": "<p>Return -∞.</p>" |
| 57 | + }, |
| 58 | + { |
| 59 | + "case": "0.5", |
| 60 | + "html": "<p>Return 0.</p>" |
| 61 | + }, |
| 62 | + { |
| 63 | + "case": "1", |
| 64 | + "html": "<p>Return ∞.</p>" |
| 65 | + }, |
| 66 | + { |
| 67 | + "case": "Otherwise", |
| 68 | + "html": "", |
| 69 | + "rationale": "let", |
| 70 | + "steps": [ |
| 71 | + { |
| 72 | + "html": "<p>Let <var>convexHalfCorner</var> be <var>interpolationValue</var>.</p>" |
| 73 | + }, |
| 74 | + { |
| 75 | + "html": "<p>If <var>interpolationValue</var> is less than 0.5, set <var>convexHalfCorner</var> to 1 - <var>interpolationValue</var>.</p>" |
| 76 | + }, |
| 77 | + { |
| 78 | + "html": "<p>Let <var>k</var> be <code>ln(0.5) / ln(<var>convexHalfCorner</var>)</code>.</p>" |
| 79 | + }, |
| 80 | + { |
| 81 | + "html": "<p>Let <var>s</var> be <code>log2(<var>k</var>)</code>.</p>" |
| 82 | + }, |
| 83 | + { |
| 84 | + "html": "<p>If <var>interpolationValue</var> is less than 0.5, return -<var>s</var>.</p>" |
| 85 | + }, |
| 86 | + { |
| 87 | + "html": "<p>Return <var>s</var>.</p>" |
| 88 | + } |
| 89 | + ] |
| 90 | + } |
| 91 | + ] |
36 | 92 | } |
37 | 93 | ] |
38 | 94 | } |
|
0 commit comments