- matrix_set(m, 0, 2, x);
- matrix_set(m, 1, 2, y);
-
- matrix_set(m, 0, 0, w);
- matrix_set(m, 1, 1, h);
+ /*
+ * There are 16 cases:
+ * Rotation X Reflection
+ * Rotation: 0 | 90 | 180 | 270
+ * Reflection: None | X | Y | XY
+ *
+ * They are spelled out instead of doing matrix multiplication to avoid
+ * any floating point errors.
+ */
+ switch (rotation) {
+ case RR_Rotate_0:
+ case RR_Rotate_180 | RR_Reflect_All:
+ matrix_s4(m, x, y, w, h, 1);
+ break;
+ case RR_Reflect_X|RR_Rotate_0:
+ case RR_Reflect_Y|RR_Rotate_180:
+ matrix_s4(m, x + w, y, -w, h, 1);
+ break;
+ case RR_Reflect_Y|RR_Rotate_0:
+ case RR_Reflect_X|RR_Rotate_180:
+ matrix_s4(m, x, y + h, w, -h, 1);
+ break;
+ case RR_Rotate_90:
+ case RR_Rotate_270 | RR_Reflect_All: /* left limited - correct in working zone. */
+ matrix_s4(m, x + w, y, -w, h, 0);
+ break;
+ case RR_Rotate_270:
+ case RR_Rotate_90 | RR_Reflect_All: /* left limited - correct in working zone. */
+ matrix_s4(m, x, y + h, w, -h, 0);
+ break;
+ case RR_Rotate_90 | RR_Reflect_X: /* left limited - correct in working zone. */
+ case RR_Rotate_270 | RR_Reflect_Y: /* left limited - correct in working zone. */
+ matrix_s4(m, x, y, w, h, 0);
+ break;
+ case RR_Rotate_90 | RR_Reflect_Y: /* right limited - correct in working zone. */
+ case RR_Rotate_270 | RR_Reflect_X: /* right limited - correct in working zone. */
+ matrix_s4(m, x + w, y + h, -w, -h, 0);
+ break;
+ case RR_Rotate_180:
+ case RR_Reflect_All|RR_Rotate_0:
+ matrix_s4(m, x + w, y + h, -w, -h, 1);
+ break;
+ }