Well, as you know, min and max are ways of limiting a number. So if you wanted to prevent view.x from getting any lower than 0, you could use this.
- Code: Select all
view.x=max(view.x, 0);
So the way of setting a lower bound is to use max, and the way to set the upper bound is to use min. So, preventing view.x from exceeding 100.
- Code: Select all
view.x=min(view.x, 100);
This makes sense, as for the lower bound, you are defining a max value of 0, and for the upper bound, you define a max value of 100 (since it is min, it can't get larger than 100).
Now, to combine them, all you need to do is put on in the other. Since either the first one (using max), or the second one (using min), returns a single value, that can be used as the argument of the other (min/max).
- Code: Select all
view.x=min(100, max(view.x, 0));
So, the max again will resolve to anything higher than 0, but that gets passed into min, so if it is higher than 100, then the view's x will be set to 100. So, all it does is limit both sides.