Skip to content

Commit 4e88f2c

Browse files
committed
[css-color-5] Hue interpolation fixes, per @dbaron’s suggestion
1 parent 841202e commit 4e88f2c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

css-color-5/Overview.bs

+10-7
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,14 @@ Hue interpolation {#hue-interpolation}
727727
-------------------
728728

729729
For color functions with a hue angle (LCH, HSL, HWB etc), there are multiple ways to interpolate.
730-
We typically want to avoid arcs over 360, as they are rarely desirable,
730+
We typically want to avoid arcs over 360 for the difference between the angles, as they are rarely desirable,
731731
so in most cases angles are fixed up prior to interpolation so that per-component interpolation is done over less than 360 degrees, often less than 180.
732+
732733
Host syntax can specify any of the following algorithms for hue interpolation
733-
(angles in the following are in degrees, but the logic is the same regardless of how they are specified):
734+
(angles in the following are in degrees, but the logic is the same regardless of how they are specified).
735+
736+
Unless the type of hue interpolation is ''specified'', both angles need to be constrained to [0, 360) prior to interpolation.
737+
One way to do this is <code><i>θ</i> = ((<i>θ</i> % 360) + 360) % 360</code>.
734738

735739
: ''shorter''
736740
:: Angles are adjusted so that θ₂ - θ₁ ∈ [0, 180). In pseudo-Javascript:
@@ -746,11 +750,11 @@ Host syntax can specify any of the following algorithms for hue interpolation
746750
: ''longer''
747751
:: Angles are adjusted so that θ₂ - θ₁ ∈ [180, 360). In pseudo-Javascript:
748752
<pre>
749-
if (θ₂ - θ₁ <= 180) {
750-
θ₂ += 360;
753+
if (0 < θ₂ - θ₁ < 180) {
754+
θ₁ += 360;
751755
}
752-
else if (θ₂ - θ₁ >= -180) {
753-
θ₁ += 360;
756+
else if (-180 < θ₂ - θ₁ < 0) {
757+
θ₂ += 360;
754758
}
755759
</pre>
756760

@@ -775,7 +779,6 @@ Host syntax can specify any of the following algorithms for hue interpolation
775779

776780
Unless otherwise specified, if no specific hue interpolation algorithm is selected by the host syntax, the default is ''shorter''.
777781

778-
779782
Security and Privacy Considerations {#SecPriv}
780783
===================================
781784

0 commit comments

Comments
 (0)