MCPcopy
hub / github.com/pmndrs/react-spring / interpolate

Function interpolate

packages/shared/src/createInterpolator.ts:59–93  ·  view source on GitHub ↗
(
  input: number,
  inputMin: number,
  inputMax: number,
  outputMin: number,
  outputMax: number,
  easing: EasingFunction,
  extrapolateLeft: ExtrapolateType,
  extrapolateRight: ExtrapolateType,
  map?: (x: number) => number
)

Source from the content-addressed store, hash-verified

57}
58
59function interpolate(
60 input: number,
61 inputMin: number,
62 inputMax: number,
63 outputMin: number,
64 outputMax: number,
65 easing: EasingFunction,
66 extrapolateLeft: ExtrapolateType,
67 extrapolateRight: ExtrapolateType,
68 map?: (x: number) => number
69) {
70 let result = map ? map(input) : input
71 // Extrapolate
72 if (result < inputMin) {
73 if (extrapolateLeft === 'identity') return result
74 else if (extrapolateLeft === 'clamp') result = inputMin
75 }
76 if (result > inputMax) {
77 if (extrapolateRight === 'identity') return result
78 else if (extrapolateRight === 'clamp') result = inputMax
79 }
80 if (outputMin === outputMax) return outputMin
81 if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax
82 // Input Range
83 if (inputMin === -Infinity) result = -result
84 else if (inputMax === Infinity) result = result - inputMin
85 else result = (result - inputMin) / (inputMax - inputMin)
86 // Easing
87 result = easing(result)
88 // Output Range
89 if (outputMin === -Infinity) result = -result
90 else if (outputMax === Infinity) result = result + outputMin
91 else result = result * (outputMax - outputMin) + outputMin
92 return result
93}
94
95function findRange(input: number, inputRange: readonly number[]) {
96 // eslint-disable-next-line no-var

Callers 2

createInterpolatorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…