| 277 | // change. Rate should always be a positive value. (T must be signed). |
| 278 | template <typename T> |
| 279 | T approach(T goal, T current, T rate) { |
| 280 | if (goal < current) { |
| 281 | return max(current - rate, goal); |
| 282 | } else if (goal > current) { |
| 283 | return min(current + rate, goal); |
| 284 | } else { |
| 285 | return current; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | // Same as approach, specialied for angles, and always approaches from the |
| 290 | // closest absolute direction. |