Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I name a method that does this...?

I have a method that receives two range endpoints - start of range and end of range and an integer.

It checks to see if the integer falls between the two end points and returns either the integer or the corresponding end point if the integer falls outside the boundary.

Example 1:

  • RangeStart = 0; RangeEnd = 10; Value = 5; Returns 5

Example 2:

  • RangeStart = 0; RangeEnd = 10; Value = -4; Returns 0

Example 3:

  • RangeStart = 0; RangeEnd = 10; Value = 23; Returns 10

Question: What should I call a method that does that? I had called it IntWithinRange, but I don't think I like that.

Any ideas?

like image 823
BenAlabaster Avatar asked Jul 16 '09 21:07

BenAlabaster


2 Answers

How about ConstrictToRange / LimitToRange / ConfineToRange? Something of this form would be seem to convey the meaning quite succinctly.

like image 67
Noldorin Avatar answered Oct 15 '22 05:10

Noldorin


I've seen it called Clamp().

And that's what M$ calls it.

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.mathhelper.clamp.aspx

like image 33
Ray Avatar answered Oct 15 '22 04:10

Ray