From 4d9003dc1dce7047b67a263d7348eb216c8b1f5f Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sun, 24 Sep 2023 08:58:18 +0200 Subject: Update math, docs --- README | 1 + source/kit/math.h | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/README b/README index 51e37ba..afa93cf 100644 --- a/README +++ b/README @@ -26,6 +26,7 @@ Features - Input buffer - Random number generation - Async functions (coroutines) + - Vector and color math - XML Preprocessor options diff --git a/source/kit/math.h b/source/kit/math.h index 8deff05..45508b7 100644 --- a/source/kit/math.h +++ b/source/kit/math.h @@ -3,12 +3,18 @@ #include "types.h" -#define _USE_MATH_DEFINES +#ifndef _USE_MATH_DEFINES +# define _USE_MATH_DEFINES +#endif #include #include #include +// TODO +// - Gamma correction. +// + #ifdef __cplusplus extern "C" { #endif @@ -25,7 +31,7 @@ extern "C" { # define KIT_VEC_TYPE f32 #endif -#define KIT_EPSILON .0001 +#define KIT_EPSILON .00001 #define KIT_COLOR_REF_X 95.047f #define KIT_COLOR_REF_Y 100.0f @@ -34,23 +40,14 @@ extern "C" { typedef KIT_VEC_TYPE vec_t; typedef union { - struct { - vec_t x, y; - }; vec_t v[2]; } vec2_t; typedef union { - struct { - vec_t x, y, z; - }; vec_t v[3]; } vec3_t; typedef struct { - struct { - vec_t x, y, z, w; - }; vec_t v[4]; } vec4_t, quat_t; @@ -594,6 +591,10 @@ static quat_t quat_slerp(quat_t q0, quat_t q1, vec_t t) { } static vec3_t rgb_to_xyz(vec3_t rgb) { + // FIXME + // Remove unnecessary x100 scaling. + // + vec_t red = rgb.v[0]; vec_t green = rgb.v[1]; vec_t blue = rgb.v[2]; @@ -627,6 +628,10 @@ static vec3_t rgb_to_xyz(vec3_t rgb) { } static vec3_t xyz_to_rgb(vec3_t xyz) { + // FIXME + // Remove unnecessary x100 scaling. + // + vec_t x = xyz.v[0] / 100.f; vec_t y = xyz.v[1] / 100.f; vec_t z = xyz.v[2] / 100.f; @@ -659,6 +664,10 @@ static vec3_t xyz_to_rgb(vec3_t xyz) { } static vec3_t lab_to_xyz(vec3_t lab) { + // FIXME + // Remove unnecessary x100 scaling. + // + vec_t lightness = lab.v[0]; vec_t a = lab.v[1]; vec_t b = lab.v[2]; @@ -687,6 +696,10 @@ static vec3_t lab_to_xyz(vec3_t lab) { } static vec3_t xyz_to_lab(vec3_t xyz) { + // FIXME + // Remove unnecessary x100 scaling. + // + vec_t x = (xyz.v[0] / KIT_COLOR_REF_X); vec_t y = (xyz.v[1] / KIT_COLOR_REF_Y); vec_t z = (xyz.v[2] / KIT_COLOR_REF_Z); -- cgit v1.2.3