lerp

package
v0.1.102 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lerp provides high-performance linear interpolation utilities. It offers three precision levels: standard (fast), precise (accurate), and fixed-point (fastest).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Between

func Between[T Float](start, stop T, fraction float64) T

Between performs type-safe linear interpolation with float64 precision. Returns NaN if either start or stop is NaN.

Example:

pos := lerp.Between(0.0, 100.0, 0.5) // 50.0

func Between32

func Between32[T ~float32](start, stop T, fraction float32) T

Between32 is optimized for float32 types with ~15% better performance than Between.

Example:

opacity := lerp.Between32(0.0, 1.0, 0.5) // 0.5

func Float32

func Float32(start, stop, fraction float32) float32

Float32 interpolates between two float32 values with zero allocation overhead.

func FloatList32

func FloatList32(a, b []float32, t float32) []float32

func Int

func Int(start, stop int, fraction float32) int

Int provides fast integer interpolation using float32 intermediates. Truncates fractional parts; use IntPrecise for correct rounding.

func IntFixed

func IntFixed(start, stop, fraction int) int

IntFixed uses fixed-point arithmetic (fraction 0-256) for branch-free performance. Fraction 256 equals 1.0. Ideal for animation loops.

func IntPrecise

func IntPrecise(start, stop int, fraction float32) int

IntPrecise provides correctly-rounded interpolation using float64.

func LerpColor

func LerpColor(a, b struct{ R, G, B, A float32 }, p float32) struct{ R, G, B, A float32 }

LerpColor performs standard RGBA interpolation.

Example:

mid := lerp.LerpColor(color1, color2, 0.5)

func LerpColorList

func LerpColorList(a, b []struct{ R, G, B, A float32 }, t float32) []struct{ R, G, B, A float32 }

func LerpColorListPrecice

func LerpColorListPrecice(a, b []struct{ R, G, B, A float32 }, t float32) []struct{ R, G, B, A float32 }

func LerpColorPrecise

func LerpColorPrecise(a, b struct{ R, G, B, A float32 }, p float32) struct{ R, G, B, A float32 }

LerpColorPrecise uses squared interpolation for gamma-correct color blending. ~3x slower but produces perceptually better results.

func LerpDiscrete

func LerpDiscrete[T any, F Float](a, b T, fraction F) T

Types

type Float

type Float interface {
	~float32 | ~float64
}

Float constraint for all float32 and float64 based types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL