From 03fc9c440a329a0a92c8f7e4b30781f00e5f0149 Mon Sep 17 00:00:00 2001 From: CodeMyst Date: Sun, 28 Jun 2020 11:06:04 +0200 Subject: [PATCH] made the lib betterC compatible --- source/cosmomyst/math/matrix.d | 12 +++--------- source/cosmomyst/math/vector.d | 10 +--------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/source/cosmomyst/math/matrix.d b/source/cosmomyst/math/matrix.d index 1d095d8..331f892 100644 --- a/source/cosmomyst/math/matrix.d +++ b/source/cosmomyst/math/matrix.d @@ -17,8 +17,10 @@ struct mat(ulong n) if (n >= 2) { } @nogc this(T...)(T args) pure nothrow { + import std.traits : isNumeric; + static foreach (arg; args) { - static assert(is(typeof(arg) == float) || is(typeof(arg) == const(float)), "all values must be of type float"); + static assert(isNumeric!(typeof(arg)), "all values must be numeric"); } static assert(args.length > 0, "no args provided"); @@ -132,11 +134,6 @@ struct mat(ulong n) if (n >= 2) { return res; } - string toString() { - import std.format : format; - return format!("%s")(c); - } - /++ + internal data as a pointer, use for sending data to shaders. +/ @@ -343,8 +340,6 @@ unittest { t1[0, 0] = 5f; assert(t1[0, 0] == 5f); - - assert(t1.toString() == "[[5, 2], [2, 2]]"); } unittest { @@ -400,7 +395,6 @@ unittest { } unittest { - auto m1 = mat4(5f, 6f, 6f, 8f, 2f, 2f, 2f, 8f, 6f, 6f, 2f, 8f, 2f, 3f, 6f, 7f); assert(mat_inverse(m1) * m1 == mat_ident!4()); } diff --git a/source/cosmomyst/math/vector.d b/source/cosmomyst/math/vector.d index 8c1d6aa..ad5b258 100644 --- a/source/cosmomyst/math/vector.d +++ b/source/cosmomyst/math/vector.d @@ -90,11 +90,6 @@ struct vec(ulong n) if (n >= 1) { return this / length(); } - string toString() const { - import std.string : format; - return format("%s", v); - } - /++ + returns the negated vector. +/ @@ -221,10 +216,9 @@ struct vec(ulong n) if (n >= 1) { + returns the dot product of 2 vectors. +/ @nogc float vec_dot(ulong n)(vec!n a, vec!n b) pure nothrow { - import std.format : format; float res = 0f; static foreach (i; 0..n) { - mixin(format!("res += a.v[%s] * b.v[%s];")(i, i)); + res += a.v[i] * b.v[i]; } return res; } @@ -247,8 +241,6 @@ unittest { auto t2 = vec2(2f); assert(t2.x == 2f); assert(t2.y == 2f); - - assert(t1.toString() == "[2, 3]"); } unittest {