Skip to content

atl/sm/util

import "atl/sm/util"

sm.util: interpolation, hashing and UTF-8 helpers.

func Smoothstep(edge0, edge1, x float64) float64

Smooth Hermite step from 0 at edge0 to 1 at edge1. See also sm.Lerp and sm.Clamp.

func Smootherstep(edge0, edge1, x float64) float64

Like Smoothstep, with zero first and second derivatives at the edges.

func PositiveModulo(x, n int) int

x mod n, always in 0..n-1 (unlike Go's %).

func Bezier2(c0, c1, c2, t float64) float64

Quadratic Bezier interpolation of scalars at t (0..1).

func Bezier3(c0, c1, c2, c3, t float64) float64

Cubic Bezier interpolation of scalars at t (0..1).

func Easing(curve string, p float64) float64

An easing curve by name ("easeInOutQuad", "easeOutBounce", ...) at progress p (0..1).

func AxesToQuat(xAxis, yAxis sm.Vec3) sm.Quat

A rotation from two perpendicular axes.

func Hash(values ...any) int

The engine's hash of any values, stable across clients.

func GeometricMedian(points []sm.Vec3, initialGuess *sm.Vec3, iterations *int) sm.Vec3

An approximation of the point with the smallest total distance to points.

func Utf8Length(s string) int

Length of UTF-8 text in characters, not bytes.

func Utf8Clamp(s string, maxChars int) string

UTF-8 text cut to at most maxChars characters.