(stops: RGB[], p: number)
| 37 | |
| 38 | /** Sample a multi-stop gradient at position p∈[0,1]. Clamps out-of-range p. */ |
| 39 | export function sampleStops(stops: RGB[], p: number): RGB { |
| 40 | if (stops.length === 0) return [255, 255, 255]; |
| 41 | if (stops.length === 1) return stops[0]!; |
| 42 | const clamped = Math.max(0, Math.min(1, p)); |
| 43 | const x = clamped * (stops.length - 1); |
| 44 | const i = Math.floor(x); |
| 45 | const frac = x - i; |
| 46 | const a = stops[i]!; |
| 47 | const b = stops[Math.min(stops.length - 1, i + 1)]!; |
| 48 | return lerpColor(a, b, frac); |
| 49 | } |
| 50 | |
| 51 | /** Wrap a phase value into [0,1) so callers can advance it without bounds-checking. */ |
| 52 | export function wrapPhase(p: number): number { |
no test coverage detected