Unify namespaces
This commit is contained in:
+66
-66
@@ -5,102 +5,102 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
float kinc_cot(float x) {
|
||||
float iron_cot(float x) {
|
||||
return cosf(x) / sinf(x);
|
||||
}
|
||||
|
||||
float kinc_round(float value) {
|
||||
float iron_round(float value) {
|
||||
return floorf(value + 0.5f);
|
||||
}
|
||||
|
||||
float kinc_abs(float value) {
|
||||
float iron_abs(float value) {
|
||||
return value < 0 ? -value : value;
|
||||
}
|
||||
|
||||
float kinc_min(float a, float b) {
|
||||
float iron_min(float a, float b) {
|
||||
return a > b ? b : a;
|
||||
}
|
||||
|
||||
float kinc_max(float a, float b) {
|
||||
float iron_max(float a, float b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
int kinc_mini(int a, int b) {
|
||||
int iron_mini(int a, int b) {
|
||||
return a > b ? b : a;
|
||||
}
|
||||
|
||||
int kinc_maxi(int a, int b) {
|
||||
int iron_maxi(int a, int b) {
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
float kinc_clamp(float value, float minValue, float maxValue) {
|
||||
return kinc_max(minValue, kinc_min(maxValue, value));
|
||||
float iron_clamp(float value, float minValue, float maxValue) {
|
||||
return iron_max(minValue, iron_min(maxValue, value));
|
||||
}
|
||||
|
||||
float kinc_matrix3x3_get(kinc_matrix3x3_t *matrix, int x, int y) {
|
||||
float iron_matrix3x3_get(iron_matrix3x3_t *matrix, int x, int y) {
|
||||
return matrix->m[x * 3 + y];
|
||||
}
|
||||
|
||||
void kinc_matrix3x3_set(kinc_matrix3x3_t *matrix, int x, int y, float value) {
|
||||
void iron_matrix3x3_set(iron_matrix3x3_t *matrix, int x, int y, float value) {
|
||||
matrix->m[x * 3 + y] = value;
|
||||
}
|
||||
|
||||
void kinc_matrix3x3_transpose(kinc_matrix3x3_t *matrix) {
|
||||
kinc_matrix3x3_t transposed;
|
||||
void iron_matrix3x3_transpose(iron_matrix3x3_t *matrix) {
|
||||
iron_matrix3x3_t transposed;
|
||||
for (int y = 0; y < 3; ++y) {
|
||||
for (int x = 0; x < 3; ++x) {
|
||||
kinc_matrix3x3_set(&transposed, x, y, kinc_matrix3x3_get(matrix, y, x));
|
||||
iron_matrix3x3_set(&transposed, x, y, iron_matrix3x3_get(matrix, y, x));
|
||||
}
|
||||
}
|
||||
memcpy(matrix->m, transposed.m, sizeof(transposed.m));
|
||||
}
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_identity(void) {
|
||||
kinc_matrix3x3_t m;
|
||||
iron_matrix3x3_t iron_matrix3x3_identity(void) {
|
||||
iron_matrix3x3_t m;
|
||||
memset(m.m, 0, sizeof(m.m));
|
||||
for (unsigned x = 0; x < 3; ++x) {
|
||||
kinc_matrix3x3_set(&m, x, x, 1.0f);
|
||||
iron_matrix3x3_set(&m, x, x, 1.0f);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_rotation_x(float alpha) {
|
||||
kinc_matrix3x3_t m = kinc_matrix3x3_identity();
|
||||
iron_matrix3x3_t iron_matrix3x3_rotation_x(float alpha) {
|
||||
iron_matrix3x3_t m = iron_matrix3x3_identity();
|
||||
float ca = cosf(alpha);
|
||||
float sa = sinf(alpha);
|
||||
kinc_matrix3x3_set(&m, 1, 1, ca);
|
||||
kinc_matrix3x3_set(&m, 2, 1, -sa);
|
||||
kinc_matrix3x3_set(&m, 1, 2, sa);
|
||||
kinc_matrix3x3_set(&m, 2, 2, ca);
|
||||
iron_matrix3x3_set(&m, 1, 1, ca);
|
||||
iron_matrix3x3_set(&m, 2, 1, -sa);
|
||||
iron_matrix3x3_set(&m, 1, 2, sa);
|
||||
iron_matrix3x3_set(&m, 2, 2, ca);
|
||||
return m;
|
||||
}
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_rotation_y(float alpha) {
|
||||
kinc_matrix3x3_t m = kinc_matrix3x3_identity();
|
||||
iron_matrix3x3_t iron_matrix3x3_rotation_y(float alpha) {
|
||||
iron_matrix3x3_t m = iron_matrix3x3_identity();
|
||||
float ca = cosf(alpha);
|
||||
float sa = sinf(alpha);
|
||||
kinc_matrix3x3_set(&m, 0, 0, ca);
|
||||
kinc_matrix3x3_set(&m, 2, 0, sa);
|
||||
kinc_matrix3x3_set(&m, 0, 2, -sa);
|
||||
kinc_matrix3x3_set(&m, 2, 2, ca);
|
||||
iron_matrix3x3_set(&m, 0, 0, ca);
|
||||
iron_matrix3x3_set(&m, 2, 0, sa);
|
||||
iron_matrix3x3_set(&m, 0, 2, -sa);
|
||||
iron_matrix3x3_set(&m, 2, 2, ca);
|
||||
return m;
|
||||
}
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_rotation_z(float alpha) {
|
||||
kinc_matrix3x3_t m = kinc_matrix3x3_identity();
|
||||
iron_matrix3x3_t iron_matrix3x3_rotation_z(float alpha) {
|
||||
iron_matrix3x3_t m = iron_matrix3x3_identity();
|
||||
float ca = cosf(alpha);
|
||||
float sa = sinf(alpha);
|
||||
kinc_matrix3x3_set(&m, 0, 0, ca);
|
||||
kinc_matrix3x3_set(&m, 1, 0, -sa);
|
||||
kinc_matrix3x3_set(&m, 0, 1, sa);
|
||||
kinc_matrix3x3_set(&m, 1, 1, ca);
|
||||
iron_matrix3x3_set(&m, 0, 0, ca);
|
||||
iron_matrix3x3_set(&m, 1, 0, -sa);
|
||||
iron_matrix3x3_set(&m, 0, 1, sa);
|
||||
iron_matrix3x3_set(&m, 1, 1, ca);
|
||||
return m;
|
||||
}
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_translation(float x, float y) {
|
||||
kinc_matrix3x3_t m = kinc_matrix3x3_identity();
|
||||
kinc_matrix3x3_set(&m, 2, 0, x);
|
||||
kinc_matrix3x3_set(&m, 2, 1, y);
|
||||
iron_matrix3x3_t iron_matrix3x3_translation(float x, float y) {
|
||||
iron_matrix3x3_t m = iron_matrix3x3_identity();
|
||||
iron_matrix3x3_set(&m, 2, 0, x);
|
||||
iron_matrix3x3_set(&m, 2, 1, y);
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -108,74 +108,74 @@ kinc_matrix3x3_t kinc_matrix3x3_translation(float x, float y) {
|
||||
#pragma clang diagnostic ignored "-Wconditional-uninitialized"
|
||||
#endif
|
||||
|
||||
kinc_matrix3x3_t kinc_matrix3x3_multiply(kinc_matrix3x3_t *a, kinc_matrix3x3_t *b) {
|
||||
kinc_matrix3x3_t result;
|
||||
iron_matrix3x3_t iron_matrix3x3_multiply(iron_matrix3x3_t *a, iron_matrix3x3_t *b) {
|
||||
iron_matrix3x3_t result;
|
||||
for (unsigned x = 0; x < 3; ++x) {
|
||||
for (unsigned y = 0; y < 3; ++y) {
|
||||
float t = kinc_matrix3x3_get(a, 0, y) * kinc_matrix3x3_get(b, x, 0);
|
||||
float t = iron_matrix3x3_get(a, 0, y) * iron_matrix3x3_get(b, x, 0);
|
||||
for (unsigned i = 1; i < 3; ++i) {
|
||||
t += kinc_matrix3x3_get(a, i, y) * kinc_matrix3x3_get(b, x, i);
|
||||
t += iron_matrix3x3_get(a, i, y) * iron_matrix3x3_get(b, x, i);
|
||||
}
|
||||
kinc_matrix3x3_set(&result, x, y, t);
|
||||
iron_matrix3x3_set(&result, x, y, t);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static float vector3_get(kinc_vector3_t vec, int index) {
|
||||
static float vector3_get(iron_vector3_t vec, int index) {
|
||||
float *values = (float *)&vec;
|
||||
return values[index];
|
||||
}
|
||||
|
||||
static void vector3_set(kinc_vector3_t *vec, int index, float value) {
|
||||
static void vector3_set(iron_vector3_t *vec, int index, float value) {
|
||||
float *values = (float *)vec;
|
||||
values[index] = value;
|
||||
}
|
||||
|
||||
kinc_vector3_t kinc_matrix3x3_multiply_vector(kinc_matrix3x3_t *a, kinc_vector3_t b) {
|
||||
kinc_vector3_t product;
|
||||
iron_vector3_t iron_matrix3x3_multiply_vector(iron_matrix3x3_t *a, iron_vector3_t b) {
|
||||
iron_vector3_t product;
|
||||
for (unsigned y = 0; y < 3; ++y) {
|
||||
float t = 0;
|
||||
for (unsigned x = 0; x < 3; ++x) {
|
||||
t += kinc_matrix3x3_get(a, x, y) * vector3_get(b, x);
|
||||
t += iron_matrix3x3_get(a, x, y) * vector3_get(b, x);
|
||||
}
|
||||
vector3_set(&product, y, t);
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
float kinc_matrix4x4_get(kinc_matrix4x4_t *matrix, int x, int y) {
|
||||
float iron_matrix4x4_get(iron_matrix4x4_t *matrix, int x, int y) {
|
||||
return matrix->m[x * 4 + y];
|
||||
}
|
||||
|
||||
void kinc_matrix4x4_set(kinc_matrix4x4_t *matrix, int x, int y, float value) {
|
||||
void iron_matrix4x4_set(iron_matrix4x4_t *matrix, int x, int y, float value) {
|
||||
matrix->m[x * 4 + y] = value;
|
||||
}
|
||||
|
||||
void kinc_matrix4x4_transpose(kinc_matrix4x4_t *matrix) {
|
||||
kinc_matrix4x4_t transposed;
|
||||
void iron_matrix4x4_transpose(iron_matrix4x4_t *matrix) {
|
||||
iron_matrix4x4_t transposed;
|
||||
for (int y = 0; y < 4; ++y) {
|
||||
for (int x = 0; x < 4; ++x) {
|
||||
kinc_matrix4x4_set(&transposed, x, y, kinc_matrix4x4_get(matrix, y, x));
|
||||
iron_matrix4x4_set(&transposed, x, y, iron_matrix4x4_get(matrix, y, x));
|
||||
}
|
||||
}
|
||||
memcpy(matrix->m, transposed.m, sizeof(transposed.m));
|
||||
}
|
||||
|
||||
kinc_matrix4x4_t kinc_matrix4x4_multiply(kinc_matrix4x4_t *a, kinc_matrix4x4_t *b) {
|
||||
kinc_matrix4x4_t result;
|
||||
iron_matrix4x4_t iron_matrix4x4_multiply(iron_matrix4x4_t *a, iron_matrix4x4_t *b) {
|
||||
iron_matrix4x4_t result;
|
||||
for (unsigned x = 0; x < 4; ++x)
|
||||
for (unsigned y = 0; y < 4; ++y) {
|
||||
float t = kinc_matrix4x4_get(a, 0, y) * kinc_matrix4x4_get(b, x, 0);
|
||||
float t = iron_matrix4x4_get(a, 0, y) * iron_matrix4x4_get(b, x, 0);
|
||||
for (unsigned i = 1; i < 4; ++i) {
|
||||
t += kinc_matrix4x4_get(a, i, y) * kinc_matrix4x4_get(b, x, i);
|
||||
t += iron_matrix4x4_get(a, i, y) * iron_matrix4x4_get(b, x, i);
|
||||
}
|
||||
kinc_matrix4x4_set(&result, x, y, t);
|
||||
iron_matrix4x4_set(&result, x, y, t);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void kinc_color_components(uint32_t color, float *red, float *green, float *blue, float *alpha) {
|
||||
void iron_color_components(uint32_t color, float *red, float *green, float *blue, float *alpha) {
|
||||
*alpha = ((color & 0xff000000) >> 24) / 255.0f;
|
||||
*red = ((color & 0x00ff0000) >> 16) / 255.0f;
|
||||
*green = ((color & 0x0000ff00) >> 8) / 255.0f;
|
||||
@@ -206,7 +206,7 @@ uint64_t next(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void kinc_random_init(int64_t seed) {
|
||||
void iron_random_init(int64_t seed) {
|
||||
s[0] = (uint64_t)seed;
|
||||
s[1] = 2;
|
||||
s[2] = 3;
|
||||
@@ -216,15 +216,15 @@ void kinc_random_init(int64_t seed) {
|
||||
s[3] = next();
|
||||
}
|
||||
|
||||
int64_t kinc_random_get(void) {
|
||||
int64_t iron_random_get(void) {
|
||||
return (int64_t)next();
|
||||
}
|
||||
|
||||
int64_t kinc_random_get_max(int64_t max) {
|
||||
return kinc_random_get() % (max + 1);
|
||||
int64_t iron_random_get_max(int64_t max) {
|
||||
return iron_random_get() % (max + 1);
|
||||
}
|
||||
|
||||
int64_t kinc_random_get_in(int64_t min, int64_t max) {
|
||||
int64_t value = kinc_random_get();
|
||||
int64_t iron_random_get_in(int64_t min, int64_t max) {
|
||||
int64_t value = iron_random_get();
|
||||
return (value < -LLONG_MAX ? LLONG_MAX : llabs(value)) % (max + 1 - min) + min;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user