MCPcopy Index your code
hub / github.com/ericdrowell/KineticJS / remap

Function remap

kinetic.js:5325–5344  ·  view source on GitHub ↗
(fromValue, fromMin, fromMax, toMin, toMax)

Source from the content-addressed store, hash-verified

5323
5324;(function () {
5325 function remap(fromValue, fromMin, fromMax, toMin, toMax) {
5326 // Compute the range of the data
5327 var fromRange = fromMax - fromMin,
5328 toRange = toMax - toMin,
5329 toValue;
5330
5331 // If either range is 0, then the value can only be mapped to 1 value
5332 if (fromRange === 0) {
5333 return toMin + toRange / 2;
5334 }
5335 if (toRange === 0) {
5336 return toMin;
5337 }
5338
5339 // (1) untranslate, (2) unscale, (3) rescale, (4) retranslate
5340 toValue = (fromValue - fromMin) / fromRange;
5341 toValue = (toRange * toValue) + toMin;
5342
5343 return toValue;
5344 }
5345
5346
5347 /**

Callers 1

kinetic.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected