Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolateCubic, interpolateCubicClosed, interpolateMonotone, interpolateMonotoneClosed #87

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Fil
Copy link
Member

@Fil Fil commented Jul 3, 2020

cubic Hermite splines ; will be useful for d3/d3-scale-chromatic#28

The difference with interpolateBasis is that this interpolator returns the exact values at the control points; with n = values.length we have:

  • values[i] = f(i/(n-1)) for interpolateCubic
  • values[i] = f(i/n) for interpolateCubicClosed, with f(1) == f(0)

Code adapted from https://github.com/Evercoder/culori (see Evercoder/culori#91 )

@Fil
Copy link
Member Author

Fil commented Jul 3, 2020

@danburzo if you'd like to review?

@Fil Fil changed the title interpolateCubic, interpolateCubicClosed interpolateCubic, interpolateCubicClosed, interpolateMonotone, interpolateMonotoneClosed Jul 3, 2020
@danburzo
Copy link

danburzo commented Jul 4, 2020

I think I'd like to revisit the boundary conditions (section 2.2 in the Steffen paper). It seems we're duplicating the slopes at either ends by adding the reflection of arr[1] across arr[0] and the reflection of arr[arr.length - 2] across arr[arr.length-1] and that makes intuitive / naive sense to me, but I'm not entirely convinced it matches either the suggestions in the paper or the curve implementation in d3-shape, which (I think) implements equation (24), that is takes the first three values into account rather than just two.

@Fil Fil mentioned this pull request Jul 4, 2020
@Fil
Copy link
Member Author

Fil commented Jul 4, 2020

See also d3/d3-shape#118 #52 #67

@Fil Fil added the feature label Jul 10, 2020
@danburzo
Copy link

danburzo commented Aug 24, 2020

I had a chance to give the cited paper another look. The previous implementation in culori, and by extension, in this PR, is using the one-sided finite differences for boundary points, which is a valid approach outlined in the paper (Section 2.2).

In [email protected], I added another implementation to use equations (24) to (27) instead as culori.interpolatorSplineMonotone2. The effect is different but not necessarily better for color interpolation:

Screenshot 2020-08-25 at 00 18 44

(In the image above, the FD versions refer to 'one-sided finite differences')

In particular, the finite-differences approach (blue stroke in the image below) produces curves that are closer to a linear interpolation; the new implementation (red stroke) tends to squeeze the colors at either end of the interpolation into a narrower portion:

Screenshot 2020-08-25 at 00 16 40

So I'm not 100% convinced the new approach produces better results...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants