Skip to content

[css-color-5][css-color-4] Unclear how to use progress in interpolation. #14021

Description

@romainmenke

See:
https://drafts.csswg.org/css-color-5/#color-mix-result

Interpolate a and b’s colors as described in CSS Color 4 §  13. Color Interpolation, with a progress percentage equal to (b’s percentage) / combined percentage), if combined percentage is greater than 0, and 0.5 otherwise. If the specified color space is a cylindrical polar color space, then the <hue-interpolation-method> controls the interpolation of hue, as described in CSS Color 4 § 13.4 Hue Interpolation. If no <hue-interpolation-method> is specified, assume shorter.

When following the link to css-color-4:
https://drafts.csswg.org/css-color-4/#interpolation

However there is no mention of progress in the context of interpolation in the css-color-4 spec.
When updating to the latest spec I got unexpected results and found that my implementation had this interpolation function:

// p is progress
function interpolate(start: number, end: number, p: number): number {
	return (start * p) + end * (1 - p);
}

While I think that the current spec requires this:

// p is progress
function interpolate(start: number, end: number, p: number): number {
	return (start * (1 - p)) + end * p;
}

I vaguely recall that there used to be a link to the images spec with more details on interpolation there?

@svgeesus Might be good to have an explicit definition of the interpolation function and how progress interacts with it.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions