Skip to content

Commit 00fa5d5

Browse files
authored
Fix spline interpolators outside [0, 1] range (#141)
* Fix spline interpolators outside [0, 1] range * Add illustratotions for all splines in docs
1 parent d75f9bf commit 00fa5d5

21 files changed

+555
-233
lines changed

docs/api.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,79 @@ culori.samples(5).map(culori.easingGamma(2));
493493

494494
### Interpolation methods
495495

496+
<div class='api-figure-grid'>
497+
<figure>
498+
<img src='/img/interpolator-linear.svg' width='400' height='80'/>
499+
<figcaption>
500+
<a href='#interpolatorLinear'>
501+
<code>culori.<strong>interpolatorLinear</strong></code>
502+
</a>
503+
</figcaption>
504+
</figure>
505+
<figure>
506+
<img src='/img/interpolator-basis.svg' width='400' height='80'/>
507+
<figcaption>
508+
<a href='#interpolatorSplineBasis'>
509+
<code>culori.<strong>interpolatorSplineBasis</strong></code>
510+
</a>
511+
</figcaption>
512+
</figure>
513+
<figure>
514+
<img src='/img/interpolator-basis-closed.svg' width='400' height='80'/>
515+
<figcaption>
516+
<a href='#interpolatorSplineBasisClosed'>
517+
<code>culori.<strong>interpolatorSplineBasisClosed</strong></code>
518+
</a>
519+
</figcaption>
520+
</figure>
521+
<figure>
522+
<img src='/img/interpolator-natural.svg' width='400' height='80'/>
523+
<figcaption>
524+
<a href='#interpolatorSplineNatural'>
525+
<code>culori.<strong>interpolatorSplineNatural</strong></code>
526+
</a>
527+
</figcaption>
528+
</figure>
529+
<figure>
530+
<img src='/img/interpolator-natural-closed.svg' width='400' height='80'/>
531+
<figcaption>
532+
<a href='#interpolatorSplineNaturalClosed'>
533+
<code>culori.<strong>interpolatorSplineNaturalClosed</strong></code>
534+
</a>
535+
</figcaption>
536+
</figure>
537+
<figure>
538+
<img src='/img/interpolator-monotone.svg' width='400' height='80'/>
539+
<figcaption>
540+
<a href='#interpolatorSplineMonotone'>
541+
<code>culori.<strong>interpolatorSplineMonotone</strong></code>
542+
</a>
543+
</figcaption>
544+
</figure>
545+
<figure>
546+
<img src='/img/interpolator-monotone-2.svg' width='400' height='80'/>
547+
<figcaption>
548+
<a href='#interpolatorSplineMonotone2'>
549+
<code>culori.<strong>interpolatorSplineMonotone2</strong></code>
550+
</a>
551+
</figcaption>
552+
</figure>
553+
<figure>
554+
<img src='/img/interpolator-monotone-closed.svg' width='400' height='80'/>
555+
<figcaption>
556+
<a href='#interpolatorSplineMonotoneClosed'>
557+
<code>culori.<strong>interpolatorSplineMonotoneClosed</strong></code>
558+
</a>
559+
</figcaption>
560+
</figure>
561+
</div>
562+
496563
You'll use these methods when you want to override how colors get interpolated in a specific color space, or when defining the default interpolation for custom color spaces.
497564

498565
<a id="interpolatorLinear" href="#interpolatorLinear">#</a> culori.**interpolatorLinear**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/linear.js)
499566

567+
<img src='/img/interpolator-linear.svg' width='400' height='80'/>
568+
500569
A linear interpolator for values in a channel.
501570

502571
#### Basis splines
@@ -505,10 +574,14 @@ A linear interpolator for values in a channel.
505574

506575
<a id="interpolatorSplineBasis" href="#interpolatorSplineBasis">#</a> culori.**interpolatorSplineBasis**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineBasis.js)
507576

577+
<img src='/img/interpolator-basis.svg' width='400' height='80'/>
578+
508579
A basis spline which uses one-sided finite differences for the slopes at the boundaries.
509580

510581
<a id="interpolatorSplineBasisClosed" href="#interpolatorSplineBasisClosed">#</a> culori.**interpolatorSplineBasisClosed**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineBasis.js)
511582

583+
<img src='/img/interpolator-basis-closed.svg' width='400' height='80'/>
584+
512585
A basis spline which considers the _values_ array to be periodic.
513586

514587
#### Natural splines
@@ -517,10 +590,14 @@ A basis spline which considers the _values_ array to be periodic.
517590

518591
<a id="interpolatorSplineNatural" href="#interpolatorSplineNatural">#</a> culori.**interpolatorSplineNatural**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineNatural.js)
519592

593+
<img src='/img/interpolator-natural.svg' width='400' height='80'/>
594+
520595
A natural spline which uses one-sided finite differences for the slopes at the boundaries.
521596

522597
<a id="interpolatorSplineNaturalClosed" href="#interpolatorSplineNaturalClosed">#</a> culori.**interpolatorSplineNaturalClosed**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineNatural.js)
523598

599+
<img src='/img/interpolator-natural-closed.svg' width='400' height='80'/>
600+
524601
A natural spline which considers the _values_ array to be periodic.
525602

526603
#### Monotone splines
@@ -533,14 +610,20 @@ The following variants are available:
533610

534611
<a id="interpolatorSplineMonotone" href="#interpolatorSplineMonotone">#</a> culori.**interpolatorSplineMonotone**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineMonotone.js)
535612

613+
<img src='/img/interpolator-monotone.svg' width='400' height='80'/>
614+
536615
A monotone spline that uses one-sided finite differences to find the slopes at the boundaries.
537616

538617
<a id="interpolatorSplineMonotone2" href="#interpolatorSplineMonotone2">#</a> culori.**interpolatorSplineMonotone2**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineMonotone.js)
539618

619+
<img src='/img/interpolator-monotone-2.svg' width='400' height='80'/>
620+
540621
A monotone spline for which we derive the slopes at the boundaries by tracing a parabola through the first/last three values.
541622

542623
<a id="interpolatorSplineMonotoneClosed" href="#interpolatorSplineMonotoneClosed">#</a> culori.**interpolatorSplineMonotoneClosed**(_values_) &middot; [Source](https://github.com/evercoder/culori/blob/main/src/interpolate/splineMonotone.js)
543624

625+
<img src='/img/interpolator-monotone-closed.svg' width='400' height='80'/>
626+
544627
A monotone spline which considers the _values_ array to be periodic.
545628

546629
#### Custom piecewise interpolation

docs/css/main.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,19 @@ pre[class*='language-'] {
244244
.token.boolean {
245245
color: var(--red);
246246
}
247+
248+
.api-figure-grid {
249+
font-size: 0.9em;
250+
display: grid;
251+
grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
252+
grid-gap: 2em 1em;
253+
}
254+
255+
.api-figure-grid figure {
256+
padding: 0;
257+
margin: 0;
258+
}
259+
260+
.api-figure-grid figure img {
261+
border: 1px solid #ccc;
262+
}
Lines changed: 1 addition & 0 deletions
Loading

docs/img/interpolator-basis.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/img/interpolator-linear.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

docs/img/interpolator-monotone.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)