From: Elias Fleckenstein Date: Tue, 1 Feb 2022 17:25:34 +0000 (+0100) Subject: Remove numeric types X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=39b52e8cfa889d55008f2edd0933d6b421556c34;p=dragonstd.git Remove numeric types --- diff --git a/README.md b/README.md index 000c278..acc765e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Dragonstd -Dragonstd is a small C library providing the types that [dragonblocks_alpha](https://github.com/dragonblocks/dragonblocks_alpha) uses. +Dragonstd is a small C library providing the data structures that [dragonblocks_alpha](https://github.com/dragonblocks/dragonblocks_alpha) uses. It serves a similar purpose as the C++ standard library would, but C++ is just bloated af. This library is only capable of what dragonblocks needs, and it does not intend to be general purpose. -Included are Array, Bintree, List and Queue as well as numeric types. +Included are Array, Bintree, List and Queue. diff --git a/number.c b/number.c deleted file mode 100644 index 0b4f096..0000000 --- a/number.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "number.h" - -#define DEFINE_CLAMP(scalar) \ - scalar scalar ## _clamp(scalar v, scalar min, scalar max) \ - { \ - return v < min ? min : v > max ? max : v; \ - } - -#define DEFINE_VECTOR2(vector, clamp) \ - bool vector ## _equals(vector a, vector b) \ - { \ - return a.x == b.x && a.y == b.y; \ - } \ - vector vector ## _add(vector a, vector b) \ - { \ - return (vector) {a.x + b.x, a.y + b.y}; \ - } \ - vector vector ## _clamp(vector v, vector min, vector max) \ - { \ - return (vector) {clamp(v.x, min.x, max.x), clamp(v.y, min.y, max.y)}; \ - } - -#define DEFINE_VECTOR3(vector, clamp) \ - bool vector ## _equals(vector a, vector b) \ - { \ - return a.x == b.x && a.y == b.y && a.z == b.z; \ - } \ - vector vector ## _add(vector a, vector b) \ - { \ - return (vector) {a.x + b.x, a.y + b.y, a.z + b.z}; \ - } \ - vector vector ## _clamp(vector v, vector min, vector max) \ - { \ - return (vector) {clamp(v.x, min.x, max.x), clamp(v.y, min.y, max.y), clamp(v.z, min.z, max.z)}; \ - } - -#define DEFINE_VECTOR4(vector, clamp) \ - bool vector ## _equals(vector a, vector b) \ - { \ - return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; \ - } \ - vector vector ## _add(vector a, vector b) \ - { \ - return (vector) {a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w}; \ - } \ - vector vector ## _clamp(vector v, vector min, vector max) \ - { \ - return (vector) {clamp(v.x, min.x, max.x), clamp(v.y, min.y, max.y), clamp(v.z, min.z, max.z), clamp(v.w, min.w, max.w)}; \ - } - -#define DEFINE_SCALAR(scalar) \ - DEFINE_CLAMP(scalar) \ - DEFINE_VECTOR2(v2 ## scalar, scalar ## _clamp) \ - DEFINE_VECTOR3(v3 ## scalar, scalar ## _clamp) \ - DEFINE_VECTOR4(v4 ## scalar, scalar ## _clamp) - -#define DEFINE_INTEGER(bits) \ - DEFINE_SCALAR(s ## bits) \ - DEFINE_SCALAR(u ## bits) - -#define DEFINE_MIX_VECTOR2(vector, scalar, mix) \ - vector vector ## _mix(vector a, vector b, scalar f) \ - { \ - return (vector) {mix(a.x, b.x, f), mix(a.y, b.y, f)}; \ - } - -#define DEFINE_MIX_VECTOR3(vector, scalar, mix) \ - vector vector ## _mix(vector a, vector b, scalar f) \ - { \ - return (vector) {mix(a.x, b.x, f), mix(a.y, b.y, f), mix(a.z, b.z, f)}; \ - } - -#define DEFINE_MIX_VECTOR4(vector, scalar, mix) \ - vector vector ## _mix(vector a, vector b, scalar f) \ - { \ - return (vector) {mix(a.x, b.x, f), mix(a.y, b.y, f), mix(a.z, b.z, f), mix(a.w, b.w, f)}; \ - } - -#define DEFINE_FLOAT(type) \ - DEFINE_SCALAR(type) \ - type type ## _mix(type a, type b, type f) \ - { \ - return (1.0 - f) * a + b * f; \ - } \ - DEFINE_MIX_VECTOR2(v2 ## type, type, type ## _mix) \ - DEFINE_MIX_VECTOR3(v3 ## type, type, type ## _mix) \ - DEFINE_MIX_VECTOR4(v4 ## type, type, type ## _mix) - -DEFINE_INTEGER(8) -DEFINE_INTEGER(16) -DEFINE_INTEGER(32) -DEFINE_INTEGER(64) - -DEFINE_FLOAT(f32) -DEFINE_FLOAT(f64) diff --git a/number.h b/number.h deleted file mode 100644 index 44e4313..0000000 --- a/number.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef _DRAGONSTD_NUMBER_H_ -#define _DRAGONSTD_NUMBER_H_ - -#include -#include - -#define DEFINE_CLAMP(type) \ - type type ## _clamp(type v, type min, type max); - -#define DEFINE_MIX(scalar, type) \ - type type ## _mix(type a, type b, scalar f); - -#define DEFINE_VECTOR(scalar, vector, box) vector; \ - typedef struct {vector min; vector max;} box; \ - bool vector ## _equals(vector a, vector b); \ - vector vector ## _add(vector a, vector b); \ - vector vector ## _clamp(vector v, vector min, vector max); \ - DEFINE_CLAMP(vector) - -#define DEFINE_VECTORS(scalar) \ - typedef struct {scalar x, y ;} DEFINE_VECTOR(scalar, v2 ## scalar, aabb2 ## scalar) \ - typedef struct {scalar x, y, z ;} DEFINE_VECTOR(scalar, v3 ## scalar, aabb3 ## scalar) \ - typedef struct {scalar x, y, z, w;} DEFINE_VECTOR(scalar, v4 ## scalar, aabb4 ## scalar) - -#define DEFINE_SCALAR(scalar, origin) \ - typedef origin scalar; \ - scalar scalar ## _max(scalar a, scalar b); \ - scalar scalar ## _min(scalar a, scalar b); \ - DEFINE_CLAMP(scalar) \ - DEFINE_VECTORS(scalar) - -#define DEFINE_INTEGER(bits) \ - DEFINE_SCALAR(s ## bits, int ## bits ## _t) \ - DEFINE_SCALAR(u ## bits, uint ## bits ## _t) - -#define DEFINE_FLOAT(type, origin) \ - DEFINE_SCALAR(type, origin) \ - DEFINE_MIX(type, type) \ - DEFINE_MIX(type, v2 ## type) \ - DEFINE_MIX(type, v3 ## type) \ - DEFINE_MIX(type, v4 ## type) - -DEFINE_INTEGER(8) -DEFINE_INTEGER(16) -DEFINE_INTEGER(32) -DEFINE_INTEGER(64) - -DEFINE_FLOAT(f32, float) -DEFINE_FLOAT(f64, double) - -#undef DEFINE_CLAMP -#undef DEFINE_MIX -#undef DEFINE_VECTOR -#undef DEFINE_VECTORS -#undef DEFINE_SCALAR -#undef DEFINE_INTEGER -#undef DEFINE_FLOAT - -#endif