summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-24 08:58:18 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-24 08:58:18 +0200
commit4d9003dc1dce7047b67a263d7348eb216c8b1f5f (patch)
tree6af57f18a34cc92bf213a7ed234366e1f64f4266 /source
parentdc7c20af7a27891d3ab4e47174c3e9a2a852c64f (diff)
downloadkit-4d9003dc1dce7047b67a263d7348eb216c8b1f5f.zip
Update math, docs
Diffstat (limited to 'source')
-rw-r--r--source/kit/math.h35
1 files changed, 24 insertions, 11 deletions
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 <math.h>
#include <assert.h>
#include <string.h>
+// 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);