NumberRange utilities

As a developer, it’s annoying to have to dissect NumberRange every time I want to interact with it. I’d like to use it throughout my codebase to represent ranges but it’s unwieldy right now. It would be great if it had some utility functions.

Off the top of my head:

  • NR:isInRange(number) -> boolean to see if a number is within the range
  • NR:clamp(number) -> number to clamp an input using the NR as a range
  • NR.size number to see how wide the range is
  • NR.collapsed boolean to see if the NR’s min and max are the same value
  • NR:getAlpha(number) -> number to get the alpha of an input number ((x-min)/(max-min))
  • NR:slide(number) -> NumberRange to slide the min and max by a certain amount

Just a bunch of stuff like this would be great

17 Likes

I support this! This would be useful for a lot of things. Roblox had something called a DoubleConstrainedValue which had min and max properties to it. While it is unfortunately depreciated it would be the closest thing to what you are requesting currently in the Roblox engine.

1 Like