}
int t_test_point_to_world_world_to_point(void) {
- struct u_vec2 res = u_point_to_screen(1, 2);
- T_ASSERT(res.x == -2 && res.y == 1, ("point to screen %d/%d\n", res.x, res.y));
+ struct u_vec2 res;
+ i32 x, y;
+ const i32 check_max = 1024 * 8;
+
+ /* 1 */
+ res = u_point_to_screen(4, 2);
+ T_ASSERT(res.x == 0 && res.y == 2, ("point to screen %d/%d\n", res.x, res.y));
res = u_point_to_world(res.x, res.y);
- T_ASSERT(res.x == 1 && res.y == 2, ("point to world %d/%d\n", res.x, res.y));
-
+ T_ASSERT(res.x == 4 && res.y == 2, ("point to world %d/%d\n", res.x, res.y));
+ /* 2 */
res = u_point_to_screen(32, 64);
T_ASSERT(res.x == -48 && res.y == 40, ("point to screen %d/%d\n", res.x, res.y));
res = u_point_to_world(res.x, res.y);
T_ASSERT(res.x == 32 && res.y == 64, ("point to world %d/%d\n", res.x, res.y));
+ /* 3 */
+ res = u_point_to_screen(256, 128);
+ T_ASSERT(res.x == 0 && res.y == 128, ("point to screen %d/%d\n", res.x, res.y));
+
+ res = u_point_to_world(res.x, res.y);
+ T_ASSERT(res.x == 256 && res.y == 128, ("point to world %d/%d\n", res.x, res.y));
+
+ /* test all points
+ * tiles on the grid line should work fine
+ * all other tiles might lose data when transforming back
+ * because it is all integer coordinates
+ */
+ for (x = -check_max; x < check_max; x += R_TILE_W) {
+ for (y = -check_max; y < check_max; y += R_TILE_H) {
+ res = u_point_to_screen(x, y);
+ res = u_point_to_world(res.x, res.y);
+ T_ASSERT(res.x == x && res.y == y, ("point to world from %d/%d to %d/%d\n", x, y, res.x, res.y));
+ }
+ }
+
return 0;
}