point in rect.
#ifdef LRTS_IMPL
#include "tests/t_args.c"
#include "tests/t_arena.c"
+#include "tests/t_math.c"
#endif
int main(int argc, char **argv) {
T_TESTBEGIN("lrts test");
lrts_getopt(argc, argv, lrts_cfg());
- T_TESTCASE("test-argv", t_test_argv);
- T_TESTCASE("test-arena", t_test_arena);
+ T_TESTCASE("argv", t_test_argv);
+ T_TESTCASE("arena", t_test_arena);
+ T_TESTCASE("tile-to-screen", t_test_tile_to_screen);
+ T_TESTCASE("point-in-rect", t_test_pointinrect);
T_TESTEND("lrts test");
--- /dev/null
+#include "../u_arena.h"
+#include "t_defs.h"
+#include "../u_math.h"
+
+int t_test_pointinrect(void) {
+ T_ASSERT(u_point_in_rect(5, 5, 4, 2, 4, 5), ("point in rect\n"));
+ T_ASSERT(u_point_in_rect(1, 1, 4, 2, 4, 5) == LRTS_FALSE, ("point not in rect\n"));
+
+ return 0;
+}
+
+int t_test_tile_to_screen(void) {
+ struct u_vec2 res = u_tile_to_screen(0, 0);
+ T_ASSERT(res.x == 0 && res.y == 0, ("tile to screen %d/%d\n", res.x, res.y));
+
+ res = u_tile_to_screen(1, 1);
+ T_ASSERT(res.x == 96 && res.y == 0, ("tile to screen %d/%d\n", res.x, res.y));
+
+ res = u_tile_to_screen(1, 2);
+ T_ASSERT(res.x == 144 && res.y == 24, ("tile to screen %d/%d\n", res.x, res.y));
+ return 0;
+}
return r;
}
+
+lrts_bool u_point_in_rect(i32 x, i32 y, i32 rx, i32 ry, i32 rw, i32 rh) {
+ return x >= rx && x <= rx + rw
+ && y >= ry && y <= ry + rh;
+}
#define U_FP(n, f) {n, f}
#define U_V2(x, y) {x, y}
+/* Clamps an integer value between min and max */
+#define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }
+
/* fixed point number
* n: whole part
* f: fractional part
*/
struct u_vec2 u_tile_to_screen(i32 x, i32 y);
-/* Clamps an integer value between min and max */
-#define U_CLAMP(v, min, max) if (v < min) { v = min; } if (v > max) { v = max; }
+/* tests if a point is contained inside a rectangle */
+lrts_bool u_point_in_rect(i32 x, i32 y, i32 rx, i32 ry, i32 rw, i32 rh);
#endif