From 4624f30f1faf4d2b77fdcb1087b1d7155d9f4d25 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Sun, 8 Mar 2026 14:37:33 +0100 Subject: [PATCH] vector alignment optional --- interfaces/Crafter.Math-Vector.cppm | 34 ++++++++++++++--------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/interfaces/Crafter.Math-Vector.cppm b/interfaces/Crafter.Math-Vector.cppm index 60a9c9a..6e113b2 100755 --- a/interfaces/Crafter.Math-Vector.cppm +++ b/interfaces/Crafter.Math-Vector.cppm @@ -45,7 +45,7 @@ namespace Crafter { T r, g; }; }; - constexpr VectorBase(float x, float y): x(x), y(y) { + constexpr VectorBase(T x, T y): x(x), y(y) { } constexpr VectorBase() = default; @@ -62,7 +62,7 @@ namespace Crafter { T r, g, b; }; }; - constexpr VectorBase(float x, float y, float z): x(x), y(y), z(z) { + constexpr VectorBase(T x, T y, T z): x(x), y(y), z(z) { } constexpr VectorBase() = default; @@ -79,7 +79,7 @@ namespace Crafter { T r, g, b, a; }; }; - constexpr VectorBase(float x, float y, float z, float w): x(x), y(y), z(z), w(w) { + constexpr VectorBase(T x, T y, T z, T w): x(x), y(y), z(z), w(w) { } constexpr VectorBase() = default; @@ -109,7 +109,7 @@ namespace Crafter { T r, g; }; }; - constexpr VectorBase(float x, float y): x(x), y(y) { + constexpr VectorBase(T x, T y): x(x), y(y) { } constexpr VectorBase() = default; @@ -126,7 +126,7 @@ namespace Crafter { T r, g, b; }; }; - constexpr VectorBase(float x, float y, float z): x(x), y(y), z(z) { + constexpr VectorBase(T x, T y, T z): x(x), y(y), z(z) { } constexpr VectorBase() = default; @@ -143,22 +143,22 @@ namespace Crafter { T r, g, b, a; }; }; - constexpr VectorBase(float x, float y, float z, float w): x(x), y(y), z(z), w(w) { + constexpr VectorBase(T x, T y, T z, T w): x(x), y(y), z(z), w(w) { } constexpr VectorBase() = default; }; - export template + export template class Vector : public VectorBase { public: - constexpr Vector(float x, float y, float z, float w ) requires(std::same_as && Len == 4) : VectorBase(x, y, z, w) { + constexpr Vector(T x, T y, T z, T w ) requires(std::same_as && Len == 4) : VectorBase(x, y, z, w) { } - constexpr Vector(float x, float y, float z) requires(std::same_as && Len == 3) : VectorBase(x, y, z) { + constexpr Vector(T x, T y, T z) requires(std::same_as && Len == 3) : VectorBase(x, y, z) { } - constexpr Vector(float x, float y) requires(std::same_as && Len == 2) : VectorBase(x, y) { + constexpr Vector(T x, T y) requires(std::same_as && Len == 2) : VectorBase(x, y) { } @@ -315,7 +315,7 @@ namespace Crafter { } constexpr void Normalize() { - float fLength = Length(); + T fLength = Length(); if (fLength > 0) { fLength = 1.0f / fLength; @@ -332,12 +332,12 @@ namespace Crafter { } } - constexpr float Length() const { - float Result = LengthSq(); + constexpr T Length() const { + T Result = LengthSq(); return std::sqrtf(Result); } - constexpr float LengthSq() const { + constexpr T LengthSq() const { return Dot(*this, *this); } @@ -353,7 +353,7 @@ namespace Crafter { template constexpr static Vector Normalize(Vector a) requires(Len == Alen) { Vector returned; - float fLength = a.Length(); + T fLength = a.Length(); if (fLength > 0) { fLength = 1.0f / fLength; @@ -366,8 +366,8 @@ namespace Crafter { } template - constexpr static float Dot(Vector a, Vector b) requires(Alen >= Len && Blen >= Len) { - float accumulate = a.v[0] * b.v[0]; + constexpr static T Dot(Vector a, Vector b) requires(Alen >= Len && Blen >= Len) { + T accumulate = a.v[0] * b.v[0]; for(std::uint32_t i = 1; i < Len; i++) { accumulate += a.v[i] * b.v[i]; }