Only one of the statements can be true: tmpx < X_MIN_POS or tmpx > X_MAX_POS. So we can be a little bit smarter here and skip the second if statement if the first was true. This saves 6 bytes of flash memory and potential some clock cycles
@@ -129,16 +129,15 @@ inline bool world2machine_clamp(float &x, float &y)
if (tmpx < X_MIN_POS) {
tmpx = X_MIN_POS;
clamped = true;
+ } else if (tmpx > X_MAX_POS) {
+ tmpx = X_MAX_POS;
+ clamped = true;
}
+
if (tmpy < Y_MIN_POS) {
tmpy = Y_MIN_POS;
- }
+ } else if (tmpy > Y_MAX_POS) {
- if (tmpx > X_MAX_POS) {
- tmpx = X_MAX_POS;
- clamped = true;
- if (tmpy > Y_MAX_POS) {
tmpy = Y_MAX_POS;