From 3f0ea887cd2923cb2cf390a4929ffce452301670 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 1 May 2024 21:28:42 -0400 Subject: [PATCH] allow any type that can be static_cast to type of vector in operators like +, -, *. / --- CMakeLists.txt | 2 +- include/blt/math/vectors.h | 48 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93185fd..77c6563 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.16.19) +set(BLT_VERSION 0.16.20) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/math/vectors.h b/include/blt/math/vectors.h index 061362c..89fe7fc 100644 --- a/include/blt/math/vectors.h +++ b/include/blt/math/vectors.h @@ -291,39 +291,39 @@ namespace blt return initializer; } - template - inline constexpr vec operator+(const vec& left, T right) + template + inline constexpr vec operator+(const vec& left, G right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = left[i] + right; + initializer[i] = left[i] + static_cast(right); return initializer; } - template - inline constexpr vec operator-(const vec& left, T right) + template + inline constexpr vec operator-(const vec& left, G right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = left[i] + right; + initializer[i] = left[i] + static_cast(right); return initializer; } - template - inline constexpr vec operator+(T f, const vec& right) + template + inline constexpr vec operator+(G left, const vec& right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = f + right[i]; + initializer[i] = static_cast(left) + right[i]; return initializer; } - template - inline constexpr vec operator-(T f, const vec& right) + template + inline constexpr vec operator-(G left, const vec& right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = f - right[i]; + initializer[i] = static_cast(left) - right[i]; return initializer; } @@ -336,39 +336,39 @@ namespace blt return initializer; } - template - inline constexpr vec operator*(const vec& left, T right) + template + inline constexpr vec operator*(const vec& left, G right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = left[i] * right; + initializer[i] = left[i] * static_cast(right); return initializer; } - template - inline constexpr vec operator*(T f, const vec& right) + template + inline constexpr vec operator*(G left, const vec& right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = f * right[i]; + initializer[i] = static_cast(left) * right[i]; return initializer; } - template - inline constexpr vec operator/(const vec& left, T right) + template + inline constexpr vec operator/(const vec& left, G right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = left[i] / right; + initializer[i] = left[i] / static_cast(right); return initializer; } - template - inline constexpr vec operator/(T left, const vec& right) + template + inline constexpr vec operator/(G left, const vec& right) { vec initializer{}; for (blt::u32 i = 0; i < size; i++) - initializer[i] = left / right[i]; + initializer[i] = static_cast(left) / right[i]; return initializer; }