Documentation
¶
Overview ¶
Package lerp provides high-performance linear interpolation utilities. It offers three precision levels: standard (fast), precise (accurate), and fixed-point (fastest).
Index ¶
- func Between[T Float](start, stop T, fraction float64) T
- func Between32[T ~float32](start, stop T, fraction float32) T
- func Float32(start, stop, fraction float32) float32
- func FloatList32(a, b []float32, t float32) []float32
- func Int(start, stop int, fraction float32) int
- func IntFixed(start, stop, fraction int) int
- func IntPrecise(start, stop int, fraction float32) int
- func LerpColor(a, b struct{ ... }, p float32) struct{ ... }
- func LerpColorList(a, b []struct{ ... }, t float32) []struct{ ... }
- func LerpColorListPrecice(a, b []struct{ ... }, t float32) []struct{ ... }
- func LerpColorPrecise(a, b struct{ ... }, p float32) struct{ ... }
- func LerpDiscrete[T any, F Float](a, b T, fraction F) T
- type Float
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Between ¶
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 ¶
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 FloatList32 ¶
func Int ¶
Int provides fast integer interpolation using float32 intermediates. Truncates fractional parts; use IntPrecise for correct rounding.
func IntFixed ¶
IntFixed uses fixed-point arithmetic (fraction 0-256) for branch-free performance. Fraction 256 equals 1.0. Ideal for animation loops.
func IntPrecise ¶
IntPrecise provides correctly-rounded interpolation using float64.
func LerpColor ¶
LerpColor performs standard RGBA interpolation.
Example:
mid := lerp.LerpColor(color1, color2, 0.5)
func LerpColorList ¶
func LerpColorListPrecice ¶
func LerpColorPrecise ¶
LerpColorPrecise uses squared interpolation for gamma-correct color blending. ~3x slower but produces perceptually better results.