splines/lerp

Generalized linear interpolation

Some splines use linear-interpolation (“lerp”) in their calculations when sampling points from their curves. This module generalizes lerp into multiple dimensions and provides example lerp functions for 1D, 2D, and 3D domains.

Types

The type of a function that can linearly-interpolate over a domain a.

pub type Interpolator(a) =
  fn(a, a, Float) -> a

Values

pub fn lerp1(i: Float, j: Float, t: Float) -> Float

Interpolates in one-dimension over floats. You can use this function instead of lerper when the generic type is Float.

pub fn lerp2(
  i: vec2.Vec2(Float),
  j: vec2.Vec2(Float),
  t: Float,
) -> vec2.Vec2(Float)

Interpolates in two-dimensions over vectors. You can use this function instead of lerper when the generic type is vec2.Vec2(Float).

pub fn lerp3(
  i: vec3.Vec3(Float),
  j: vec3.Vec3(Float),
  t: Float,
) -> vec3.Vec3(Float)

Interpolates in three-dimensions over vectors. You can use this function instead of lerper when the generic type is vec3.Vec3(Float).

pub fn lerper(
  add: fn(a, a) -> a,
  subtract: fn(a, a) -> a,
  scale: fn(a, Float) -> a,
) -> fn(a, a, Float) -> a

Constructs an Interpolator function for the domain a by providing the functions used in the computation, add (+), subtract (-), and scalar multiplication (*).

Search Document