2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @file util.h
|
|
|
|
|
* @brief Declares the public util API.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-03 10:07:35 -04:00
|
|
|
#ifndef _UTIL_H_
|
|
|
|
|
#define _UTIL_H_
|
|
|
|
|
|
2026-01-05 08:58:06 -05:00
|
|
|
#include <akerror.h>
|
2026-05-24 09:51:58 -04:00
|
|
|
#include <akgl/staticstring.h>
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/** @brief Represents a two-dimensional point. */
|
2025-08-03 10:07:35 -04:00
|
|
|
typedef struct point {
|
Reindent all C sources to the canonical stroustrup style
Mechanical whitespace-only change across src/, include/, tests/, and
util/, applied with scripts/reindent.sh. No behavioral change.
Most files already conformed. The genuine outliers indented at 2 columns
(json_helpers.c, util.c from akgl_rectangle_points onward, assets.c,
staticstring.c, akgl_actor_add_child, util.h, staticstring.h) or used
spaces where the canonical form is a tab (draw.c). cc-mode also re-aligns
line-continuation backslashes in multi-line macros to its default
c-backslash-column, which is required for the tree to be a fixed point of
the indenter.
Verified whitespace-only: `git diff -w` over this change is empty apart
from three trailing blank lines removed at EOF in src/heap.c,
src/registry.c, and tests/tilemap.c. The build produces no new errors and
ctest is unchanged at 13/14, with `character` still the one intentional
failure.
The tree is now a fixed point of `scripts/reindent.sh --check`.
include/akgl/SDL_GameControllerDB.h is generated and excluded.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 18:17:37 -04:00
|
|
|
int x;
|
|
|
|
|
int y;
|
|
|
|
|
int z;
|
2025-08-03 10:07:35 -04:00
|
|
|
} point;
|
|
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/** @brief Stores the corners of an axis-aligned rectangle. */
|
2025-08-03 10:07:35 -04:00
|
|
|
typedef struct RectanglePoints {
|
Reindent all C sources to the canonical stroustrup style
Mechanical whitespace-only change across src/, include/, tests/, and
util/, applied with scripts/reindent.sh. No behavioral change.
Most files already conformed. The genuine outliers indented at 2 columns
(json_helpers.c, util.c from akgl_rectangle_points onward, assets.c,
staticstring.c, akgl_actor_add_child, util.h, staticstring.h) or used
spaces where the canonical form is a tab (draw.c). cc-mode also re-aligns
line-continuation backslashes in multi-line macros to its default
c-backslash-column, which is required for the tree to be a fixed point of
the indenter.
Verified whitespace-only: `git diff -w` over this change is empty apart
from three trailing blank lines removed at EOF in src/heap.c,
src/registry.c, and tests/tilemap.c. The build produces no new errors and
ctest is unchanged at 13/14, with `character` still the one intentional
failure.
The tree is now a fixed point of `scripts/reindent.sh --check`.
include/akgl/SDL_GameControllerDB.h is generated and excluded.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-30 18:17:37 -04:00
|
|
|
point topleft;
|
|
|
|
|
point topright;
|
|
|
|
|
point bottomleft;
|
|
|
|
|
point bottomright;
|
2025-08-03 10:07:35 -04:00
|
|
|
} RectanglePoints;
|
|
|
|
|
|
2026-05-06 23:18:42 -04:00
|
|
|
#define AKGL_COLLIDE_RECTANGLES(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) ((r1x < (r2x + r2w)) || ((r1x + r1w) > r2x)
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Rectangle points.
|
|
|
|
|
* @param dest Output destination populated by the function.
|
|
|
|
|
* @param rect Rectangle whose corner points are calculated.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_rectangle_points(RectanglePoints *dest, SDL_FRect *rect);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Collide point rectangle.
|
|
|
|
|
* @param p Point to test for containment.
|
|
|
|
|
* @param r Rectangle corner data used for collision testing.
|
|
|
|
|
* @param collide Output set to whether the tested geometry intersects.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_collide_point_rectangle(point *p, RectanglePoints *r, bool *collide);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Collide rectangles.
|
|
|
|
|
* @param r1 First rectangle to compare.
|
|
|
|
|
* @param r2 Second rectangle to compare.
|
|
|
|
|
* @param collide Output set to whether the tested geometry intersects.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Path relative.
|
|
|
|
|
* @param root Base directory used to resolve the path.
|
|
|
|
|
* @param path Path to resolve or transform.
|
|
|
|
|
* @param dst Output destination populated by the function.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-24 09:51:58 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_path_relative(char *root, char *path, akgl_String *dst);
|
|
|
|
|
|
2025-08-03 10:07:35 -04:00
|
|
|
// These are REALLY slow routines that are only useful in testing harnesses
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Compare sdl surfaces.
|
|
|
|
|
* @param s1 First SDL surface to compare.
|
|
|
|
|
* @param s2 Second SDL surface to compare.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_VALUE When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2);
|
2026-07-30 01:10:31 -04:00
|
|
|
/**
|
|
|
|
|
* @brief Render and compare.
|
|
|
|
|
* @param t1 First texture to render for comparison.
|
|
|
|
|
* @param t2 Second texture to render for comparison.
|
|
|
|
|
* @param x Horizontal destination coordinate.
|
|
|
|
|
* @param y Vertical destination coordinate.
|
|
|
|
|
* @param w Destination width.
|
|
|
|
|
* @param h Destination height.
|
|
|
|
|
* @param writeout Optional filename for the rendered diagnostic image.
|
|
|
|
|
* @return `NULL` on success, otherwise an error context owned by the caller.
|
|
|
|
|
* @throws AKERR_IO When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
|
|
|
|
* @throws AKGL_ERR_SDL When the corresponding validation or operation fails.
|
|
|
|
|
*/
|
2026-05-06 23:18:42 -04:00
|
|
|
akerr_ErrorContext AKERR_NOIGNORE *akgl_render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout);
|
2025-08-03 10:07:35 -04:00
|
|
|
|
|
|
|
|
#endif // _UTIL_H_
|