facelessuser / coloraide

A library to aid in using colors
https://facelessuser.github.io/coloraide
MIT License
187 stars 11 forks source link

Bezier Interpolation and hue fix-ups #217

Closed facelessuser closed 2 years ago

facelessuser commented 2 years ago

Currently, linear piecewise interpolation uses hue fix-ups as described by the CSS spec. The way this works is the interpolation between two stops applies a fixup on those two hues. A single hue that is both the start and end hue of two different segments can evaluate differently on both segments. Since the impact of this is contained only to the segment on which it applies, this works well for linear piecewise interpolation.

For Bezier, a single hue that is both the start on one segment and the end of another cannot evaluate differently for each segment as Bezier evaluates all the hues together. For this reason, we just normalize hues and call it a day. But thinking about this more, we can at least honor specified. I'm not sure how we could apply shorter, longer, increasing and decreasing, but specified simply requires us to not normalize the hues.

facelessuser commented 2 years ago

It may actually be possible to support all of them.

facelessuser commented 2 years ago

The key is to slightly alter what CSS is doing for the hue fixup algorithms. We can actually make this generalized for both piecewise and bezier.

Basically, any time we want to alter h1 in the algorithm, we can just do the opposite on h2. That means we can adjust all in the chain without backtracking. But that isn't enough either, we also need to then adjust all other hues and offset them by the same to keep them relative to the previously altered hue. What ends up happening is that we get the same results, but the value may be off by 360 of what they were before, but the values are equivalent.

In the end, it's a way that we can handle all the hue fixups in a purely generalized way. This will allow us to process all the colors generalized, and once processed, hand them off to an interpolater. This will get rid of redundant code and allow us to expose interpolators as a plugin (either now or later).

facelessuser commented 2 years ago

This was a necessity to get fixed as it left a disparity between the two interpolation methods. This will be fixed in the next release, whether that is RC2 or the final 1.0.