From 06261cfdfeec0d8186b62d7e1be849fb5276227d Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Mon, 29 Apr 2024 01:13:05 +0200 Subject: math: vec[234][fi]: Add begin, cbegin methods and explicit const_pointer and pointer conversion ops, allowing to access aligned memory like Matrix4 --- include/jau/math/vec2f.hpp | 6 ++++++ include/jau/math/vec2i.hpp | 6 ++++++ include/jau/math/vec3f.hpp | 6 ++++++ include/jau/math/vec4f.hpp | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/include/jau/math/vec2f.hpp b/include/jau/math/vec2f.hpp index 598d01e..9a830f7 100644 --- a/include/jau/math/vec2f.hpp +++ b/include/jau/math/vec2f.hpp @@ -86,12 +86,18 @@ namespace jau::math { return (&x)[i]; } + explicit operator const_pointer() const noexcept { return &x; } + constexpr const_iterator cbegin() const noexcept { return &x; } + /** Returns writeable reference to component */ constexpr reference operator[](size_t i) noexcept { assert(i < 2); return (&x)[i]; } + explicit operator pointer() noexcept { return &x; } + constexpr iterator begin() noexcept { return &x; } + /** xy = this, returns xy. */ constexpr iterator get(iterator xy) const noexcept { xy[0] = x; diff --git a/include/jau/math/vec2i.hpp b/include/jau/math/vec2i.hpp index 17e84de..ec6e237 100644 --- a/include/jau/math/vec2i.hpp +++ b/include/jau/math/vec2i.hpp @@ -83,12 +83,18 @@ namespace jau::math { return (&x)[i]; } + explicit operator const_pointer() const noexcept { return &x; } + constexpr const_iterator cbegin() const noexcept { return &x; } + /** Returns writeable reference to component */ constexpr reference operator[](size_t i) noexcept { assert(i < 2); return (&x)[i]; } + explicit operator pointer() noexcept { return &x; } + constexpr iterator begin() noexcept { return &x; } + /** xy = this, returns xy. */ constexpr iterator get(iterator xy) const noexcept { xy[0] = x; diff --git a/include/jau/math/vec3f.hpp b/include/jau/math/vec3f.hpp index b63a405..c68b45c 100644 --- a/include/jau/math/vec3f.hpp +++ b/include/jau/math/vec3f.hpp @@ -96,12 +96,18 @@ namespace jau::math { return (&x)[i]; } + explicit operator const_pointer() const noexcept { return &x; } + constexpr const_iterator cbegin() const noexcept { return &x; } + /** Returns writeable reference to component */ constexpr reference operator[](size_t i) noexcept { assert(i < 3); return (&x)[i]; } + explicit operator pointer() noexcept { return &x; } + constexpr iterator begin() noexcept { return &x; } + /** xyz = this, returns xyz. */ constexpr iterator get(iterator xyz) const noexcept { xyz[0] = x; diff --git a/include/jau/math/vec4f.hpp b/include/jau/math/vec4f.hpp index 2580c17..b27c767 100644 --- a/include/jau/math/vec4f.hpp +++ b/include/jau/math/vec4f.hpp @@ -97,12 +97,18 @@ namespace jau::math { return (&x)[i]; } + explicit operator const_pointer() const noexcept { return &x; } + constexpr const_iterator cbegin() const noexcept { return &x; } + /** Returns writeable reference to component */ constexpr reference operator[](size_t i) noexcept { assert(i < 4); return (&x)[i]; } + explicit operator pointer() noexcept { return &x; } + constexpr iterator begin() noexcept { return &x; } + /** xyzw = this, returns xyzw. */ constexpr iterator get(iterator xyzw) const noexcept { xyzw[0] = x; -- cgit v1.2.3