Need to find a mathematical operation formulating such a function:
a<=x<=b,-r<=w<=r,r<b-a
y=x+w, if a<=x+w<=b;
y=b, if x+w>b;
y=a, if x+w<a;
This is just similar to mod operation. So is there an operation for the above function?
Need to find a mathematical operation formulating such a function:
a<=x<=b,-r<=w<=r,r<b-a
y=x+w, if a<=x+w<=b;
y=b, if x+w>b;
y=a, if x+w<a;
This is just similar to mod operation. So is there an operation for the above function?
Copyright © 2021 JogjaFile Inc.

Your function is equivalent to
$$\frac{a + b + |x+\omega - a| - |x+\omega - b|}{2}$$
where $| \cdot |$ denotes absolute value.
You can see an example of this function in action, with $a = 5$ and $b=7$.
I've substituted $y=x+\omega$ in the wolfram alpha demostration to make it easier to see the behavior of the function. As someone has pointed out in the comments, these types of functions are examples of clamping.