MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / sampleStops

Function sampleStops

src/cli/prompts/gradient.tsx:39–49  ·  view source on GitHub ↗
(stops: RGB[], p: number)

Source from the content-addressed store, hash-verified

37
38/** Sample a multi-stop gradient at position p∈[0,1]. Clamps out-of-range p. */
39export 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. */
52export function wrapPhase(p: number): number {

Callers 3

gradient.test.tsFile · 0.85
GradientTextFunction · 0.85
GradientBarFunction · 0.85

Calls 1

lerpColorFunction · 0.85

Tested by

no test coverage detected