Skip to content

Conversation

@tobi01001
Copy link

The current scale implementation can lead to return values beyond min/max being specified when the value is out of bounds.

This commit ensures that the boundaries are kept:

export function scale(value, minIn, maxIn, minOut, maxOut) {
  if(value <= minIn) {
	  return minOut;
  }
  else if(value >= maxIn) {
	  return maxOut;
  }
  else
  {	  
	const slope = (minOut - maxOut) / (minIn - maxIn);
	const intercept = slope * -(minIn) + minOut;
	return value * slope + intercept;
  }
}

The current scale implementation can lead to return values beyond min/max being specified when the value is out of bounds.

This commit ensures that the boundaries are kept.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant