• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    Rust
  • License
    Other
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interpolation made easy.

This crate provides splines, mathematic curves defined piecewise through control keys a.k.a. knots.

Feel free to dig in the online documentation for further information.

Spline interpolation made easy.

This crate exposes splines for which each sections can be interpolated independently of each other – i.e. it’s possible to interpolate with a linear interpolator on one section and then switch to a cubic Hermite interpolator for the next section.

Most of the crate consists of three types:

  • [Key], which represents the control points by which the spline must pass.
  • Interpolation, the type of possible interpolation for each segment.
  • [Spline], a spline from which you can sample points by interpolation.

When adding control points, you add new sections. Two control points define a section – i.e. it’s not possible to define a spline without at least two control points. Every time you add a new control point, a new section is created. Each section is assigned an interpolation mode that is picked from its lower control point.

Quickly create splines

use splines::{Interpolation, Key, Spline};

let start = Key::new(0., 0., Interpolation::Linear);
let end = Key::new(1., 10., Interpolation::default());
let spline = Spline::from_vec(vec![start, end]);

You will notice that we used Interpolation::Linear for the first key. The first key start’s interpolation will be used for the whole segment defined by those two keys. The end’s interpolation won’t be used. You can in theory use any Interpolation you want for the last key. We use the default one because we don’t care.

Interpolate values

The whole purpose of splines is to interpolate discrete values to yield continuous ones. This is usually done with the [Spline::sample] method. This method expects the sampling parameter (often, this will be the time of your simulation) as argument and will yield an interpolated value.

If you try to sample in out-of-bounds sampling parameter, you’ll get no value.

assert_eq!(spline.sample(0.), Some(0.));
assert_eq!(spline.clamped_sample(1.), Some(10.));
assert_eq!(spline.sample(1.1), None);

It’s possible that you want to get a value even if you’re out-of-bounds. This is especially important for simulations / animations. Feel free to use the Spline::clamped_interpolation for that purpose.

assert_eq!(spline.clamped_sample(-0.9), Some(0.)); // clamped to the first key
assert_eq!(spline.clamped_sample(1.1), Some(10.)); // clamped to the last key

Polymorphic sampling types

[Spline] curves are parametered both by the carried value (being interpolated) but also the sampling type. It’s very typical to use f32 or f64 but really, you can in theory use any kind of type; that type must, however, implement a contract defined by a set of traits to implement. See the documentation of this module for further details.

Features and customization

This crate was written with features baked in and hidden behind feature-gates. The idea is that the default configuration (i.e. you just add "splines = …" to your Cargo.toml) will always give you the minimal, core and raw concepts of what splines, keys / knots and interpolation modes are. However, you might want more. Instead of letting other people do the extra work to add implementations for very famous and useful traits – and do it in less efficient way, because they wouldn’t have access to the internals of this crate, it’s possible to enable features in an ad hoc way.

This mechanism is not final and this is currently an experiment to see how people like it or not. It’s especially important to see how it copes with the documentation.

So here’s a list of currently supported features and how to enable them:

  • Serde.
    • This feature implements both the Serialize and Deserialize traits from serde for all types exported by this crate.
    • Enable with the "serde" feature.
  • cgmath implementors.
    • Adds some useful implementations of Interpolate for some cgmath types.
    • Enable with the "cgmath" feature.
  • glam implementors.
    • Adds some useful implementations of Interpolate for some glam types.
    • Enable with the "glam" feature.
  • nalgebra implementors.
    • Adds some useful implementations of Interpolate for some nalgebra types.
    • Enable with the "nalgebra" feature.
  • Standard library / no standard library.
    • It’s possible to compile against the standard library or go on your own without it.
    • Compiling with the standard library is enabled by default.
    • Use default-features = [] in your Cargo.toml to disable.
    • Enable explicitly with the "std" feature.

More Repositories

1

hop.nvim

Neovim motions on speed!
Lua
2,121
star
2

luminance-rs

Type-safe, type-level and stateless Rust graphics framework
Rust
1,073
star
3

mind.nvim

The power of trees at your fingertips.
Lua
704
star
4

this-week-in-neovim-contents

Contents of weekly news delivered by this-week-in-neovim.org.
261
star
5

warmy

Hot-reloading loadable and reloadable resources
Rust
210
star
6

this-week-in-neovim.org

this-week-in-neovim.org official webapp repository
Rust
183
star
7

glsl

GLSL parser for Rust
Rust
180
star
8

spectra

Rust demoscene engine (currently on hold)
Rust
124
star
9

luminance

Type-safe, type-level and stateless Haskell graphics framework
Haskell
110
star
10

shades

Rust EDSL for shading languages
Rust
66
star
11

config

My main configuration files
Lua
65
star
12

cargo-sync-readme

Generate a Markdown section in your README based on your Rust documentation
Rust
55
star
13

toodoux

A task manager based on taskwarrior
Rust
51
star
14

mind

The power of trees at your fingertips
Rust
42
star
15

notisys.nvim

System-wide notifications for Neovim
Lua
40
star
16

do-notation

The Haskell’s do notation brought to Rust
Rust
39
star
17

cheddar

The Cheddar GLSL superset language
Rust
27
star
18

spline-editor

A simple spline editor for the splines crate
Rust
24
star
19

wavefront

Haskell Wavefront OBJ loader library
Haskell
19
star
20

bidule

Very simple and Rust FRP crate
Rust
18
star
21

poesie.nvim

Lua
16
star
22

stack-haddock-upload

A little script to upload documentation to Hackage within a stack-powered project
Shell
14
star
23

learn-luminance

11
star
24

luminance-gl-rs

DEPRECATED luminance-gl has been moved into https://github.com/phaazon/luminance-rs
Rust
11
star
25

celeri-remoulade

The Undead Sceners PC demo for Evoke 2016
Rust
10
star
26

smoothie

Smooth curves via several interpolation modes
Haskell
10
star
27

advent-of-code-2k18

https://adventofcode.com/2018
Rust
9
star
28

phaazon.net

Source code of phaazon.net.
Rust
8
star
29

kak-tree-sitter

tree-sitter meets Kakoune
Rust
8
star
30

try-guard

A guard! macro inspired by the guard Alternative function from Haskell.
Rust
6
star
31

luminance-samples

Luminance samples
Haskell
6
star
32

monad-journal

Pure logger typeclass and monad transformer
Haskell
6
star
33

outline-2017-invitro

Outline 2017 Invitation, by DESiRE and The Undead Sceners (code by @phaazon)
Rust
6
star
34

quaazar

Realtime 3D engine
Haskell
6
star
35

pixels-of-life

A GPU accelerated version of Conway’s Game of Life
Rust
5
star
36

save-z0r

Because those loops are too epic to let them go!
Rust
5
star
37

hsFModEx

FModEx Haskell API. Discontinued.
Haskell
4
star
38

hid

Haskell interface to hidapi
Haskell
4
star
39

any-cache

Cache with any key and any associated value
Rust
4
star
40

zero

Semigroups with absorbing element
Haskell
4
star
41

lightning-road-to-liquid-radiator

Official source code of Lightning Road To Liquid Radiator
C++
4
star
42

lqducul

Rust
4
star
43

cheddar-edit

A shader-toy-like project that aims to shader rapid prototyping
Rust
4
star
44

msi-kb-backlit

A command line tool to change backlit colors of your MSI keyboard
Haskell
3
star
45

reactant

FRP Haskell library
Haskell
3
star
46

non-empty

Efficient non-empty vectors in Rust
Rust
3
star
47

al

Haskell OpenAL raw binding
Haskell
3
star
48

glsl-quasiquote

The glsl! procedural macro for the glsl crate.
3
star
49

awoo

Rust
3
star
50

html-entities

Rust html entities utility functions
Rust
2
star
51

brainfarts

Pets de cerveaux.
2
star
52

kwak

The (in)famous bot you all love on IRC! (see her in action in #demofr@freenode)
Rust
2
star
53

luminance-windowing

Common windowing code for luminance (not an actual backend)
2
star
54

event

Monoidal, monadic and first-class events.
Haskell
2
star
55

par-soeur

Run away, nothing to see here!
Rust
2
star
56

advent-of-code-2021

https://adventofcode.com/
Rust
2
star
57

luminance-glutin

glutin support for luminance
Rust
2
star
58

proc-macro-faithful-display

A more faithful Display for proc-macro token types.
Rust
2
star
59

thunk

Some research project of mine about sharing thunks in Rust
Rust
2
star
60

tellbot

IRC bot with account simple tasks and tells function
Haskell
2
star
61

inject-function

Haskell package that lets you write regular functions with the extra feature to be able to inject parameters that can be shared over function composition
Haskell
2
star
62

leaf

A simple portfolio generator
Haskell
2
star
63

rust-gl-toy

As I’m learning rust, let’s play with OpenGL and GLFW here ;)
Rust
1
star
64

igl

Indexed OpenGL; a safer OpenGL implementation
Haskell
1
star
65

algo

Some famous algorithms, written with fun
Rust
1
star
66

conal_frp

An experiment at implementing FRP as described by its father, Conal Elliott. Paper here http://conal.net/papers/push-pull-frp/push-pull-frp.pdf
Haskell
1
star
67

heat-station

Official source code of Heat Station
C++
1
star
68

chronos

Simple FRP timeline. Designed to be used for demoscene purposes
Haskell
1
star
69

luminance-glfw

GLFW support for luminance
1
star
70

skp

skp D framework
D
1
star
71

advent-of-code-2020

Haskell
1
star
72

gltf

Haskell GLTF loader
Haskell
1
star
73

aur

All packages I maintain in AUR
Shell
1
star
74

codingame-unleash-the-geek

My contribution to Unleash The Geek (started on 7th of October 2019)
Rust
1
star
75

meta

Demoscene framework
Perl
1
star
76

fractalis

A Mandelbrot fractal viewer
C
1
star
77

leetify

Leetify some text!
Haskell
1
star
78

agui

Abstract GUI
Haskell
1
star
79

impersonate

An experimental Markov chain generator that learns how to speak as if it was someone else.
Rust
1
star
80

sdffont

A tool that generates signed distance fields fontmap from font file (.ttf, and so on).
Haskell
1
star
81

hush

Demoscene soft synthesizer designed to be embedded in intros.
Rust
1
star
82

iutbx1-ds

IUT Bordeaux 1 Dimitri Sabadie official repository
C++
1
star
83

atoi-data-dependency

A short and fun study of data dependency and compiler optimizations
Rust
1
star
84

rcpp

A Rust implementation of the C Preprocessor
Rust
1
star
85

colorscheme-gen

A little tool to generate color scheme for urxvt session and using the Text Export option of the colorscheme web site.
Shell
1
star
86

phraskell

Fractal set viewer.
Haskell
1
star
87

blog

phaazon.net blog articles
1
star
88

advent-of-code-2022

Advent of Code 2022 solutions
Rust
1
star