Skip to content

Commit

Permalink
Adding macros for math min, max, and clamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chukobyte committed Feb 24, 2024
1 parent 4bd9a80 commit ae0313b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions seika/data_structures/ska_array2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ bool ska_array2d_set(SkaArray2D* array2d, size_t x, size_t y, void* newValue) {

void ska_array2d_resize(SkaArray2D* array2d, size_t newX, size_t newY) {
// Reallocate memory for data array
const size_t width = max(newX, 1);
const size_t height = max(newY, 1);
const size_t width = SKA_MATH_MAX(newX, 1);
const size_t height = SKA_MATH_MAX(newY, 1);

array2d->data = ska_mem_reallocate(array2d->data, height * sizeof(void*));
for (size_t i = 0; i < height; i++) {
Expand Down
4 changes: 4 additions & 0 deletions seika/math/se_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ typedef struct SKAMinMaxVec2 {
SKAVector2 ska_math_minmax_vec2_get_random_in_range(const SKAMinMaxVec2* minmax);

// --- Misc --- //
#define SKA_MATH_MIN(A, B) ((A) < (B) ? (A) : (B))
#define SKA_MATH_MAX(A, B) ((A) > (B) ? (A) : (B))
#define SKA_MATH_CLAMP(VAL, MIN_VAL, MAX_VAL) ((VAL) < (MIN_VAL) ? (MIN_VAL) : (VAL) > (MAX_VAL) ? (MAX_VAL) : (VAL))

float ska_math_lerpf(float a, float b, float alpha);
float ska_math_map_to_range(float input, float inputMin, float inputMax, float outputMin, float outputMax);
float ska_math_map_to_unit(float input, float inputMin, float inputMax);
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seika",
"version": "0.0.38",
"version": "0.0.39",
"dependencies": [
{
"name": "sdl2",
Expand Down

0 comments on commit ae0313b

Please sign in to comment.