From 44a96c00069a181f37ae8f6c6056ffeff012238b Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Fri, 22 Mar 2019 21:56:27 +0800 Subject: [PATCH 01/19] build: update CMakeLists.txt to use alias namespace cppid::gm3d --- CMakeLists.txt | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bfed25b..798f825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,26 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.13) project(Gm3d) -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) +add_library(cppid-gm3d INTERFACE) +add_library(cppid::gm3d ALIAS cppid-gm3d) -set(Gm3d_WARNING_OPTIONS "-Wall" "-Wpedantic") - -add_library(gm3d INTERFACE) - -target_include_directories(gm3d +target_include_directories(cppid-gm3d INTERFACE "${PROJECT_SOURCE_DIR}/src/" ) -target_compile_options(gm3d INTERFACE ${Gm3d_WARNING_OPTIONS} "-stdlib=libc++") +target_compile_options(cppid-gm3d + INTERFACE + -Wall + -Wpedantic + -pedantic-errors + -fno-rtti +) +target_compile_features(cppid-gm3d + INTERFACE + cxx_std_17 +) if(GM3D_BUILD_TESTING) enable_testing() @@ -35,16 +40,15 @@ if(GM3D_BUILD_TESTING) get_filename_component(Gm3d_NAME ${Gm3d_FILES} NAME_WE) - set(Gm3d_TARGET_NAME "gm3d-test-${Gm3d_NAME}") + set(Gm3d_TARGET_NAME "cppid-gm3d-test-${Gm3d_NAME}") add_executable(${Gm3d_TARGET_NAME} ${Gm3d_FILES}) - target_link_libraries(${Gm3d_TARGET_NAME} PRIVATE gm3d) - - target_link_libraries(${Gm3d_TARGET_NAME} PRIVATE gm3d Catch2) - - target_compile_options( - ${Gm3d_TARGET_NAME} PRIVATE ${Gm3d_WARNING_OPTIONS} "-stdlib=libc++") + target_link_libraries(${Gm3d_TARGET_NAME} + PRIVATE + cppid::gm3d + Catch2::Catch2 + ) add_test( NAME ${Gm3d_TARGET_NAME} @@ -54,5 +58,3 @@ if(GM3D_BUILD_TESTING) endforeach() endif() - - From 24bda605ab280f7c030bc4302bd09783e5d83fcb Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Fri, 22 Mar 2019 21:56:27 +0800 Subject: [PATCH 02/19] refactor: edit namespace to cppid::gm3d and edit header guard macro Header guard macro will prefixes with CPPID_GM3D_. --- src/gm3d/Mat3.hpp | 4 ++-- src/gm3d/Mat4.hpp | 8 ++++---- src/gm3d/Rgba.hpp | 8 ++++---- src/gm3d/Vec.hpp | 8 ++++---- src/gm3d/Vec2.hpp | 8 ++++---- src/gm3d/Vec3.hpp | 8 ++++---- src/gm3d/all.hpp | 4 ++-- src/gm3d/detail/BasicRgba.hpp | 8 ++++---- src/gm3d/detail/type_traits.hpp | 8 ++++---- test/matrix3.cpp | 4 ++-- test/matrix4.cpp | 2 +- test/rgba_float.cpp | 4 ++-- test/rgba_uint8.cpp | 2 +- test/vector2.cpp | 2 +- test/vector3.cpp | 2 +- 15 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/gm3d/Mat3.hpp b/src/gm3d/Mat3.hpp index 3cedd46..d01b03c 100644 --- a/src/gm3d/Mat3.hpp +++ b/src/gm3d/Mat3.hpp @@ -3,7 +3,7 @@ #include "Mat4.hpp" -namespace gm3d { +namespace cppid::gm3d { template struct Mat3 { T m[9]; @@ -193,6 +193,6 @@ struct Mat3 { } }; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/Mat4.hpp b/src/gm3d/Mat4.hpp index e04635e..7a55a9c 100644 --- a/src/gm3d/Mat4.hpp +++ b/src/gm3d/Mat4.hpp @@ -1,5 +1,5 @@ -#ifndef GM3D_MAT4_HPP -#define GM3D_MAT4_HPP +#ifndef CPPID_GM3D_MAT4_HPP +#define CPPID_GM3D_MAT4_HPP #include #include @@ -8,7 +8,7 @@ #include "Vec2.hpp" #include "Vec3.hpp" -namespace gm3d { +namespace cppid::gm3d { template struct Mat4 { @@ -678,6 +678,6 @@ struct Mat4 { } }; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/Rgba.hpp b/src/gm3d/Rgba.hpp index b1100c9..eee9557 100644 --- a/src/gm3d/Rgba.hpp +++ b/src/gm3d/Rgba.hpp @@ -1,12 +1,12 @@ -#ifndef GM3D_RGBA_HPP -#define GM3D_RGBA_HPP +#ifndef CPPID_GM3D_RGBA_HPP +#define CPPID_GM3D_RGBA_HPP #include #include #include "detail/BasicRgba.hpp" -namespace gm3d { +namespace cppid::gm3d { template class Rgba; @@ -59,6 +59,6 @@ class Rgba : public detail::BasicRgba, float> { } }; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/Vec.hpp b/src/gm3d/Vec.hpp index 29f3cbc..ccd3f22 100644 --- a/src/gm3d/Vec.hpp +++ b/src/gm3d/Vec.hpp @@ -1,5 +1,5 @@ -#ifndef GM3D_VEC_HPP -#define GM3D_VEC_HPP +#ifndef CPPID_GM3D_VEC_HPP +#define CPPID_GM3D_VEC_HPP #include #include @@ -11,7 +11,7 @@ #include "detail/type_traits.hpp" -namespace gm3d { +namespace cppid::gm3d { template struct Vec { @@ -406,6 +406,6 @@ struct Vec { } }; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/Vec2.hpp b/src/gm3d/Vec2.hpp index 6744614..2786b00 100644 --- a/src/gm3d/Vec2.hpp +++ b/src/gm3d/Vec2.hpp @@ -1,13 +1,13 @@ -#ifndef GM3D_VEC2_HPP -#define GM3D_VEC2_HPP +#ifndef CPPID_GM3D_VEC2_HPP +#define CPPID_GM3D_VEC2_HPP #include "Vec.hpp" -namespace gm3d { +namespace cppid::gm3d { template using Vec2 = Vec; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/Vec3.hpp b/src/gm3d/Vec3.hpp index 97deff7..11e97f0 100644 --- a/src/gm3d/Vec3.hpp +++ b/src/gm3d/Vec3.hpp @@ -1,16 +1,16 @@ -#ifndef GM3D_VEC3_HPP -#define GM3D_VEC3_HPP +#ifndef CPPID_GM3D_VEC3_HPP +#define CPPID_GM3D_VEC3_HPP #include #include #include "Vec.hpp" -namespace gm3d { +namespace cppid::gm3d { template using Vec3 = Vec; -} // namespace gm3d +} // namespace cppid::gm3d #endif diff --git a/src/gm3d/all.hpp b/src/gm3d/all.hpp index 69c2359..fe39617 100644 --- a/src/gm3d/all.hpp +++ b/src/gm3d/all.hpp @@ -1,5 +1,5 @@ -#ifndef GM3D_ALL_HPP -#define GM3D_ALL_HPP +#ifndef CPPID_GM3D_ALL_HPP +#define CPPID_GM3D_ALL_HPP #include "Mat3.hpp" #include "Mat4.hpp" diff --git a/src/gm3d/detail/BasicRgba.hpp b/src/gm3d/detail/BasicRgba.hpp index 424427d..9eb9326 100644 --- a/src/gm3d/detail/BasicRgba.hpp +++ b/src/gm3d/detail/BasicRgba.hpp @@ -1,7 +1,7 @@ -#ifndef GM3D_DETAIL_BASIC_RGBA_HPP -#define GM3D_DETAIL_BASIC_RGBA_HPP +#ifndef CPPID_GM3D_DETAIL_BASIC_RGBA_HPP +#define CPPID_GM3D_DETAIL_BASIC_RGBA_HPP -namespace gm3d::detail { +namespace cppid::gm3d::detail { template class BasicRgba { @@ -93,6 +93,6 @@ class BasicRgba { Scalar r_, g_, b_, a_; }; -} // namespace gm3d::detail +} // namespace cppid::gm3d::detail #endif diff --git a/src/gm3d/detail/type_traits.hpp b/src/gm3d/detail/type_traits.hpp index e4652ca..1b57237 100644 --- a/src/gm3d/detail/type_traits.hpp +++ b/src/gm3d/detail/type_traits.hpp @@ -1,10 +1,10 @@ -#ifndef GM3D_DETAIL_TYPE_TRAITS_HPP -#define GM3D_DETAIL_TYPE_TRAITS_HPP +#ifndef CPPID_GM3D_DETAIL_TYPE_TRAITS_HPP +#define CPPID_GM3D_DETAIL_TYPE_TRAITS_HPP #include #include -namespace gm3d::detail { +namespace cppid::gm3d::detail { template struct is_explicit_constructible @@ -26,6 +26,6 @@ template inline constexpr bool is_implicit_constructible_v = is_implicit_constructible::value; -} // namespace gm3d::detail +} // namespace cppid::gm3d::detail #endif diff --git a/test/matrix3.cpp b/test/matrix3.cpp index 0701e0c..5103429 100644 --- a/test/matrix3.cpp +++ b/test/matrix3.cpp @@ -6,8 +6,8 @@ #include -using gm3d::Mat3; -using gm3d::Mat4; +using cppid::gm3d::Mat3; +using cppid::gm3d::Mat4; using Mat3f = Mat3; TEST_CASE("float_matrix3_test traits") diff --git a/test/matrix4.cpp b/test/matrix4.cpp index ee53370..c1e9ebe 100644 --- a/test/matrix4.cpp +++ b/test/matrix4.cpp @@ -6,7 +6,7 @@ #include -using Mat4f = gm3d::Mat4; +using Mat4f = cppid::gm3d::Mat4; TEST_CASE("float_matrix4_test traits") { diff --git a/test/rgba_float.cpp b/test/rgba_float.cpp index 287874b..bba06f8 100644 --- a/test/rgba_float.cpp +++ b/test/rgba_float.cpp @@ -7,8 +7,8 @@ #include using u8 = std::uint8_t; -using Rgba8 = gm3d::Rgba; -using Rgbaf = gm3d::Rgba; +using Rgba8 = cppid::gm3d::Rgba; +using Rgbaf = cppid::gm3d::Rgba; TEST_CASE("rgba_uint8 traits") { diff --git a/test/rgba_uint8.cpp b/test/rgba_uint8.cpp index badd51e..910e364 100644 --- a/test/rgba_uint8.cpp +++ b/test/rgba_uint8.cpp @@ -6,7 +6,7 @@ #include -using Rgba8 = gm3d::Rgba; +using Rgba8 = cppid::gm3d::Rgba; TEST_CASE("rgba_uint8 traits") { diff --git a/test/vector2.cpp b/test/vector2.cpp index 9f5d955..7f402f8 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -6,7 +6,7 @@ #include -using gm3d::Vec2; +using cppid::gm3d::Vec2; using Vec2f = Vec2; TEST_CASE("float_vector2_test traits") diff --git a/test/vector3.cpp b/test/vector3.cpp index 0ca5fa0..a1bc949 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -6,7 +6,7 @@ #include -using gm3d::Vec3; +using cppid::gm3d::Vec3; using Vec3f = Vec3; TEST_CASE("float_vector3_test traits") From ab0f55167b77a1d4dabf794a49e4a091f2a04b05 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Fri, 22 Mar 2019 23:05:48 +0800 Subject: [PATCH 03/19] refactor: move project folders to src/cppid/gm3d --- CMakeLists.txt | 4 ++-- src/{ => cppid}/gm3d/Mat3.hpp | 0 src/{ => cppid}/gm3d/Mat4.hpp | 0 src/{ => cppid}/gm3d/Rgba.hpp | 0 src/{ => cppid}/gm3d/Vec.hpp | 0 src/{ => cppid}/gm3d/Vec2.hpp | 0 src/{ => cppid}/gm3d/Vec3.hpp | 0 src/{ => cppid}/gm3d/all.hpp | 0 src/{ => cppid}/gm3d/detail/BasicRgba.hpp | 0 src/{ => cppid}/gm3d/detail/type_traits.hpp | 0 test/matrix3.cpp | 2 +- test/matrix4.cpp | 2 +- test/rgba_float.cpp | 2 +- test/rgba_uint8.cpp | 2 +- test/vector2.cpp | 2 +- test/vector3.cpp | 2 +- 16 files changed, 8 insertions(+), 8 deletions(-) rename src/{ => cppid}/gm3d/Mat3.hpp (100%) rename src/{ => cppid}/gm3d/Mat4.hpp (100%) rename src/{ => cppid}/gm3d/Rgba.hpp (100%) rename src/{ => cppid}/gm3d/Vec.hpp (100%) rename src/{ => cppid}/gm3d/Vec2.hpp (100%) rename src/{ => cppid}/gm3d/Vec3.hpp (100%) rename src/{ => cppid}/gm3d/all.hpp (100%) rename src/{ => cppid}/gm3d/detail/BasicRgba.hpp (100%) rename src/{ => cppid}/gm3d/detail/type_traits.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 798f825..b0254b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,8 @@ add_library(cppid-gm3d INTERFACE) add_library(cppid::gm3d ALIAS cppid-gm3d) target_include_directories(cppid-gm3d -INTERFACE - "${PROJECT_SOURCE_DIR}/src/" + INTERFACE + "${PROJECT_SOURCE_DIR}/src" ) target_compile_options(cppid-gm3d diff --git a/src/gm3d/Mat3.hpp b/src/cppid/gm3d/Mat3.hpp similarity index 100% rename from src/gm3d/Mat3.hpp rename to src/cppid/gm3d/Mat3.hpp diff --git a/src/gm3d/Mat4.hpp b/src/cppid/gm3d/Mat4.hpp similarity index 100% rename from src/gm3d/Mat4.hpp rename to src/cppid/gm3d/Mat4.hpp diff --git a/src/gm3d/Rgba.hpp b/src/cppid/gm3d/Rgba.hpp similarity index 100% rename from src/gm3d/Rgba.hpp rename to src/cppid/gm3d/Rgba.hpp diff --git a/src/gm3d/Vec.hpp b/src/cppid/gm3d/Vec.hpp similarity index 100% rename from src/gm3d/Vec.hpp rename to src/cppid/gm3d/Vec.hpp diff --git a/src/gm3d/Vec2.hpp b/src/cppid/gm3d/Vec2.hpp similarity index 100% rename from src/gm3d/Vec2.hpp rename to src/cppid/gm3d/Vec2.hpp diff --git a/src/gm3d/Vec3.hpp b/src/cppid/gm3d/Vec3.hpp similarity index 100% rename from src/gm3d/Vec3.hpp rename to src/cppid/gm3d/Vec3.hpp diff --git a/src/gm3d/all.hpp b/src/cppid/gm3d/all.hpp similarity index 100% rename from src/gm3d/all.hpp rename to src/cppid/gm3d/all.hpp diff --git a/src/gm3d/detail/BasicRgba.hpp b/src/cppid/gm3d/detail/BasicRgba.hpp similarity index 100% rename from src/gm3d/detail/BasicRgba.hpp rename to src/cppid/gm3d/detail/BasicRgba.hpp diff --git a/src/gm3d/detail/type_traits.hpp b/src/cppid/gm3d/detail/type_traits.hpp similarity index 100% rename from src/gm3d/detail/type_traits.hpp rename to src/cppid/gm3d/detail/type_traits.hpp diff --git a/test/matrix3.cpp b/test/matrix3.cpp index 5103429..6c20924 100644 --- a/test/matrix3.cpp +++ b/test/matrix3.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Mat3; using cppid::gm3d::Mat4; diff --git a/test/matrix4.cpp b/test/matrix4.cpp index c1e9ebe..b6c712a 100644 --- a/test/matrix4.cpp +++ b/test/matrix4.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using Mat4f = cppid::gm3d::Mat4; diff --git a/test/rgba_float.cpp b/test/rgba_float.cpp index bba06f8..e8322f2 100644 --- a/test/rgba_float.cpp +++ b/test/rgba_float.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using u8 = std::uint8_t; using Rgba8 = cppid::gm3d::Rgba; diff --git a/test/rgba_uint8.cpp b/test/rgba_uint8.cpp index 910e364..1139fd0 100644 --- a/test/rgba_uint8.cpp +++ b/test/rgba_uint8.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using Rgba8 = cppid::gm3d::Rgba; diff --git a/test/vector2.cpp b/test/vector2.cpp index 7f402f8..66858c1 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Vec2; using Vec2f = Vec2; diff --git a/test/vector3.cpp b/test/vector3.cpp index a1bc949..05dda9d 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Vec3; using Vec3f = Vec3; From 7ab34265fce5e467b1ca27e09ead70fe4c75baa5 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Fri, 22 Mar 2019 23:19:56 +0800 Subject: [PATCH 04/19] refactor: change file names to lowercase --- src/cppid/gm3d/all.hpp | 10 +++++----- .../gm3d/detail/{BasicRgba.hpp => basic_rgba.hpp} | 0 src/cppid/gm3d/{Mat3.hpp => mat3.hpp} | 2 +- src/cppid/gm3d/{Mat4.hpp => mat4.hpp} | 4 ++-- src/cppid/gm3d/{Rgba.hpp => rgba.hpp} | 2 +- src/cppid/gm3d/{Vec.hpp => vec.hpp} | 0 src/cppid/gm3d/{Vec2.hpp => vec2.hpp} | 2 +- src/cppid/gm3d/{Vec3.hpp => vec3.hpp} | 2 +- test/matrix3.cpp | 2 +- test/matrix4.cpp | 2 +- test/rgba_float.cpp | 2 +- test/rgba_uint8.cpp | 2 +- test/vector2.cpp | 2 +- test/vector3.cpp | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) rename src/cppid/gm3d/detail/{BasicRgba.hpp => basic_rgba.hpp} (100%) rename src/cppid/gm3d/{Mat3.hpp => mat3.hpp} (99%) rename src/cppid/gm3d/{Mat4.hpp => mat4.hpp} (99%) rename src/cppid/gm3d/{Rgba.hpp => rgba.hpp} (97%) rename src/cppid/gm3d/{Vec.hpp => vec.hpp} (100%) rename src/cppid/gm3d/{Vec2.hpp => vec2.hpp} (89%) rename src/cppid/gm3d/{Vec3.hpp => vec3.hpp} (91%) diff --git a/src/cppid/gm3d/all.hpp b/src/cppid/gm3d/all.hpp index fe39617..6e20f55 100644 --- a/src/cppid/gm3d/all.hpp +++ b/src/cppid/gm3d/all.hpp @@ -1,10 +1,10 @@ #ifndef CPPID_GM3D_ALL_HPP #define CPPID_GM3D_ALL_HPP -#include "Mat3.hpp" -#include "Mat4.hpp" -#include "Rgba.hpp" -#include "Vec2.hpp" -#include "Vec3.hpp" +#include "mat3.hpp" +#include "mat4.hpp" +#include "rgba.hpp" +#include "vec2.hpp" +#include "vec3.hpp" #endif diff --git a/src/cppid/gm3d/detail/BasicRgba.hpp b/src/cppid/gm3d/detail/basic_rgba.hpp similarity index 100% rename from src/cppid/gm3d/detail/BasicRgba.hpp rename to src/cppid/gm3d/detail/basic_rgba.hpp diff --git a/src/cppid/gm3d/Mat3.hpp b/src/cppid/gm3d/mat3.hpp similarity index 99% rename from src/cppid/gm3d/Mat3.hpp rename to src/cppid/gm3d/mat3.hpp index d01b03c..8c0aaf3 100644 --- a/src/cppid/gm3d/Mat3.hpp +++ b/src/cppid/gm3d/mat3.hpp @@ -1,7 +1,7 @@ #ifndef MOLPHENE_M3D_MAT3_HPP #define MOLPHENE_M3D_MAT3_HPP -#include "Mat4.hpp" +#include "mat4.hpp" namespace cppid::gm3d { template diff --git a/src/cppid/gm3d/Mat4.hpp b/src/cppid/gm3d/mat4.hpp similarity index 99% rename from src/cppid/gm3d/Mat4.hpp rename to src/cppid/gm3d/mat4.hpp index 7a55a9c..ff76553 100644 --- a/src/cppid/gm3d/Mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -5,8 +5,8 @@ #include #include -#include "Vec2.hpp" -#include "Vec3.hpp" +#include "vec2.hpp" +#include "vec3.hpp" namespace cppid::gm3d { diff --git a/src/cppid/gm3d/Rgba.hpp b/src/cppid/gm3d/rgba.hpp similarity index 97% rename from src/cppid/gm3d/Rgba.hpp rename to src/cppid/gm3d/rgba.hpp index eee9557..35f7a78 100644 --- a/src/cppid/gm3d/Rgba.hpp +++ b/src/cppid/gm3d/rgba.hpp @@ -4,7 +4,7 @@ #include #include -#include "detail/BasicRgba.hpp" +#include "detail/basic_rgba.hpp" namespace cppid::gm3d { diff --git a/src/cppid/gm3d/Vec.hpp b/src/cppid/gm3d/vec.hpp similarity index 100% rename from src/cppid/gm3d/Vec.hpp rename to src/cppid/gm3d/vec.hpp diff --git a/src/cppid/gm3d/Vec2.hpp b/src/cppid/gm3d/vec2.hpp similarity index 89% rename from src/cppid/gm3d/Vec2.hpp rename to src/cppid/gm3d/vec2.hpp index 2786b00..d5762c6 100644 --- a/src/cppid/gm3d/Vec2.hpp +++ b/src/cppid/gm3d/vec2.hpp @@ -1,7 +1,7 @@ #ifndef CPPID_GM3D_VEC2_HPP #define CPPID_GM3D_VEC2_HPP -#include "Vec.hpp" +#include "vec.hpp" namespace cppid::gm3d { diff --git a/src/cppid/gm3d/Vec3.hpp b/src/cppid/gm3d/vec3.hpp similarity index 91% rename from src/cppid/gm3d/Vec3.hpp rename to src/cppid/gm3d/vec3.hpp index 11e97f0..82cbeff 100644 --- a/src/cppid/gm3d/Vec3.hpp +++ b/src/cppid/gm3d/vec3.hpp @@ -4,7 +4,7 @@ #include #include -#include "Vec.hpp" +#include "vec.hpp" namespace cppid::gm3d { diff --git a/test/matrix3.cpp b/test/matrix3.cpp index 6c20924..e9aeb9a 100644 --- a/test/matrix3.cpp +++ b/test/matrix3.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Mat3; using cppid::gm3d::Mat4; diff --git a/test/matrix4.cpp b/test/matrix4.cpp index b6c712a..a98bf05 100644 --- a/test/matrix4.cpp +++ b/test/matrix4.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using Mat4f = cppid::gm3d::Mat4; diff --git a/test/rgba_float.cpp b/test/rgba_float.cpp index e8322f2..8a348cb 100644 --- a/test/rgba_float.cpp +++ b/test/rgba_float.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using u8 = std::uint8_t; using Rgba8 = cppid::gm3d::Rgba; diff --git a/test/rgba_uint8.cpp b/test/rgba_uint8.cpp index 1139fd0..c87db5a 100644 --- a/test/rgba_uint8.cpp +++ b/test/rgba_uint8.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using Rgba8 = cppid::gm3d::Rgba; diff --git a/test/vector2.cpp b/test/vector2.cpp index 66858c1..bf29cc6 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Vec2; using Vec2f = Vec2; diff --git a/test/vector3.cpp b/test/vector3.cpp index 05dda9d..401ee47 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -4,7 +4,7 @@ #define CATCH_CONFIG_MAIN #include -#include +#include using cppid::gm3d::Vec3; using Vec3f = Vec3; From 4a2b70418be75775a555d65ae5cf8feae8fe5786 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Fri, 22 Mar 2019 23:34:09 +0800 Subject: [PATCH 05/19] refactor: change style of types name to lowercase_snake_case style --- src/cppid/gm3d/detail/basic_rgba.hpp | 38 ++++----- src/cppid/gm3d/mat3.hpp | 26 +++--- src/cppid/gm3d/mat4.hpp | 60 ++++++------- src/cppid/gm3d/rgba.hpp | 42 ++++----- src/cppid/gm3d/vec.hpp | 122 +++++++++++++-------------- src/cppid/gm3d/vec2.hpp | 2 +- src/cppid/gm3d/vec3.hpp | 5 +- test/matrix3.cpp | 18 ++-- test/matrix4.cpp | 12 +-- test/rgba_float.cpp | 34 ++++---- test/rgba_uint8.cpp | 24 +++--- test/vector2.cpp | 84 +++++++++--------- test/vector3.cpp | 94 ++++++++++----------- 13 files changed, 279 insertions(+), 282 deletions(-) diff --git a/src/cppid/gm3d/detail/basic_rgba.hpp b/src/cppid/gm3d/detail/basic_rgba.hpp index 9eb9326..849732e 100644 --- a/src/cppid/gm3d/detail/basic_rgba.hpp +++ b/src/cppid/gm3d/detail/basic_rgba.hpp @@ -4,23 +4,23 @@ namespace cppid::gm3d::detail { template -class BasicRgba { +class basic_rgba { public: - using Scalar = T; + using scalar_type = T; - BasicRgba() noexcept = default; + basic_rgba() noexcept = default; - explicit BasicRgba(Scalar s) noexcept - : BasicRgba{s, s, s, s} + explicit basic_rgba(scalar_type s) noexcept + : basic_rgba{s, s, s, s} { } - BasicRgba(Scalar s, Scalar a) noexcept - : BasicRgba{s, s, s, a} + basic_rgba(scalar_type s, scalar_type a) noexcept + : basic_rgba{s, s, s, a} { } - BasicRgba(Scalar r, Scalar g, Scalar b, Scalar a) noexcept + basic_rgba(scalar_type r, scalar_type g, scalar_type b, scalar_type a) noexcept : r_{r} , g_{g} , b_{b} @@ -29,68 +29,68 @@ class BasicRgba { } void - r(Scalar val) noexcept + r(scalar_type val) noexcept { r_ = val; } void - g(Scalar val) noexcept + g(scalar_type val) noexcept { g_ = val; } void - b(Scalar val) noexcept + b(scalar_type val) noexcept { b_ = val; } void - a(Scalar val) noexcept + a(scalar_type val) noexcept { a_ = val; } auto - r() const noexcept -> Scalar + r() const noexcept -> scalar_type { return r_; } auto - g() const noexcept -> Scalar + g() const noexcept -> scalar_type { return g_; } auto - b() const noexcept -> Scalar + b() const noexcept -> scalar_type { return b_; } auto - a() const noexcept -> Scalar + a() const noexcept -> scalar_type { return a_; } friend auto - operator==(const BasicRgba& lhs, const BasicRgba& rhs) noexcept -> bool + operator==(const basic_rgba& lhs, const basic_rgba& rhs) noexcept -> bool { return lhs.r() == rhs.r() && lhs.g() == rhs.g() && lhs.b() == rhs.b() && lhs.a() == rhs.a(); } friend auto - operator!=(const BasicRgba& lhs, const BasicRgba& rhs) noexcept -> bool + operator!=(const basic_rgba& lhs, const basic_rgba& rhs) noexcept -> bool { return !(lhs == rhs); } private: - Scalar r_, g_, b_, a_; + scalar_type r_, g_, b_, a_; }; } // namespace cppid::gm3d::detail diff --git a/src/cppid/gm3d/mat3.hpp b/src/cppid/gm3d/mat3.hpp index 8c0aaf3..2fa5013 100644 --- a/src/cppid/gm3d/mat3.hpp +++ b/src/cppid/gm3d/mat3.hpp @@ -5,17 +5,17 @@ namespace cppid::gm3d { template -struct Mat3 { +struct mat3 { T m[9]; - Mat3() noexcept = default; + mat3() noexcept = default; - explicit Mat3(T s) noexcept - : Mat3{s, 0, 0, 0, s, 0, 0, 0, s} + explicit mat3(T s) noexcept + : mat3{s, 0, 0, 0, s, 0, 0, 0, s} { } - Mat3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22) noexcept + mat3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22) noexcept : m{m00, m01, m02, m10, m11, m12, m20, m21, m22} { } @@ -23,8 +23,8 @@ struct Mat3 { template && !std::is_convertible_v>* = nullptr> - explicit Mat3(const Mat4& m4) noexcept - : Mat3(m4.m[0], + explicit mat3(const mat4& m4) noexcept + : mat3(m4.m[0], m4.m[1], m4.m[2], m4.m[4], @@ -39,8 +39,8 @@ struct Mat3 { template && std::is_convertible_v>* = nullptr> - Mat3(const Mat4& m4) noexcept - : Mat3(m4.m[0], + mat3(const mat4& m4) noexcept + : mat3(m4.m[0], m4.m[1], m4.m[2], m4.m[4], @@ -55,8 +55,8 @@ struct Mat3 { template && !std::is_convertible_v>* = nullptr> - explicit Mat3(const Mat3& m3) noexcept - : Mat3(m3.m[0], + explicit mat3(const mat3& m3) noexcept + : mat3(m3.m[0], m3.m[1], m3.m[2], m3.m[3], @@ -71,8 +71,8 @@ struct Mat3 { template && std::is_convertible_v>* = nullptr> - Mat3(const Mat3& m3) noexcept - : Mat3(m3.m[0], + mat3(const mat3& m3) noexcept + : mat3(m3.m[0], m3.m[1], m3.m[2], m3.m[3], diff --git a/src/cppid/gm3d/mat4.hpp b/src/cppid/gm3d/mat4.hpp index ff76553..0df6363 100644 --- a/src/cppid/gm3d/mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -11,17 +11,17 @@ namespace cppid::gm3d { template -struct Mat4 { +struct mat4 { T m[16]; - Mat4() noexcept = default; + mat4() noexcept = default; - explicit Mat4(T s) noexcept - : Mat4{s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, s} + explicit mat4(T s) noexcept + : mat4{s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, s} { } - Mat4(T m00, + mat4(T m00, T m01, T m02, T m03, @@ -59,8 +59,8 @@ struct Mat4 { template && !std::is_convertible_v>* = nullptr> - explicit Mat4(const Mat4& m) noexcept - : Mat4(m.m[0], + explicit mat4(const mat4& m) noexcept + : mat4(m.m[0], m.m[1], m.m[2], m.m[3], @@ -82,8 +82,8 @@ struct Mat4 { template && std::is_convertible_v>* = nullptr> - explicit Mat4(const Mat4& m) noexcept - : Mat4(m.m[0], + explicit mat4(const mat4& m) noexcept + : mat4(m.m[0], m.m[1], m.m[2], m.m[3], @@ -103,7 +103,7 @@ struct Mat4 { } auto - operator*=(const Mat4& m4) noexcept -> Mat4& + operator*=(const mat4& m4) noexcept -> mat4& { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], @@ -135,13 +135,13 @@ struct Mat4 { return *this; } - auto operator*(const Mat4& m4) const noexcept -> Mat4 + auto operator*(const mat4& m4) const noexcept -> mat4 { - return Mat4{*this} *= m4; + return mat4{*this} *= m4; } auto - operator*=(T s) noexcept -> Mat4& + operator*=(T s) noexcept -> mat4& { m[0] *= s; m[1] *= s; @@ -163,9 +163,9 @@ struct Mat4 { return *this; } - auto operator*(T s) const noexcept -> Mat4 + auto operator*(T s) const noexcept -> mat4 { - return Mat4{*this} *= s; + return mat4{*this} *= s; } void @@ -361,19 +361,19 @@ struct Mat4 { } auto - scale(T s) noexcept -> Mat4& + scale(T s) noexcept -> mat4& { return scale(s, s, s); } auto - scale(const Vec3& v) noexcept -> Mat4& + scale(const vec3& v) noexcept -> mat4& { return scale(v.x(), v.y(), v.z()); } auto - scale(T x, T y, T z) noexcept -> Mat4& + scale(T x, T y, T z) noexcept -> mat4& { m[0] *= x; m[5] *= y; @@ -382,13 +382,13 @@ struct Mat4 { } auto - identity() noexcept -> Mat4& + identity() noexcept -> mat4& { return *this = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; } auto - rotate(T a, const Vec3& origin) noexcept -> Mat4& + rotate(T a, const vec3& origin) noexcept -> mat4& { // zero rotation is nothing if(!a) { @@ -447,7 +447,7 @@ struct Mat4 { } auto - translate(T x, T y, T z) noexcept -> Mat4& + translate(T x, T y, T z) noexcept -> mat4& { const auto m03 = m[3]; const auto m13 = m[7]; @@ -473,13 +473,13 @@ struct Mat4 { } auto - translate(const Vec3& v) noexcept -> Mat4& + translate(const vec3& v) noexcept -> mat4& { return translate(v.x(), v.y(), v.z()); } auto - frustum(T l, T r, T b, T t, T n, T f) noexcept -> Mat4& + frustum(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 * n / (r - l); m[5] = 2 * n / (t - b); @@ -500,7 +500,7 @@ struct Mat4 { } auto - orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> Mat4& + orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 / (r - l); m[5] = 2 / (t - b); @@ -516,7 +516,7 @@ struct Mat4 { } auto - lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept -> Mat4& + lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept -> mat4& { auto fx = ex - lx; auto fy = ey - ly; @@ -562,14 +562,14 @@ struct Mat4 { } auto - lookat(Vec3 e, Vec3 l, Vec3 u) noexcept -> Mat4& + lookat(vec3 e, vec3 l, vec3 u) noexcept -> mat4& { return lookat( e.x(), e.y(), e.z(), l.x(), l.y(), l.z(), u.x(), u.y(), u.z()); } auto - perspective(T fov, T a, T n, T f) noexcept -> Mat4& + perspective(T fov, T a, T n, T f) noexcept -> mat4& { const auto t = std::tan(fov / 2) * n; const auto r = a * t; @@ -578,7 +578,7 @@ struct Mat4 { } auto - adjoint() noexcept -> Mat4& + adjoint() noexcept -> mat4& { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], @@ -628,7 +628,7 @@ struct Mat4 { } auto - inverse() noexcept -> Mat4& + inverse() noexcept -> mat4& { const auto det = determinant(); adjoint(); @@ -636,7 +636,7 @@ struct Mat4 { } auto - transpose() noexcept -> Mat4& + transpose() noexcept -> mat4& { *this = {m[0], m[4], diff --git a/src/cppid/gm3d/rgba.hpp b/src/cppid/gm3d/rgba.hpp index 35f7a78..02d4c99 100644 --- a/src/cppid/gm3d/rgba.hpp +++ b/src/cppid/gm3d/rgba.hpp @@ -9,52 +9,52 @@ namespace cppid::gm3d { template -class Rgba; +class rgba; template<> -class Rgba -: public detail::BasicRgba, std::uint8_t> { +class rgba +: public detail::basic_rgba, std::uint8_t> { public: - using Scalar = detail::BasicRgba, std::uint8_t>::Scalar; + using scalar_type = detail::basic_rgba, std::uint8_t>::scalar_type; - using detail::BasicRgba, std::uint8_t>::BasicRgba; + using detail::basic_rgba, std::uint8_t>::basic_rgba; - Rgba() noexcept = default; + rgba() noexcept = default; - Rgba(Scalar r, Scalar g, Scalar b) noexcept - : Rgba{r, g, b, 0xFF} + rgba(scalar_type r, scalar_type g, scalar_type b) noexcept + : rgba{r, g, b, 0xFF} { } }; template<> -class Rgba : public detail::BasicRgba, float> { +class rgba : public detail::basic_rgba, float> { public: - using Scalar = detail::BasicRgba, float>::Scalar; + using scalar_type = detail::basic_rgba, float>::scalar_type; - using detail::BasicRgba, float>::BasicRgba; + using detail::basic_rgba, float>::basic_rgba; - Rgba() noexcept = default; + rgba() noexcept = default; template>> - explicit Rgba(const Rgba& col) - : Rgba{col.r(), col.g(), col.b(), col.a()} + explicit rgba(const rgba& col) + : rgba{col.r(), col.g(), col.b(), col.a()} { } template>> - Rgba(T r, T g, T b, T a) noexcept - : Rgba{r / Scalar{255} * a / Scalar{255}, - g / Scalar{255} * a / Scalar{255}, - b / Scalar{255} * a / Scalar{255}, - a / Scalar{255}} + rgba(T r, T g, T b, T a) noexcept + : rgba{r / scalar_type{255} * a / scalar_type{255}, + g / scalar_type{255} * a / scalar_type{255}, + b / scalar_type{255} * a / scalar_type{255}, + a / scalar_type{255}} { } - Rgba(Scalar r, Scalar g, Scalar b) noexcept - : Rgba{r, g, b, 1} + rgba(scalar_type r, scalar_type g, scalar_type b) noexcept + : rgba{r, g, b, 1} { } }; diff --git a/src/cppid/gm3d/vec.hpp b/src/cppid/gm3d/vec.hpp index ccd3f22..ae0f58c 100644 --- a/src/cppid/gm3d/vec.hpp +++ b/src/cppid/gm3d/vec.hpp @@ -14,18 +14,18 @@ namespace cppid::gm3d { template -struct Vec { +struct vec { T elems[N]; - Vec() noexcept = default; + vec() noexcept = default; - explicit Vec(T s) noexcept - : Vec{s, std::make_index_sequence()} + explicit vec(T s) noexcept + : vec{s, std::make_index_sequence()} { } template> - Vec(T s, std::index_sequence) noexcept + vec(T s, std::index_sequence) noexcept : elems{(static_cast(Ns), s)...} { } @@ -33,7 +33,7 @@ struct Vec { template)>> - Vec(Us... args) noexcept + vec(Us... args) noexcept : elems{T(args)...} { } @@ -41,8 +41,8 @@ struct Vec { template< typename U, std::enable_if_t>* = nullptr> - explicit Vec(Vec v) noexcept - : Vec{v, std::make_index_sequence()} + explicit vec(vec v) noexcept + : vec{v, std::make_index_sequence()} { } @@ -51,7 +51,7 @@ struct Vec { std::size_t... Ns, std::enable_if_t<(sizeof...(Ns) == N) && detail::is_explicit_constructible_v>* = nullptr> - Vec(Vec v, std::index_sequence) noexcept + vec(vec v, std::index_sequence) noexcept : elems{v.elems[Ns]...} { } @@ -59,8 +59,8 @@ struct Vec { template< typename U, std::enable_if_t>* = nullptr> - Vec(Vec v) noexcept - : Vec{v, std::make_index_sequence()} + vec(vec v) noexcept + : vec{v, std::make_index_sequence()} { } @@ -69,83 +69,83 @@ struct Vec { std::size_t... Ns, std::enable_if_t<(sizeof...(Ns) == N) && detail::is_implicit_constructible_v>* = nullptr> - Vec(Vec v, std::index_sequence) noexcept + vec(vec v, std::index_sequence) noexcept : elems{T(v.elems[Ns])...} { } template>> auto - operator=(const Vec rhs) noexcept -> Vec& + operator=(const vec rhs) noexcept -> vec& { op_assign(rhs.elems, std::make_index_sequence()); return *this; } auto - operator+=(const Vec& rhs) noexcept -> Vec& + operator+=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); return *this; } auto - operator+=(T rhs) noexcept -> Vec& + operator+=(T rhs) noexcept -> vec& { op_assign(rhs, std::plus{}, std::make_index_sequence()); return *this; } auto - operator-=(const Vec& rhs) noexcept -> Vec& + operator-=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); return *this; } auto - operator-=(T rhs) noexcept -> Vec& + operator-=(T rhs) noexcept -> vec& { op_assign(rhs, std::minus{}, std::make_index_sequence()); return *this; } auto - operator*=(const Vec& rhs) noexcept -> Vec& + operator*=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::multiplies{}, std::make_index_sequence()); return *this; } auto - operator*=(T rhs) noexcept -> Vec& + operator*=(T rhs) noexcept -> vec& { op_assign(rhs, std::multiplies{}, std::make_index_sequence()); return *this; } auto - operator/=(const Vec& rhs) noexcept -> Vec& + operator/=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::divides{}, std::make_index_sequence()); return *this; } auto - operator/=(T rhs) noexcept -> Vec& + operator/=(T rhs) noexcept -> vec& { op_assign(rhs, std::divides{}, std::make_index_sequence()); return *this; } auto - operator==(const Vec& rhs) const noexcept -> bool + operator==(const vec& rhs) const noexcept -> bool { return is_equal(rhs.elems, std::make_index_sequence()); } auto - operator!=(const Vec& rhs) const noexcept -> bool + operator!=(const vec& rhs) const noexcept -> bool { return !((*this) == rhs); } @@ -203,7 +203,7 @@ struct Vec { } auto - dot(const Vec& other) const noexcept -> T + dot(const vec& other) const noexcept -> T { return dot(other, std::make_index_sequence()); } @@ -221,20 +221,20 @@ struct Vec { } auto - to_unit() const noexcept -> Vec + to_unit() const noexcept -> vec { return *this / magnitude(); } auto - reflect(const Vec& n) const noexcept -> Vec + reflect(const vec& n) const noexcept -> vec { return *this - 2 * dot(n) * n; } template* = nullptr> auto - cross(const Vec& other) const noexcept -> Vec + cross(const vec& other) const noexcept -> vec { return {elems[1] * other.elems[2] - elems[2] * other.elems[1], elems[2] * other.elems[0] - elems[0] * other.elems[2], @@ -242,7 +242,7 @@ struct Vec { } friend auto - operator+(const Vec& val) noexcept -> Vec + operator+(const vec& val) noexcept -> vec { return val; } @@ -250,26 +250,26 @@ struct Vec { template, T, U>>> friend auto - operator+(const Vec& lhs, const Vec& rhs) noexcept - -> Vec, T, U>, N> + operator+(const vec& lhs, const vec& rhs) noexcept + -> vec, T, U>, N> { return invoke_op{}(std::plus{}, lhs, rhs, std::make_index_sequence()); } friend auto - operator+(const Vec& lhs, T rhs) noexcept -> Vec + operator+(const vec& lhs, T rhs) noexcept -> vec { - return lhs + Vec{rhs}; + return lhs + vec{rhs}; } friend auto - operator+(T lhs, const Vec& rhs) noexcept -> Vec + operator+(T lhs, const vec& rhs) noexcept -> vec { - return Vec{lhs} + rhs; + return vec{lhs} + rhs; } friend auto - operator-(const Vec& lhs) noexcept -> Vec + operator-(const vec& lhs) noexcept -> vec { return invoke_op{}(std::negate{}, lhs, std::make_index_sequence()); } @@ -277,64 +277,64 @@ struct Vec { template, T, U>>> friend auto - operator-(const Vec& lhs, const Vec& rhs) noexcept - -> Vec, T, U>, N> + operator-(const vec& lhs, const vec& rhs) noexcept + -> vec, T, U>, N> { return invoke_op{}(std::minus{}, lhs, rhs, std::make_index_sequence()); } friend auto - operator-(const Vec& lhs, T rhs) noexcept -> Vec + operator-(const vec& lhs, T rhs) noexcept -> vec { - return lhs - Vec{rhs}; + return lhs - vec{rhs}; } friend auto - operator-(T lhs, const Vec& rhs) noexcept -> Vec + operator-(T lhs, const vec& rhs) noexcept -> vec { - return Vec{lhs} - rhs; + return vec{lhs} - rhs; } template< typename U, typename = std::enable_if_t, T, U>>> - friend auto operator*(const Vec& lhs, const Vec& rhs) noexcept - -> Vec, T, U>, N> + friend auto operator*(const vec& lhs, const vec& rhs) noexcept + -> vec, T, U>, N> { return invoke_op{}( std::multiplies{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator*(const Vec& lhs, T rhs) noexcept -> Vec + friend auto operator*(const vec& lhs, T rhs) noexcept -> vec { - return lhs * Vec{rhs}; + return lhs * vec{rhs}; } - friend auto operator*(T lhs, const Vec& rhs) noexcept -> Vec + friend auto operator*(T lhs, const vec& rhs) noexcept -> vec { - return Vec{lhs} * rhs; + return vec{lhs} * rhs; } template< typename U, typename = std::enable_if_t, T, U>>> friend auto - operator/(const Vec& lhs, const Vec& rhs) noexcept - -> Vec, T, U>, N> + operator/(const vec& lhs, const vec& rhs) noexcept + -> vec, T, U>, N> { return invoke_op{}(std::divides{}, lhs, rhs, std::make_index_sequence()); } friend auto - operator/(const Vec& lhs, T rhs) noexcept -> Vec + operator/(const vec& lhs, T rhs) noexcept -> vec { - return lhs / Vec{rhs}; + return lhs / vec{rhs}; } friend auto - operator/(T lhs, const Vec& rhs) noexcept -> Vec + operator/(T lhs, const vec& rhs) noexcept -> vec { - return Vec{lhs} / rhs; + return vec{lhs} / rhs; } private: @@ -342,9 +342,9 @@ struct Vec { template auto operator()(const P op, - const Vec& lhs, + const vec& lhs, std::index_sequence) const noexcept - -> Vec, N> + -> vec, N> { static_assert(sizeof...(Ns) == N); return {op(lhs.elems[Ns])...}; @@ -353,10 +353,10 @@ struct Vec { template auto operator()(const P op, - const Vec& lhs, - const Vec& rhs, + const vec& lhs, + const vec& rhs, std::index_sequence) const noexcept - -> Vec, N> + -> vec, N> { static_assert(sizeof...(Ns) == N); return {op(lhs.elems[Ns], rhs.elems[Ns])...}; @@ -393,14 +393,14 @@ struct Vec { template auto - negate(std::index_sequence) const noexcept -> Vec + negate(std::index_sequence) const noexcept -> vec { - return Vec{(-elems[Ns])...}; + return vec{(-elems[Ns])...}; } template auto - dot(const Vec& other, std::index_sequence) const noexcept -> T + dot(const vec& other, std::index_sequence) const noexcept -> T { return ((elems[Ns] * other.elems[Ns]) + ... + 0); } diff --git a/src/cppid/gm3d/vec2.hpp b/src/cppid/gm3d/vec2.hpp index d5762c6..053ff08 100644 --- a/src/cppid/gm3d/vec2.hpp +++ b/src/cppid/gm3d/vec2.hpp @@ -6,7 +6,7 @@ namespace cppid::gm3d { template -using Vec2 = Vec; +using vec2 = vec; } // namespace cppid::gm3d diff --git a/src/cppid/gm3d/vec3.hpp b/src/cppid/gm3d/vec3.hpp index 82cbeff..22aa39c 100644 --- a/src/cppid/gm3d/vec3.hpp +++ b/src/cppid/gm3d/vec3.hpp @@ -1,15 +1,12 @@ #ifndef CPPID_GM3D_VEC3_HPP #define CPPID_GM3D_VEC3_HPP -#include -#include - #include "vec.hpp" namespace cppid::gm3d { template -using Vec3 = Vec; +using vec3 = vec; } // namespace cppid::gm3d diff --git a/test/matrix3.cpp b/test/matrix3.cpp index e9aeb9a..a516d3d 100644 --- a/test/matrix3.cpp +++ b/test/matrix3.cpp @@ -6,21 +6,21 @@ #include -using cppid::gm3d::Mat3; -using cppid::gm3d::Mat4; -using Mat3f = Mat3; +using cppid::gm3d::mat3; +using cppid::gm3d::mat4; +using mat3f = mat3; TEST_CASE("float_matrix3_test traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Mat3f) == (sizeof(float) * 9)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(mat3f) == (sizeof(float) * 9)); } TEST_CASE("float_matrix3_test initialization") { { - auto mat = Mat3f{1}; + auto mat = mat3f{1}; REQUIRE(mat.m00() == 1.0f); REQUIRE(mat.m01() == 0.0f); REQUIRE(mat.m02() == 0.0f); @@ -35,7 +35,7 @@ TEST_CASE("float_matrix3_test initialization") } { auto mat = - Mat3f{0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f, 20.0f, 21.0f, 22.0f}; + mat3f{0.0f, 1.0f, 2.0f, 10.0f, 11.0f, 12.0f, 20.0f, 21.0f, 22.0f}; REQUIRE(mat.m00() == 0.0f); REQUIRE(mat.m01() == 1.0f); @@ -50,7 +50,7 @@ TEST_CASE("float_matrix3_test initialization") REQUIRE(mat.m22() == 22.0f); } { - auto mat = Mat3f{Mat4{1}}; + auto mat = mat3f{mat4{1}}; REQUIRE(mat.m00() == 1.0f); REQUIRE(mat.m01() == 0.0f); diff --git a/test/matrix4.cpp b/test/matrix4.cpp index a98bf05..50019a4 100644 --- a/test/matrix4.cpp +++ b/test/matrix4.cpp @@ -6,19 +6,19 @@ #include -using Mat4f = cppid::gm3d::Mat4; +using mat4f = cppid::gm3d::mat4; TEST_CASE("float_matrix4_test traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Mat4f) == (sizeof(float) * 16)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(mat4f) == (sizeof(float) * 16)); } TEST_CASE("float_matrix4_test initialization") { { - auto mat = Mat4f{1}; + auto mat = mat4f{1}; REQUIRE(mat.m00() == 1.0f); REQUIRE(mat.m01() == 0.0f); REQUIRE(mat.m02() == 0.0f); @@ -40,7 +40,7 @@ TEST_CASE("float_matrix4_test initialization") REQUIRE(mat.m33() == 1.0f); } { - auto mat = Mat4f{0.0f, + auto mat = mat4f{0.0f, 1.0f, 2.0f, 3.0f, diff --git a/test/rgba_float.cpp b/test/rgba_float.cpp index 8a348cb..baa7924 100644 --- a/test/rgba_float.cpp +++ b/test/rgba_float.cpp @@ -7,63 +7,63 @@ #include using u8 = std::uint8_t; -using Rgba8 = cppid::gm3d::Rgba; -using Rgbaf = cppid::gm3d::Rgba; +using rgba8 = cppid::gm3d::rgba; +using rgbaf = cppid::gm3d::rgba; TEST_CASE("rgba_uint8 traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Rgbaf) == (sizeof(float) * 4)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(rgbaf) == (sizeof(float) * 4)); } TEST_CASE("rgba_uint8 initialization") { { - auto col = Rgbaf{0}; + auto col = rgbaf{0}; REQUIRE(col.r() == 0.0f); REQUIRE(col.g() == 0.0f); REQUIRE(col.b() == 0.0f); REQUIRE(col.a() == 0.0f); } { - auto col = Rgbaf{0.4, 0.4}; + auto col = rgbaf{0.4, 0.4}; REQUIRE(col.r() == Approx(0.4f)); REQUIRE(col.g() == Approx(0.4f)); REQUIRE(col.b() == Approx(0.4f)); REQUIRE(col.a() == Approx(0.4f)); } { - auto col = Rgbaf{0.6, 0.4, 1.8}; + auto col = rgbaf{0.6, 0.4, 1.8}; REQUIRE(col.r() == Approx(0.6f)); REQUIRE(col.g() == Approx(0.4f)); REQUIRE(col.b() == Approx(1.8f)); REQUIRE(col.a() == Approx(1.0f)); } { - auto col = Rgbaf{0.6, 0.4, 1.8, 1.0}; + auto col = rgbaf{0.6, 0.4, 1.8, 1.0}; REQUIRE(col.r() == Approx(0.6f)); REQUIRE(col.g() == Approx(0.4f)); REQUIRE(col.b() == Approx(1.8f)); REQUIRE(col.a() == Approx(1.0f)); } { - auto col = Rgbaf{u8{45}, u8{201}, u8{99}, u8{255}}; + auto col = rgbaf{u8{45}, u8{201}, u8{99}, u8{255}}; REQUIRE(col.r() == Approx(0.176471)); REQUIRE(col.g() == Approx(0.788235)); REQUIRE(col.b() == Approx(0.388235)); REQUIRE(col.a() == Approx(1.0)); } { - auto col = Rgbaf{Rgba8{45, 201, 99, 255}}; + auto col = rgbaf{rgba8{45, 201, 99, 255}}; REQUIRE(col.r() == Approx(0.176471)); REQUIRE(col.g() == Approx(0.788235)); REQUIRE(col.b() == Approx(0.388235)); REQUIRE(col.a() == Approx(1.0)); } { - auto cu8 = Rgba8{45, 201, 99, 255}; - auto col = Rgbaf{cu8}; + auto cu8 = rgba8{45, 201, 99, 255}; + auto col = rgbaf{cu8}; REQUIRE(col.r() == Approx(0.176471)); REQUIRE(col.g() == Approx(0.788235)); REQUIRE(col.b() == Approx(0.388235)); @@ -73,10 +73,10 @@ TEST_CASE("rgba_uint8 initialization") TEST_CASE("rgba_uint8 equality comparable") { - auto cola = Rgbaf{0.6, 0.4, 1.8, 1.0}; - auto colb = Rgbaf{0.6, 0.4, 1.8, 1.0}; - auto colc = Rgbaf{0.6, 0.4, 1.8, 1.0}; - auto cold = Rgbaf{0, 0, 0, 0}; + auto cola = rgbaf{0.6, 0.4, 1.8, 1.0}; + auto colb = rgbaf{0.6, 0.4, 1.8, 1.0}; + auto colc = rgbaf{0.6, 0.4, 1.8, 1.0}; + auto cold = rgbaf{0, 0, 0, 0}; REQUIRE(cola == cola); REQUIRE(cola == colb); diff --git a/test/rgba_uint8.cpp b/test/rgba_uint8.cpp index c87db5a..8d3fdee 100644 --- a/test/rgba_uint8.cpp +++ b/test/rgba_uint8.cpp @@ -6,40 +6,40 @@ #include -using Rgba8 = cppid::gm3d::Rgba; +using rgba8 = cppid::gm3d::rgba; TEST_CASE("rgba_uint8 traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Rgba8) == (sizeof(std::uint8_t) * 4)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(rgba8) == (sizeof(std::uint8_t) * 4)); } TEST_CASE("rgba_uint8 initialization") { { - auto col = Rgba8{0}; + auto col = rgba8{0}; REQUIRE(col.r() == 0); REQUIRE(col.g() == 0); REQUIRE(col.b() == 0); REQUIRE(col.a() == 0); } { - auto col = Rgba8{0xFF, 0x7F}; + auto col = rgba8{0xFF, 0x7F}; REQUIRE(col.r() == 0xFF); REQUIRE(col.g() == 0xFF); REQUIRE(col.b() == 0xFF); REQUIRE(col.a() == 0x7F); } { - auto col = Rgba8{0xFF, 0x7F, 0x50}; + auto col = rgba8{0xFF, 0x7F, 0x50}; REQUIRE(col.r() == 0xFF); REQUIRE(col.g() == 0x7F); REQUIRE(col.b() == 0x50); REQUIRE(col.a() == 255); } { - auto col = Rgba8{0xFF, 0x7F, 0x50, 21}; + auto col = rgba8{0xFF, 0x7F, 0x50, 21}; REQUIRE(col.r() == 0xFF); REQUIRE(col.g() == 0x7F); REQUIRE(col.b() == 0x50); @@ -49,10 +49,10 @@ TEST_CASE("rgba_uint8 initialization") TEST_CASE("rgba_uint8 equality comparable") { - auto cola = Rgba8{0xFF, 0x7F, 0x50, 0x00}; - auto colb = Rgba8{0xFF, 0x7F, 0x50, 0x00}; - auto colc = Rgba8{0xFF, 0x7F, 0x50, 0x00}; - auto cold = Rgba8{0, 0, 0, 0}; + auto cola = rgba8{0xFF, 0x7F, 0x50, 0x00}; + auto colb = rgba8{0xFF, 0x7F, 0x50, 0x00}; + auto colc = rgba8{0xFF, 0x7F, 0x50, 0x00}; + auto cold = rgba8{0, 0, 0, 0}; REQUIRE(cola == cola); REQUIRE(cola == colb); diff --git a/test/vector2.cpp b/test/vector2.cpp index bf29cc6..9a8cebf 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -6,47 +6,47 @@ #include -using cppid::gm3d::Vec2; -using Vec2f = Vec2; +using cppid::gm3d::vec2; +using vec2f = vec2; TEST_CASE("float_vector2_test traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Vec2f) == (sizeof(float) * 2)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(vec2f) == (sizeof(float) * 2)); } TEST_CASE("float_vector2_test initialization") { { - auto vt = Vec2f{0}; + auto vt = vec2f{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); } { - auto vt = Vec2f{1.5, 2.2}; + auto vt = vec2f{1.5, 2.2}; REQUIRE(vt.x() == 1.5f); REQUIRE(vt.y() == 2.2f); } { - auto vt = Vec2f{Vec2f{1.5, 2.3}}; + auto vt = vec2f{vec2f{1.5, 2.3}}; REQUIRE(vt.x() == 1.5f); REQUIRE(vt.y() == 2.3f); } { - auto vt = Vec2f{Vec2{0}}; + auto vt = vec2f{vec2{0}}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); } { - auto vt = Vec2f{0}; - vt = Vec2{0}; + auto vt = vec2f{0}; + vt = vec2{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); } { - auto vd = Vec2{0}; - Vec2f vt = vd; + auto vd = vec2{0}; + vec2f vt = vd; CHECK(vt.x() == 0.0f); CHECK(vt.y() == 0.0f); } @@ -54,39 +54,39 @@ TEST_CASE("float_vector2_test initialization") TEST_CASE("float_vector2_test comparison") { - REQUIRE((Vec2f{0} == Vec2f{0, 0})); - REQUIRE((Vec2f{3.5} == Vec2f{3.5, 3.5})); - REQUIRE((Vec2f{-.5} == Vec2f{-.5, -.5})); + REQUIRE((vec2f{0} == vec2f{0, 0})); + REQUIRE((vec2f{3.5} == vec2f{3.5, 3.5})); + REQUIRE((vec2f{-.5} == vec2f{-.5, -.5})); - REQUIRE((Vec2f{-.5} != Vec2f{-.5, -.1})); + REQUIRE((vec2f{-.5} != vec2f{-.5, -.1})); } TEST_CASE("float_vector2_test addition") { { - auto vt = Vec2f{-10.4, 0.4}; - vt += Vec2f{0}; + auto vt = vec2f{-10.4, 0.4}; + vt += vec2f{0}; REQUIRE(vt.x() == Approx(-10.4f)); REQUIRE(vt.y() == Approx(0.4f)); } { - auto vt = Vec2f{10.4, -2.2}; + auto vt = vec2f{10.4, -2.2}; vt += 3.2; REQUIRE(vt.x() == Approx(13.6f)); REQUIRE(vt.y() == Approx(1.0f)); } { - auto vt = Vec2f{0} + Vec2f{2.5, 0.3}; + auto vt = vec2f{0} + vec2f{2.5, 0.3}; REQUIRE(vt.x() == Approx(2.5f)); REQUIRE(vt.y() == Approx(0.3f)); } { - auto vt = Vec2f{-1., 0} + 0.2; + auto vt = vec2f{-1., 0} + 0.2; REQUIRE(vt.x() == Approx(-0.8f)); REQUIRE(vt.y() == Approx(0.2f)); } { - auto vt = 0.2 + Vec2f{-1., 0}; + auto vt = 0.2 + vec2f{-1., 0}; REQUIRE(vt.x() == Approx(-0.8f)); REQUIRE(vt.y() == Approx(0.2f)); } @@ -95,29 +95,29 @@ TEST_CASE("float_vector2_test addition") TEST_CASE("float_vector2_test subtraction") { { - auto vt = Vec2f{0}; - vt -= Vec2f(-10.4, 0.4); + auto vt = vec2f{0}; + vt -= vec2f(-10.4, 0.4); REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } { - auto vt = Vec2f{1.5, 2.2}; + auto vt = vec2f{1.5, 2.2}; vt -= 3.2; REQUIRE(vt.x() == Approx(-1.7f)); REQUIRE(vt.y() == Approx(-1.f)); } { - auto vt = Vec2f{1.5, 2.2} - Vec2f{0}; + auto vt = vec2f{1.5, 2.2} - vec2f{0}; REQUIRE(vt.x() == Approx(1.5f)); REQUIRE(vt.y() == Approx(2.2f)); } { - auto vt = Vec2f{2.5, -0.3} - 1; + auto vt = vec2f{2.5, -0.3} - 1; REQUIRE(vt.x() == Approx(1.5f)); REQUIRE(vt.y() == Approx(-1.3f)); } { - auto vt = 1u - Vec2f{2.5, -0.3}; + auto vt = 1u - vec2f{2.5, -0.3}; REQUIRE(vt.x() == Approx(-1.5f)); REQUIRE(vt.y() == Approx(1.3f)); } @@ -126,29 +126,29 @@ TEST_CASE("float_vector2_test subtraction") TEST_CASE("float_vector2_test multiplication") { { - auto vt = Vec2f(-10.4, 0.4); - vt *= Vec2f{-1}; + auto vt = vec2f(-10.4, 0.4); + vt *= vec2f{-1}; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } { - auto vt = Vec2f(-10.4, 0.4); + auto vt = vec2f(-10.4, 0.4); vt *= -1l; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } { - auto vt = Vec2f(-10.4, 0.4) * Vec2f{-1}; + auto vt = vec2f(-10.4, 0.4) * vec2f{-1}; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } { - auto vt = Vec2f(-10.4, 0.4) * -1.0; + auto vt = vec2f(-10.4, 0.4) * -1.0; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } { - auto vt = -1 * Vec2f(-10.4, 0.4); + auto vt = -1 * vec2f(-10.4, 0.4); REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); } @@ -157,29 +157,29 @@ TEST_CASE("float_vector2_test multiplication") TEST_CASE("float_vector2_test division") { { - auto vt = Vec2f(-10.0, 0.5); - vt /= Vec2f{2}; + auto vt = vec2f(-10.0, 0.5); + vt /= vec2f{2}; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); } { - auto vt = Vec2f(-10.0, 0.5); + auto vt = vec2f(-10.0, 0.5); vt /= 2ull; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); } { - auto vt = Vec2f(-10.0, 0.5) / Vec2f{2}; + auto vt = vec2f(-10.0, 0.5) / vec2f{2}; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); } { - auto vt = Vec2f(-10.0, 0.5) / 2; + auto vt = vec2f(-10.0, 0.5) / 2; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); } { - auto vt = 2 / Vec2f(-10.0, 0.5); + auto vt = 2 / vec2f(-10.0, 0.5); REQUIRE(vt.x() == Approx(-0.2f)); REQUIRE(vt.y() == Approx(4.0f)); } @@ -188,7 +188,7 @@ TEST_CASE("float_vector2_test division") TEST_CASE("float_vector2_test reflect") { { - auto d = Vec2f{10, -2}; + auto d = vec2f{10, -2}; auto r = d.reflect({0, 1}); REQUIRE(r.x() == Approx(10.f)); REQUIRE(r.y() == Approx(2.0f)); diff --git a/test/vector3.cpp b/test/vector3.cpp index 401ee47..53d142a 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -6,52 +6,52 @@ #include -using cppid::gm3d::Vec3; -using Vec3f = Vec3; +using cppid::gm3d::vec3; +using vec3f = vec3; TEST_CASE("float_vector3_test traits") { - REQUIRE(std::is_trivial_v); - REQUIRE(std::is_standard_layout_v); - REQUIRE(sizeof(Vec3f) == (sizeof(float) * 3)); + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(vec3f) == (sizeof(float) * 3)); } TEST_CASE("float_vector3_test initialization") { { - auto vt = Vec3f{0}; + auto vt = vec3f{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); REQUIRE(vt.z() == 0.0f); } { - auto vt = Vec3f{1.5, 2.2, 8.9}; + auto vt = vec3f{1.5, 2.2, 8.9}; REQUIRE(vt.x() == 1.5f); REQUIRE(vt.y() == 2.2f); REQUIRE(vt.z() == 8.9f); } { - auto vt = Vec3f{Vec3f{1.5, 2.3, 6.4}}; + auto vt = vec3f{vec3f{1.5, 2.3, 6.4}}; REQUIRE(vt.x() == 1.5f); REQUIRE(vt.y() == 2.3f); REQUIRE(vt.z() == 6.4f); } { - auto vt = Vec3f{Vec3{0}}; + auto vt = vec3f{vec3{0}}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); REQUIRE(vt.z() == 0.0f); } { - auto vt = Vec3f{0}; - vt = Vec3{0}; + auto vt = vec3f{0}; + vt = vec3{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); REQUIRE(vt.z() == 0.0f); } { - auto vd = Vec3{0}; - Vec3f vt = vd; + auto vd = vec3{0}; + vec3f vt = vd; CHECK(vt.x() == 0.0f); CHECK(vt.y() == 0.0f); CHECK(vt.z() == 0.0f); @@ -60,24 +60,24 @@ TEST_CASE("float_vector3_test initialization") TEST_CASE("float_vector3_test comparison") { - REQUIRE((Vec3f{0} == Vec3f{0, 0, 0})); - REQUIRE((Vec3f{3.5} == Vec3f{3.5, 3.5, 3.5})); - REQUIRE((Vec3f{-.5} == Vec3f{-.5, -.5, -.5})); + REQUIRE((vec3f{0} == vec3f{0, 0, 0})); + REQUIRE((vec3f{3.5} == vec3f{3.5, 3.5, 3.5})); + REQUIRE((vec3f{-.5} == vec3f{-.5, -.5, -.5})); - REQUIRE((Vec3f{-.5} != Vec3f{-.5, -.1, -.5})); + REQUIRE((vec3f{-.5} != vec3f{-.5, -.1, -.5})); } TEST_CASE("float_vector3_test addition") { { - auto vt = Vec3f{-10.4, 0.4, -15.4}; - vt += Vec3f{0}; + auto vt = vec3f{-10.4, 0.4, -15.4}; + vt += vec3f{0}; REQUIRE(vt.x() == Approx(-10.4f)); REQUIRE(vt.y() == Approx(0.4f)); REQUIRE(vt.z() == Approx(-15.4f)); } { - auto vt = Vec3f{10.4, -2.2, 5.5}; + auto vt = vec3f{10.4, -2.2, 5.5}; vt += 3.2; REQUIRE(vt.x() == Approx(13.6f)); REQUIRE(vt.y() == Approx(1.0f)); @@ -85,25 +85,25 @@ TEST_CASE("float_vector3_test addition") ; } { - auto vt = Vec3f{0} + Vec3f{2.5, 0.3, 7.4}; + auto vt = vec3f{0} + vec3f{2.5, 0.3, 7.4}; REQUIRE(vt.x() == Approx(2.5f)); REQUIRE(vt.y() == Approx(0.3f)); REQUIRE(vt.z() == Approx(7.4f)); } { - auto vt = Vec3f{-1., 0, 1} + 0.2; + auto vt = vec3f{-1., 0, 1} + 0.2; REQUIRE(vt.x() == Approx(-0.8f)); REQUIRE(vt.y() == Approx(0.2f)); REQUIRE(vt.z() == Approx(1.2f)); } { - auto vt = 0.2 + Vec3f{-1., 0, 1}; + auto vt = 0.2 + vec3f{-1., 0, 1}; REQUIRE(vt.x() == Approx(-0.8f)); REQUIRE(vt.y() == Approx(0.2f)); REQUIRE(vt.z() == Approx(1.2f)); } { - auto vt = Vec3{0} + Vec3{0}; + auto vt = vec3{0} + vec3{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -113,39 +113,39 @@ TEST_CASE("float_vector3_test addition") TEST_CASE("float_vector3_test subtraction") { { - auto vt = Vec3f{0}; - vt -= Vec3f(-10.4, 0.4, -15.4); + auto vt = vec3f{0}; + vt -= vec3f(-10.4, 0.4, -15.4); REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = Vec3f{1.5, 2.2, 8.9}; + auto vt = vec3f{1.5, 2.2, 8.9}; vt -= 3.2; REQUIRE(vt.x() == Approx(-1.7f)); REQUIRE(vt.y() == Approx(-1.f)); REQUIRE(vt.z() == Approx(5.7f)); } { - auto vt = Vec3f{1.5, 2.2, 8.9} - Vec3f{0}; + auto vt = vec3f{1.5, 2.2, 8.9} - vec3f{0}; REQUIRE(vt.x() == Approx(1.5f)); REQUIRE(vt.y() == Approx(2.2f)); REQUIRE(vt.z() == Approx(8.9f)); } { - auto vt = Vec3f{2.5, -0.3, 7.4} - 1; + auto vt = vec3f{2.5, -0.3, 7.4} - 1; REQUIRE(vt.x() == Approx(1.5f)); REQUIRE(vt.y() == Approx(-1.3f)); REQUIRE(vt.z() == Approx(6.4f)); } { - auto vt = 1u - Vec3f{2.5, -0.3, 7.4}; + auto vt = 1u - vec3f{2.5, -0.3, 7.4}; REQUIRE(vt.x() == Approx(-1.5f)); REQUIRE(vt.y() == Approx(1.3f)); REQUIRE(vt.z() == Approx(-6.4f)); } { - auto vt = Vec3{0} - Vec3{0}; + auto vt = vec3{0} - vec3{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -155,39 +155,39 @@ TEST_CASE("float_vector3_test subtraction") TEST_CASE("float_vector3_test multiplication") { { - auto vt = Vec3f(-10.4, 0.4, -15.4); - vt *= Vec3f{-1}; + auto vt = vec3f(-10.4, 0.4, -15.4); + vt *= vec3f{-1}; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = Vec3f(-10.4, 0.4, -15.4); + auto vt = vec3f(-10.4, 0.4, -15.4); vt *= -1l; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = Vec3f(-10.4, 0.4, -15.4) * Vec3f{-1}; + auto vt = vec3f(-10.4, 0.4, -15.4) * vec3f{-1}; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = Vec3f(-10.4, 0.4, -15.4) * -1.0; + auto vt = vec3f(-10.4, 0.4, -15.4) * -1.0; REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = -1 * Vec3f(-10.4, 0.4, -15.4); + auto vt = -1 * vec3f(-10.4, 0.4, -15.4); REQUIRE(vt.x() == Approx(10.4f)); REQUIRE(vt.y() == Approx(-0.4f)); REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = Vec3{0} * Vec3{0}; + auto vt = vec3{0} * vec3{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -197,39 +197,39 @@ TEST_CASE("float_vector3_test multiplication") TEST_CASE("float_vector3_test division") { { - auto vt = Vec3f(-10.0, 0.5, 2); - vt /= Vec3f{2}; + auto vt = vec3f(-10.0, 0.5, 2); + vt /= vec3f{2}; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = Vec3f(-10.0, 0.5, 2); + auto vt = vec3f(-10.0, 0.5, 2); vt /= 2ull; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = Vec3f(-10.0, 0.5, 2) / Vec3f{2}; + auto vt = vec3f(-10.0, 0.5, 2) / vec3f{2}; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = Vec3f(-10.0, 0.5, 2) / 2; + auto vt = vec3f(-10.0, 0.5, 2) / 2; REQUIRE(vt.x() == Approx(-5.0f)); REQUIRE(vt.y() == Approx(0.25f)); REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = 2 / Vec3f(-10.0, 0.5, 2); + auto vt = 2 / vec3f(-10.0, 0.5, 2); REQUIRE(vt.x() == Approx(-0.2f)); REQUIRE(vt.y() == Approx(4.0f)); REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = Vec3{0} / Vec3{1}; + auto vt = vec3{0} / vec3{1}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -239,7 +239,7 @@ TEST_CASE("float_vector3_test division") TEST_CASE("float_vector3_test reflect") { { - auto d = Vec3f{10, -2, 0}; + auto d = vec3f{10, -2, 0}; auto r = d.reflect({0, 1, 0}); REQUIRE(r.x() == Approx(10.f)); REQUIRE(r.y() == Approx(2.0f)); @@ -250,7 +250,7 @@ TEST_CASE("float_vector3_test reflect") TEST_CASE("float_vector3_test to_unit") { { - auto vt = Vec3f(-10.0, 0.5, 2) / 2; + auto vt = vec3f(-10.0, 0.5, 2) / 2; auto n = vt.to_unit(); REQUIRE(n.magnitude() == Approx(1.0f)); } From 4eb6b4d8f713f0bf58606a852010709a75aba88f Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 09:52:12 +0800 Subject: [PATCH 06/19] style: change clang-format configuration and apply format to all files --- .clang-format | 2 +- src/cppid/gm3d/detail/basic_rgba.hpp | 37 +++---- src/cppid/gm3d/mat3.hpp | 54 ++++------ src/cppid/gm3d/mat4.hpp | 154 +++++++++------------------ src/cppid/gm3d/rgba.hpp | 3 +- src/cppid/gm3d/vec.hpp | 140 +++++++++--------------- test/matrix4.cpp | 2 +- 7 files changed, 139 insertions(+), 253 deletions(-) diff --git a/.clang-format b/.clang-format index 994520f..b6c9baf 100644 --- a/.clang-format +++ b/.clang-format @@ -13,7 +13,7 @@ AllowShortFunctionsOnASingleLine: None AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: All +AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false AlwaysBreakTemplateDeclarations: Yes BinPackArguments: false diff --git a/src/cppid/gm3d/detail/basic_rgba.hpp b/src/cppid/gm3d/detail/basic_rgba.hpp index 849732e..6b9bc11 100644 --- a/src/cppid/gm3d/detail/basic_rgba.hpp +++ b/src/cppid/gm3d/detail/basic_rgba.hpp @@ -20,7 +20,10 @@ class basic_rgba { { } - basic_rgba(scalar_type r, scalar_type g, scalar_type b, scalar_type a) noexcept + basic_rgba(scalar_type r, + scalar_type g, + scalar_type b, + scalar_type a) noexcept : r_{r} , g_{g} , b_{b} @@ -28,63 +31,55 @@ class basic_rgba { { } - void - r(scalar_type val) noexcept + void r(scalar_type val) noexcept { r_ = val; } - void - g(scalar_type val) noexcept + void g(scalar_type val) noexcept { g_ = val; } - void - b(scalar_type val) noexcept + void b(scalar_type val) noexcept { b_ = val; } - void - a(scalar_type val) noexcept + void a(scalar_type val) noexcept { a_ = val; } - auto - r() const noexcept -> scalar_type + auto r() const noexcept -> scalar_type { return r_; } - auto - g() const noexcept -> scalar_type + auto g() const noexcept -> scalar_type { return g_; } - auto - b() const noexcept -> scalar_type + auto b() const noexcept -> scalar_type { return b_; } - auto - a() const noexcept -> scalar_type + auto a() const noexcept -> scalar_type { return a_; } - friend auto - operator==(const basic_rgba& lhs, const basic_rgba& rhs) noexcept -> bool + friend auto operator==(const basic_rgba& lhs, const basic_rgba& rhs) noexcept + -> bool { return lhs.r() == rhs.r() && lhs.g() == rhs.g() && lhs.b() == rhs.b() && lhs.a() == rhs.a(); } - friend auto - operator!=(const basic_rgba& lhs, const basic_rgba& rhs) noexcept -> bool + friend auto operator!=(const basic_rgba& lhs, const basic_rgba& rhs) noexcept + -> bool { return !(lhs == rhs); } diff --git a/src/cppid/gm3d/mat3.hpp b/src/cppid/gm3d/mat3.hpp index 2fa5013..041d6ec 100644 --- a/src/cppid/gm3d/mat3.hpp +++ b/src/cppid/gm3d/mat3.hpp @@ -84,110 +84,92 @@ struct mat3 { { } - void - m00(T val) noexcept + void m00(T val) noexcept { m[0] = val; } - void - m01(T val) noexcept + void m01(T val) noexcept { m[1] = val; } - void - m02(T val) noexcept + void m02(T val) noexcept { m[2] = val; } - void - m10(T val) noexcept + void m10(T val) noexcept { m[3] = val; } - void - m11(T val) noexcept + void m11(T val) noexcept { m[4] = val; } - void - m12(T val) noexcept + void m12(T val) noexcept { m[5] = val; } - void - m20(T val) noexcept + void m20(T val) noexcept { m[6] = val; } - void - m21(T val) noexcept + void m21(T val) noexcept { m[7] = val; } - void - m22(T val) noexcept + void m22(T val) noexcept { m[8] = val; } - auto - m00() const noexcept -> T + auto m00() const noexcept -> T { return m[0]; } - auto - m01() const noexcept -> T + auto m01() const noexcept -> T { return m[1]; } - auto - m02() const noexcept -> T + auto m02() const noexcept -> T { return m[2]; } - auto - m10() const noexcept -> T + auto m10() const noexcept -> T { return m[3]; } - auto - m11() const noexcept -> T + auto m11() const noexcept -> T { return m[4]; } - auto - m12() const noexcept -> T + auto m12() const noexcept -> T { return m[5]; } - auto - m20() const noexcept -> T + auto m20() const noexcept -> T { return m[6]; } - auto - m21() const noexcept -> T + auto m21() const noexcept -> T { return m[7]; } - auto - m22() const noexcept -> T + auto m22() const noexcept -> T { return m[8]; } diff --git a/src/cppid/gm3d/mat4.hpp b/src/cppid/gm3d/mat4.hpp index 0df6363..447fd55 100644 --- a/src/cppid/gm3d/mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -102,8 +102,7 @@ struct mat4 { { } - auto - operator*=(const mat4& m4) noexcept -> mat4& + auto operator*=(const mat4& m4) noexcept -> mat4& { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], @@ -140,8 +139,7 @@ struct mat4 { return mat4{*this} *= m4; } - auto - operator*=(T s) noexcept -> mat4& + auto operator*=(T s) noexcept -> mat4& { m[0] *= s; m[1] *= s; @@ -168,212 +166,177 @@ struct mat4 { return mat4{*this} *= s; } - void - m00(T val) noexcept + void m00(T val) noexcept { m[0] = val; } - void - m01(T val) noexcept + void m01(T val) noexcept { m[1] = val; } - void - m02(T val) noexcept + void m02(T val) noexcept { m[2] = val; } - void - m03(T val) noexcept + void m03(T val) noexcept { m[3] = val; } - void - m10(T val) noexcept + void m10(T val) noexcept { m[4] = val; } - void - m11(T val) noexcept + void m11(T val) noexcept { m[5] = val; } - void - m12(T val) noexcept + void m12(T val) noexcept { m[6] = val; } - void - m13(T val) noexcept + void m13(T val) noexcept { m[7] = val; } - void - m20(T val) noexcept + void m20(T val) noexcept { m[8] = val; } - void - m21(T val) noexcept + void m21(T val) noexcept { m[9] = val; } - void - m22(T val) noexcept + void m22(T val) noexcept { m[10] = val; } - void - m23(T val) noexcept + void m23(T val) noexcept { m[11] = val; } - void - m30(T val) noexcept + void m30(T val) noexcept { m[12] = val; } - void - m31(T val) noexcept + void m31(T val) noexcept { m[13] = val; } - void - m32(T val) noexcept + void m32(T val) noexcept { m[14] = val; } - void - m33(T val) noexcept + void m33(T val) noexcept { m[15] = val; } - auto - m00() const noexcept -> T + auto m00() const noexcept -> T { return m[0]; } - auto - m01() const noexcept -> T + auto m01() const noexcept -> T { return m[1]; } - auto - m02() const noexcept -> T + auto m02() const noexcept -> T { return m[2]; } - auto - m03() const noexcept -> T + auto m03() const noexcept -> T { return m[3]; } - auto - m10() const noexcept -> T + auto m10() const noexcept -> T { return m[4]; } - auto - m11() const noexcept -> T + auto m11() const noexcept -> T { return m[5]; } - auto - m12() const noexcept -> T + auto m12() const noexcept -> T { return m[6]; } - auto - m13() const noexcept -> T + auto m13() const noexcept -> T { return m[7]; } - auto - m20() const noexcept -> T + auto m20() const noexcept -> T { return m[8]; } - auto - m21() const noexcept -> T + auto m21() const noexcept -> T { return m[9]; } - auto - m22() const noexcept -> T + auto m22() const noexcept -> T { return m[10]; } - auto - m23() const noexcept -> T + auto m23() const noexcept -> T { return m[11]; } - auto - m30() const noexcept -> T + auto m30() const noexcept -> T { return m[12]; } - auto - m31() const noexcept -> T + auto m31() const noexcept -> T { return m[13]; } - auto - m32() const noexcept -> T + auto m32() const noexcept -> T { return m[14]; } - auto - m33() const noexcept -> T + auto m33() const noexcept -> T { return m[15]; } - auto - scale(T s) noexcept -> mat4& + auto scale(T s) noexcept -> mat4& { return scale(s, s, s); } - auto - scale(const vec3& v) noexcept -> mat4& + auto scale(const vec3& v) noexcept -> mat4& { return scale(v.x(), v.y(), v.z()); } - auto - scale(T x, T y, T z) noexcept -> mat4& + auto scale(T x, T y, T z) noexcept -> mat4& { m[0] *= x; m[5] *= y; @@ -381,14 +344,12 @@ struct mat4 { return *this; } - auto - identity() noexcept -> mat4& + auto identity() noexcept -> mat4& { return *this = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; } - auto - rotate(T a, const vec3& origin) noexcept -> mat4& + auto rotate(T a, const vec3& origin) noexcept -> mat4& { // zero rotation is nothing if(!a) { @@ -446,8 +407,7 @@ struct mat4 { return *this; } - auto - translate(T x, T y, T z) noexcept -> mat4& + auto translate(T x, T y, T z) noexcept -> mat4& { const auto m03 = m[3]; const auto m13 = m[7]; @@ -472,14 +432,12 @@ struct mat4 { return *this; } - auto - translate(const vec3& v) noexcept -> mat4& + auto translate(const vec3& v) noexcept -> mat4& { return translate(v.x(), v.y(), v.z()); } - auto - frustum(T l, T r, T b, T t, T n, T f) noexcept -> mat4& + auto frustum(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 * n / (r - l); m[5] = 2 * n / (t - b); @@ -499,8 +457,7 @@ struct mat4 { return *this; } - auto - orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> mat4& + auto orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 / (r - l); m[5] = 2 / (t - b); @@ -515,8 +472,8 @@ struct mat4 { return *this; } - auto - lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept -> mat4& + auto lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept + -> mat4& { auto fx = ex - lx; auto fy = ey - ly; @@ -561,15 +518,13 @@ struct mat4 { return *this; } - auto - lookat(vec3 e, vec3 l, vec3 u) noexcept -> mat4& + auto lookat(vec3 e, vec3 l, vec3 u) noexcept -> mat4& { return lookat( e.x(), e.y(), e.z(), l.x(), l.y(), l.z(), u.x(), u.y(), u.z()); } - auto - perspective(T fov, T a, T n, T f) noexcept -> mat4& + auto perspective(T fov, T a, T n, T f) noexcept -> mat4& { const auto t = std::tan(fov / 2) * n; const auto r = a * t; @@ -577,8 +532,7 @@ struct mat4 { return *this; } - auto - adjoint() noexcept -> mat4& + auto adjoint() noexcept -> mat4& { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], @@ -621,22 +575,19 @@ struct mat4 { return *this; } - auto - is_invertible() const noexcept -> bool + auto is_invertible() const noexcept -> bool { return determinant() != T{0}; } - auto - inverse() noexcept -> mat4& + auto inverse() noexcept -> mat4& { const auto det = determinant(); adjoint(); return this->operator*=(det); } - auto - transpose() noexcept -> mat4& + auto transpose() noexcept -> mat4& { *this = {m[0], m[4], @@ -658,8 +609,7 @@ struct mat4 { return *this; } - auto - determinant() const noexcept -> bool + auto determinant() const noexcept -> bool { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], diff --git a/src/cppid/gm3d/rgba.hpp b/src/cppid/gm3d/rgba.hpp index 02d4c99..d9dd4ac 100644 --- a/src/cppid/gm3d/rgba.hpp +++ b/src/cppid/gm3d/rgba.hpp @@ -15,7 +15,8 @@ template<> class rgba : public detail::basic_rgba, std::uint8_t> { public: - using scalar_type = detail::basic_rgba, std::uint8_t>::scalar_type; + using scalar_type = + detail::basic_rgba, std::uint8_t>::scalar_type; using detail::basic_rgba, std::uint8_t>::basic_rgba; diff --git a/src/cppid/gm3d/vec.hpp b/src/cppid/gm3d/vec.hpp index ae0f58c..bedd3c1 100644 --- a/src/cppid/gm3d/vec.hpp +++ b/src/cppid/gm3d/vec.hpp @@ -75,222 +75,189 @@ struct vec { } template>> - auto - operator=(const vec rhs) noexcept -> vec& + auto operator=(const vec rhs) noexcept -> vec& { op_assign(rhs.elems, std::make_index_sequence()); return *this; } - auto - operator+=(const vec& rhs) noexcept -> vec& + auto operator+=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); return *this; } - auto - operator+=(T rhs) noexcept -> vec& + auto operator+=(T rhs) noexcept -> vec& { op_assign(rhs, std::plus{}, std::make_index_sequence()); return *this; } - auto - operator-=(const vec& rhs) noexcept -> vec& + auto operator-=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); return *this; } - auto - operator-=(T rhs) noexcept -> vec& + auto operator-=(T rhs) noexcept -> vec& { op_assign(rhs, std::minus{}, std::make_index_sequence()); return *this; } - auto - operator*=(const vec& rhs) noexcept -> vec& + auto operator*=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::multiplies{}, std::make_index_sequence()); return *this; } - auto - operator*=(T rhs) noexcept -> vec& + auto operator*=(T rhs) noexcept -> vec& { op_assign(rhs, std::multiplies{}, std::make_index_sequence()); return *this; } - auto - operator/=(const vec& rhs) noexcept -> vec& + auto operator/=(const vec& rhs) noexcept -> vec& { op_assign(rhs.elems, std::divides{}, std::make_index_sequence()); return *this; } - auto - operator/=(T rhs) noexcept -> vec& + auto operator/=(T rhs) noexcept -> vec& { op_assign(rhs, std::divides{}, std::make_index_sequence()); return *this; } - auto - operator==(const vec& rhs) const noexcept -> bool + auto operator==(const vec& rhs) const noexcept -> bool { return is_equal(rhs.elems, std::make_index_sequence()); } - auto - operator!=(const vec& rhs) const noexcept -> bool + auto operator!=(const vec& rhs) const noexcept -> bool { return !((*this) == rhs); } - void - x(T val) noexcept + void x(T val) noexcept { elems[0] = val; } - void - y(T val) noexcept + void y(T val) noexcept { elems[1] = val; } template= 3, V>* = nullptr> - void - z(T val) noexcept + void z(T val) noexcept { elems[2] = val; } template= 4, V>* = nullptr> - void - w(T val) noexcept + void w(T val) noexcept { elems[3] = val; } - auto - x() const noexcept -> T + auto x() const noexcept -> T { return elems[0]; } - auto - y() const noexcept -> T + auto y() const noexcept -> T { return elems[1]; } template= 3, V>* = nullptr> - auto - z() const noexcept -> T + auto z() const noexcept -> T { return elems[2]; } template= 4, V>* = nullptr> - auto - w() const noexcept -> T + auto w() const noexcept -> T { return elems[3]; } - auto - dot(const vec& other) const noexcept -> T + auto dot(const vec& other) const noexcept -> T { return dot(other, std::make_index_sequence()); } - auto - magnitude() const noexcept -> T + auto magnitude() const noexcept -> T { return std::sqrt(dot(*this)); } - auto - magnitude_squared() const noexcept -> T + auto magnitude_squared() const noexcept -> T { return dot(*this); } - auto - to_unit() const noexcept -> vec + auto to_unit() const noexcept -> vec { return *this / magnitude(); } - auto - reflect(const vec& n) const noexcept -> vec + auto reflect(const vec& n) const noexcept -> vec { return *this - 2 * dot(n) * n; } template* = nullptr> - auto - cross(const vec& other) const noexcept -> vec + auto cross(const vec& other) const noexcept -> vec { return {elems[1] * other.elems[2] - elems[2] * other.elems[1], elems[2] * other.elems[0] - elems[0] * other.elems[2], elems[0] * other.elems[1] - elems[1] * other.elems[0]}; } - friend auto - operator+(const vec& val) noexcept -> vec + friend auto operator+(const vec& val) noexcept -> vec { return val; } template, T, U>>> - friend auto - operator+(const vec& lhs, const vec& rhs) noexcept + friend auto operator+(const vec& lhs, const vec& rhs) noexcept -> vec, T, U>, N> { return invoke_op{}(std::plus{}, lhs, rhs, std::make_index_sequence()); } - friend auto - operator+(const vec& lhs, T rhs) noexcept -> vec + friend auto operator+(const vec& lhs, T rhs) noexcept -> vec { return lhs + vec{rhs}; } - friend auto - operator+(T lhs, const vec& rhs) noexcept -> vec + friend auto operator+(T lhs, const vec& rhs) noexcept -> vec { return vec{lhs} + rhs; } - friend auto - operator-(const vec& lhs) noexcept -> vec + friend auto operator-(const vec& lhs) noexcept -> vec { return invoke_op{}(std::negate{}, lhs, std::make_index_sequence()); } template, T, U>>> - friend auto - operator-(const vec& lhs, const vec& rhs) noexcept + friend auto operator-(const vec& lhs, const vec& rhs) noexcept -> vec, T, U>, N> { return invoke_op{}(std::minus{}, lhs, rhs, std::make_index_sequence()); } - friend auto - operator-(const vec& lhs, T rhs) noexcept -> vec + friend auto operator-(const vec& lhs, T rhs) noexcept -> vec { return lhs - vec{rhs}; } - friend auto - operator-(T lhs, const vec& rhs) noexcept -> vec + friend auto operator-(T lhs, const vec& rhs) noexcept -> vec { return vec{lhs} - rhs; } @@ -318,21 +285,18 @@ struct vec { template< typename U, typename = std::enable_if_t, T, U>>> - friend auto - operator/(const vec& lhs, const vec& rhs) noexcept + friend auto operator/(const vec& lhs, const vec& rhs) noexcept -> vec, T, U>, N> { return invoke_op{}(std::divides{}, lhs, rhs, std::make_index_sequence()); } - friend auto - operator/(const vec& lhs, T rhs) noexcept -> vec + friend auto operator/(const vec& lhs, T rhs) noexcept -> vec { return lhs / vec{rhs}; } - friend auto - operator/(T lhs, const vec& rhs) noexcept -> vec + friend auto operator/(T lhs, const vec& rhs) noexcept -> vec { return vec{lhs} / rhs; } @@ -340,10 +304,9 @@ struct vec { private: struct invoke_op { template - auto - operator()(const P op, - const vec& lhs, - std::index_sequence) const noexcept + auto operator()(const P op, + const vec& lhs, + std::index_sequence) const noexcept -> vec, N> { static_assert(sizeof...(Ns) == N); @@ -351,11 +314,10 @@ struct vec { } template - auto - operator()(const P op, - const vec& lhs, - const vec& rhs, - std::index_sequence) const noexcept + auto operator()(const P op, + const vec& lhs, + const vec& rhs, + std::index_sequence) const noexcept -> vec, N> { static_assert(sizeof...(Ns) == N); @@ -371,36 +333,32 @@ struct vec { } template - inline void - op_assign(U rhs, P op, std::index_sequence) noexcept + inline void op_assign(U rhs, P op, std::index_sequence) noexcept { ((elems[Ns] = op(elems[Ns], rhs)), ...); } template - inline void - op_assign(const U (&rhs)[N], std::index_sequence) noexcept + inline void op_assign(const U (&rhs)[N], std::index_sequence) noexcept { ((elems[Ns] = rhs[Ns]), ...); } template - auto - is_equal(const U (&rhs)[N], std::index_sequence) const noexcept -> bool + auto is_equal(const U (&rhs)[N], std::index_sequence) const noexcept + -> bool { return ((elems[Ns] == rhs[Ns]) && ... && true); } template - auto - negate(std::index_sequence) const noexcept -> vec + auto negate(std::index_sequence) const noexcept -> vec { return vec{(-elems[Ns])...}; } template - auto - dot(const vec& other, std::index_sequence) const noexcept -> T + auto dot(const vec& other, std::index_sequence) const noexcept -> T { return ((elems[Ns] * other.elems[Ns]) + ... + 0); } diff --git a/test/matrix4.cpp b/test/matrix4.cpp index 50019a4..ec6eee4 100644 --- a/test/matrix4.cpp +++ b/test/matrix4.cpp @@ -71,7 +71,7 @@ TEST_CASE("float_matrix4_test initialization") REQUIRE(mat.m21() == 21.0f); REQUIRE(mat.m22() == 22.0f); REQUIRE(mat.m23() == 23.0f); - + REQUIRE(mat.m30() == 30.0f); REQUIRE(mat.m31() == 31.0f); REQUIRE(mat.m32() == 32.0f); From 4b5f9992400e0661a3597f1db9d3b2b271ac9e7e Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 10:56:47 +0800 Subject: [PATCH 07/19] refactor: use Boost.QVM with vector customisation point --- CMakeLists.txt | 18 +++++++++++++++++ src/cppid/gm3d/vec.hpp | 44 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0254b9..74f0ee1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,19 @@ cmake_minimum_required(VERSION 3.13) project(Gm3d) +find_package(Boost) + +if(NOT Boost_FOUND) + add_library(Boost::boost INTERFACE IMPORTED) + if(BOOST_ROOT) + target_include_directories(Boost::boost INTERFACE ${BOOST_ROOT}/include) + elseif(BOOST_INCLUDEDIR) + target_include_directories(Boost::boost INTERFACE ${BOOST_INCLUDEDIR}) + else() + message(SEND_ERROR "Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.") + endif() +endif() + add_library(cppid-gm3d INTERFACE) add_library(cppid::gm3d ALIAS cppid-gm3d) @@ -9,6 +22,11 @@ target_include_directories(cppid-gm3d "${PROJECT_SOURCE_DIR}/src" ) +target_link_libraries(cppid-gm3d + INTERFACE + Boost::boost +) + target_compile_options(cppid-gm3d INTERFACE -Wall diff --git a/src/cppid/gm3d/vec.hpp b/src/cppid/gm3d/vec.hpp index bedd3c1..2c0a7f1 100644 --- a/src/cppid/gm3d/vec.hpp +++ b/src/cppid/gm3d/vec.hpp @@ -9,6 +9,8 @@ #include #include +#include + #include "detail/type_traits.hpp" namespace cppid::gm3d { @@ -211,9 +213,7 @@ struct vec { template* = nullptr> auto cross(const vec& other) const noexcept -> vec { - return {elems[1] * other.elems[2] - elems[2] * other.elems[1], - elems[2] * other.elems[0] - elems[0] * other.elems[2], - elems[0] * other.elems[1] - elems[1] * other.elems[0]}; + return boost::qvm::cross(*this, other); } friend auto operator+(const vec& val) noexcept -> vec @@ -366,4 +366,42 @@ struct vec { } // namespace cppid::gm3d +namespace boost::qvm { +template +struct vec_traits> { + using scalar_type = T; + + static int const dim = N; + + template + static inline auto + write_element(cppid::gm3d::vec& v) noexcept -> scalar_type& + { + return v.elems[I]; + } + + template + static inline auto + read_element(cppid::gm3d::vec const& v) noexcept + -> scalar_type + { + return v.elems[I]; + } + + static inline auto + write_element_idx(int i, cppid::gm3d::vec& v) noexcept + -> scalar_type& + { + return v.elems[i]; + } + + static inline auto + read_element_idx(int i, cppid::gm3d::vec const& v) noexcept + -> scalar_type + { + return v.elems[i]; + } +}; + +} // namespace boost::qvm #endif From 043aee1cdc140b1acc178a59f3401223ff7ccaba Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 11:04:40 +0800 Subject: [PATCH 08/19] refactor: use Boost.QVM with matrix customisation point --- src/cppid/gm3d/mat3.hpp | 37 +++++++++ src/cppid/gm3d/mat4.hpp | 165 +++++++++++----------------------------- 2 files changed, 81 insertions(+), 121 deletions(-) diff --git a/src/cppid/gm3d/mat3.hpp b/src/cppid/gm3d/mat3.hpp index 041d6ec..80e9f32 100644 --- a/src/cppid/gm3d/mat3.hpp +++ b/src/cppid/gm3d/mat3.hpp @@ -1,9 +1,12 @@ #ifndef MOLPHENE_M3D_MAT3_HPP #define MOLPHENE_M3D_MAT3_HPP +#include + #include "mat4.hpp" namespace cppid::gm3d { + template struct mat3 { T m[9]; @@ -177,4 +180,38 @@ struct mat3 { } // namespace cppid::gm3d +namespace boost::qvm { + +template +struct mat_traits> { + using scalar_type = T; + static int const rows = 3; + static int const cols = 3; + + template + static scalar_type read_element(cppid::gm3d::mat3 const& x) + { + return x.m[Row * 3 + Col]; + } + + template + static scalar_type& write_element(cppid::gm3d::mat3& x) + { + return x.m[Row * 3 + Col]; + } + + static scalar_type + read_element_idx(int row, int col, cppid::gm3d::mat3 const& x) + { + return x.m[row * 3 + col]; + } + + static scalar_type& + write_element_idx(int row, int col, cppid::gm3d::mat3& x) + { + return x.m[row * 3 + col]; + } +}; +} // namespace boost::qvm + #endif diff --git a/src/cppid/gm3d/mat4.hpp b/src/cppid/gm3d/mat4.hpp index 447fd55..9c4f9af 100644 --- a/src/cppid/gm3d/mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -1,10 +1,12 @@ -#ifndef CPPID_GM3D_MAT4_HPP -#define CPPID_GM3D_MAT4_HPP +#ifndef MOLPHENE_GFXM_MAT4_HPP +#define MOLPHENE_GFXM_MAT4_HPP #include #include #include +#include + #include "vec2.hpp" #include "vec3.hpp" @@ -346,64 +348,13 @@ struct mat4 { auto identity() noexcept -> mat4& { - return *this = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + boost::qvm::set_identity(*this); + return *this; } - auto rotate(T a, const vec3& origin) noexcept -> mat4& + auto rotate(const vec3& origin, T a) noexcept -> mat4& { - // zero rotation is nothing - if(!a) { - return *this; - } - - const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], - m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], - m22 = m[10], m23 = m[11], m30 = m[12], m31 = m[13], m32 = m[14], - m33 = m[15]; - - const auto norm = origin.to_unit(); - const auto x = norm.x(); - const auto y = norm.y(); - const auto z = norm.z(); - const auto s = std::sin(a); - const auto c = std::cos(a); - const auto t = T{1} - c; - const auto xx = x * x; - const auto xy = x * y; - const auto yy = y * y; - const auto yz = y * z; - const auto zz = z * z; - const auto zx = z * x; - - const auto n00 = c + t * xx; - const auto n01 = t * xy + s * z; - const auto n02 = t * zx - s * y; - - const auto n10 = t * xy - s * z; - const auto n11 = c + t * yy; - const auto n12 = t * yz + s * x; - - const auto n20 = t * zx + s * y; - const auto n21 = t * yz - s * x; - const auto n22 = c + t * zz; - - m[0] = m00 * n00 + m01 * n10 + m02 * n20; - m[1] = m00 * n01 + m01 * n11 + m02 * n21; - m[2] = m00 * n02 + m01 * n12 + m02 * n22; - m[3] = m03; - m[4] = m10 * n00 + m11 * n10 + m12 * n20; - m[5] = m10 * n01 + m11 * n11 + m12 * n21; - m[6] = m10 * n02 + m11 * n12 + m12 * n22; - m[7] = m13; - m[8] = m20 * n00 + m21 * n10 + m22 * n20; - m[9] = m20 * n01 + m21 * n11 + m22 * n21; - m[10] = m20 * n02 + m21 * n12 + m22 * n22; - m[11] = m23; - m[12] = m30 * n00 + m31 * n10 + m32 * n20; - m[13] = m30 * n01 + m31 * n11 + m32 * n21; - m[14] = m30 * n02 + m31 * n12 + m32 * n22; - m[15] = m33; - + boost::qvm::rotate(*this, origin, a); return *this; } @@ -526,53 +477,7 @@ struct mat4 { auto perspective(T fov, T a, T n, T f) noexcept -> mat4& { - const auto t = std::tan(fov / 2) * n; - const auto r = a * t; - frustum(-r, r, -t, t, n, f); - return *this; - } - - auto adjoint() noexcept -> mat4& - { - const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], - m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], - m22 = m[10], m23 = m[11], m30 = m[12], m31 = m[13], m32 = m[14], - m33 = m[15]; - - m[0] = m12 * m23 * m31 - m13 * m22 * m31 + m13 * m21 * m32 - - m11 * m23 * m32 - m12 * m21 * m33 + m11 * m22 * m33; - m[1] = m03 * m22 * m31 - m02 * m23 * m31 - m03 * m21 * m32 + - m01 * m23 * m32 + m02 * m21 * m33 - m01 * m22 * m33; - m[2] = m02 * m13 * m31 - m03 * m12 * m31 + m03 * m11 * m32 - - m01 * m13 * m32 - m02 * m11 * m33 + m01 * m12 * m33; - m[3] = m03 * m12 * m21 - m02 * m13 * m21 - m03 * m11 * m22 + - m01 * m13 * m22 + m02 * m11 * m23 - m01 * m12 * m23; - m[4] = m13 * m22 * m30 - m12 * m23 * m30 - m13 * m20 * m32 + - m10 * m23 * m32 + m12 * m20 * m33 - m10 * m22 * m33; - m[5] = m02 * m23 * m30 - m03 * m22 * m30 + m03 * m20 * m32 - - m00 * m23 * m32 - m02 * m20 * m33 + m00 * m22 * m33; - m[6] = m03 * m12 * m30 - m02 * m13 * m30 - m03 * m10 * m32 + - m00 * m13 * m32 + m02 * m10 * m33 - m00 * m12 * m33; - m[7] = m02 * m13 * m20 - m03 * m12 * m20 + m03 * m10 * m22 - - m00 * m13 * m22 - m02 * m10 * m23 + m00 * m12 * m23; - m[8] = m11 * m23 * m30 - m13 * m21 * m30 + m13 * m20 * m31 - - m10 * m23 * m31 - m11 * m20 * m33 + m10 * m21 * m33; - m[9] = m03 * m21 * m30 - m01 * m23 * m30 - m03 * m20 * m31 + - m00 * m23 * m31 + m01 * m20 * m33 - m00 * m21 * m33; - m[10] = m01 * m13 * m30 - m03 * m11 * m30 + m03 * m10 * m31 - - m00 * m13 * m31 - m01 * m10 * m33 + m00 * m11 * m33; - m[11] = m03 * m11 * m20 - m01 * m13 * m20 - m03 * m10 * m21 + - m00 * m13 * m21 + m01 * m10 * m23 - m00 * m11 * m23; - m[12] = m12 * m21 * m30 - m11 * m22 * m30 - m12 * m20 * m31 + - m10 * m22 * m31 + m11 * m20 * m32 - m10 * m21 * m32; - m[13] = m01 * m22 * m30 - m02 * m21 * m30 + m02 * m20 * m31 - - m00 * m22 * m31 - m01 * m20 * m32 + m00 * m21 * m32; - m[14] = m02 * m11 * m30 - m01 * m12 * m30 - m02 * m10 * m31 + - m00 * m12 * m31 + m01 * m10 * m32 - m00 * m11 * m32; - m[15] = m01 * m12 * m20 - m02 * m11 * m20 + m02 * m10 * m21 - - m00 * m12 * m21 - m01 * m10 * m22 + m00 * m11 * m22; - - return *this; + return *this = boost::qvm::perspective_rh(fov, a, n, f); } auto is_invertible() const noexcept -> bool @@ -582,9 +487,7 @@ struct mat4 { auto inverse() noexcept -> mat4& { - const auto det = determinant(); - adjoint(); - return this->operator*=(det); + return *this = boost::qvm::inverse(*this); } auto transpose() noexcept -> mat4& @@ -611,23 +514,43 @@ struct mat4 { auto determinant() const noexcept -> bool { - const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], - m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], - m22 = m[10], m23 = m[11], m30 = m[12], m31 = m[13], m32 = m[14], - m33 = m[15]; - - return ( - m30 * m21 * m12 * m03 - m20 * m31 * m12 * m03 - m30 * m11 * m22 * m03 + - m10 * m31 * m22 * m03 + m20 * m11 * m32 * m03 - m10 * m21 * m32 * m03 - - m30 * m21 * m02 * m13 + m20 * m31 * m02 * m13 + m30 * m01 * m22 * m13 - - m00 * m31 * m22 * m13 - m20 * m01 * m32 * m13 + m00 * m21 * m32 * m13 + - m30 * m11 * m02 * m23 - m10 * m31 * m02 * m23 - m30 * m01 * m12 * m23 + - m00 * m31 * m12 * m23 + m10 * m01 * m32 * m23 - m00 * m11 * m32 * m23 - - m20 * m11 * m02 * m33 + m10 * m21 * m02 * m33 + m20 * m01 * m12 * m33 - - m00 * m21 * m12 * m33 - m10 * m01 * m22 * m33 + m00 * m11 * m22 * m33); + return boost::qvm::determinant(*this); } }; } // namespace cppid::gm3d +namespace boost::qvm { +template +struct mat_traits> { + using scalar_type = T; + static int const rows = 4; + static int const cols = 4; + + template + static scalar_type read_element(cppid::gm3d::mat4 const& x) + { + return x.m[Row * 4 + Col]; + } + + template + static scalar_type& write_element(cppid::gm3d::mat4& x) + { + return x.m[Row * 4 + Col]; + } + + static scalar_type + read_element_idx(int row, int col, cppid::gm3d::mat4 const& x) + { + return x.m[row * 4 + col]; + } + + static scalar_type& + write_element_idx(int row, int col, cppid::gm3d::mat4& x) + { + return x.m[row * 4 + col]; + } +}; +} // namespace boost::qvm + #endif From 2e7639f94643289294b2b1aae3f8c2c18d2138d2 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 11:21:43 +0800 Subject: [PATCH 09/19] refactor: rename vec class to basic_vector_nd --- .../gm3d/{vec.hpp => basic_vector_nd.hpp} | 161 ++++++++++-------- src/cppid/gm3d/vec2.hpp | 4 +- src/cppid/gm3d/vec3.hpp | 4 +- 3 files changed, 92 insertions(+), 77 deletions(-) rename src/cppid/gm3d/{vec.hpp => basic_vector_nd.hpp} (57%) diff --git a/src/cppid/gm3d/vec.hpp b/src/cppid/gm3d/basic_vector_nd.hpp similarity index 57% rename from src/cppid/gm3d/vec.hpp rename to src/cppid/gm3d/basic_vector_nd.hpp index 2c0a7f1..d497703 100644 --- a/src/cppid/gm3d/vec.hpp +++ b/src/cppid/gm3d/basic_vector_nd.hpp @@ -1,5 +1,5 @@ -#ifndef CPPID_GM3D_VEC_HPP -#define CPPID_GM3D_VEC_HPP +#ifndef CPPID_GM3D_BASIC_VECTOR_ND_HPP +#define CPPID_GM3D_BASIC_VECTOR_ND_HPP #include #include @@ -16,18 +16,18 @@ namespace cppid::gm3d { template -struct vec { +struct basic_vector_nd { T elems[N]; - vec() noexcept = default; + basic_vector_nd() noexcept = default; - explicit vec(T s) noexcept - : vec{s, std::make_index_sequence()} + explicit basic_vector_nd(T s) noexcept + : basic_vector_nd{s, std::make_index_sequence()} { } template> - vec(T s, std::index_sequence) noexcept + basic_vector_nd(T s, std::index_sequence) noexcept : elems{(static_cast(Ns), s)...} { } @@ -35,7 +35,7 @@ struct vec { template)>> - vec(Us... args) noexcept + basic_vector_nd(Us... args) noexcept : elems{T(args)...} { } @@ -43,8 +43,8 @@ struct vec { template< typename U, std::enable_if_t>* = nullptr> - explicit vec(vec v) noexcept - : vec{v, std::make_index_sequence()} + explicit basic_vector_nd(basic_vector_nd v) noexcept + : basic_vector_nd{v, std::make_index_sequence()} { } @@ -53,7 +53,7 @@ struct vec { std::size_t... Ns, std::enable_if_t<(sizeof...(Ns) == N) && detail::is_explicit_constructible_v>* = nullptr> - vec(vec v, std::index_sequence) noexcept + basic_vector_nd(basic_vector_nd v, std::index_sequence) noexcept : elems{v.elems[Ns]...} { } @@ -61,8 +61,8 @@ struct vec { template< typename U, std::enable_if_t>* = nullptr> - vec(vec v) noexcept - : vec{v, std::make_index_sequence()} + basic_vector_nd(basic_vector_nd v) noexcept + : basic_vector_nd{v, std::make_index_sequence()} { } @@ -71,72 +71,72 @@ struct vec { std::size_t... Ns, std::enable_if_t<(sizeof...(Ns) == N) && detail::is_implicit_constructible_v>* = nullptr> - vec(vec v, std::index_sequence) noexcept + basic_vector_nd(basic_vector_nd v, std::index_sequence) noexcept : elems{T(v.elems[Ns])...} { } template>> - auto operator=(const vec rhs) noexcept -> vec& + auto operator=(const basic_vector_nd rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::make_index_sequence()); return *this; } - auto operator+=(const vec& rhs) noexcept -> vec& + auto operator+=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); return *this; } - auto operator+=(T rhs) noexcept -> vec& + auto operator+=(T rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::plus{}, std::make_index_sequence()); return *this; } - auto operator-=(const vec& rhs) noexcept -> vec& + auto operator-=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); return *this; } - auto operator-=(T rhs) noexcept -> vec& + auto operator-=(T rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::minus{}, std::make_index_sequence()); return *this; } - auto operator*=(const vec& rhs) noexcept -> vec& + auto operator*=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::multiplies{}, std::make_index_sequence()); return *this; } - auto operator*=(T rhs) noexcept -> vec& + auto operator*=(T rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::multiplies{}, std::make_index_sequence()); return *this; } - auto operator/=(const vec& rhs) noexcept -> vec& + auto operator/=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::divides{}, std::make_index_sequence()); return *this; } - auto operator/=(T rhs) noexcept -> vec& + auto operator/=(T rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::divides{}, std::make_index_sequence()); return *this; } - auto operator==(const vec& rhs) const noexcept -> bool + auto operator==(const basic_vector_nd& rhs) const noexcept -> bool { return is_equal(rhs.elems, std::make_index_sequence()); } - auto operator!=(const vec& rhs) const noexcept -> bool + auto operator!=(const basic_vector_nd& rhs) const noexcept -> bool { return !((*this) == rhs); } @@ -185,7 +185,7 @@ struct vec { return elems[3]; } - auto dot(const vec& other) const noexcept -> T + auto dot(const basic_vector_nd& other) const noexcept -> T { return dot(other, std::make_index_sequence()); } @@ -200,114 +200,126 @@ struct vec { return dot(*this); } - auto to_unit() const noexcept -> vec + auto to_unit() const noexcept -> basic_vector_nd { return *this / magnitude(); } - auto reflect(const vec& n) const noexcept -> vec + auto reflect(const basic_vector_nd& n) const noexcept -> basic_vector_nd { return *this - 2 * dot(n) * n; } template* = nullptr> - auto cross(const vec& other) const noexcept -> vec + auto cross(const basic_vector_nd& other) const noexcept -> basic_vector_nd { return boost::qvm::cross(*this, other); } - friend auto operator+(const vec& val) noexcept -> vec + friend auto operator+(const basic_vector_nd& val) noexcept -> basic_vector_nd { return val; } template, T, U>>> - friend auto operator+(const vec& lhs, const vec& rhs) noexcept - -> vec, T, U>, N> + friend auto operator+(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, T, U>, N> { return invoke_op{}(std::plus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator+(const vec& lhs, T rhs) noexcept -> vec + friend auto operator+(const basic_vector_nd& lhs, T rhs) noexcept + -> basic_vector_nd { - return lhs + vec{rhs}; + return lhs + basic_vector_nd{rhs}; } - friend auto operator+(T lhs, const vec& rhs) noexcept -> vec + friend auto operator+(T lhs, const basic_vector_nd& rhs) noexcept + -> basic_vector_nd { - return vec{lhs} + rhs; + return basic_vector_nd{lhs} + rhs; } - friend auto operator-(const vec& lhs) noexcept -> vec + friend auto operator-(const basic_vector_nd& lhs) noexcept -> basic_vector_nd { return invoke_op{}(std::negate{}, lhs, std::make_index_sequence()); } template, T, U>>> - friend auto operator-(const vec& lhs, const vec& rhs) noexcept - -> vec, T, U>, N> + friend auto operator-(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, T, U>, N> { return invoke_op{}(std::minus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator-(const vec& lhs, T rhs) noexcept -> vec + friend auto operator-(const basic_vector_nd& lhs, T rhs) noexcept + -> basic_vector_nd { - return lhs - vec{rhs}; + return lhs - basic_vector_nd{rhs}; } - friend auto operator-(T lhs, const vec& rhs) noexcept -> vec + friend auto operator-(T lhs, const basic_vector_nd& rhs) noexcept + -> basic_vector_nd { - return vec{lhs} - rhs; + return basic_vector_nd{lhs} - rhs; } template< typename U, typename = std::enable_if_t, T, U>>> - friend auto operator*(const vec& lhs, const vec& rhs) noexcept - -> vec, T, U>, N> + friend auto operator*(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, T, U>, N> { return invoke_op{}( std::multiplies{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator*(const vec& lhs, T rhs) noexcept -> vec + friend auto operator*(const basic_vector_nd& lhs, T rhs) noexcept + -> basic_vector_nd { - return lhs * vec{rhs}; + return lhs * basic_vector_nd{rhs}; } - friend auto operator*(T lhs, const vec& rhs) noexcept -> vec + friend auto operator*(T lhs, const basic_vector_nd& rhs) noexcept + -> basic_vector_nd { - return vec{lhs} * rhs; + return basic_vector_nd{lhs} * rhs; } template< typename U, typename = std::enable_if_t, T, U>>> - friend auto operator/(const vec& lhs, const vec& rhs) noexcept - -> vec, T, U>, N> + friend auto operator/(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, T, U>, N> { return invoke_op{}(std::divides{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator/(const vec& lhs, T rhs) noexcept -> vec + friend auto operator/(const basic_vector_nd& lhs, T rhs) noexcept + -> basic_vector_nd { - return lhs / vec{rhs}; + return lhs / basic_vector_nd{rhs}; } - friend auto operator/(T lhs, const vec& rhs) noexcept -> vec + friend auto operator/(T lhs, const basic_vector_nd& rhs) noexcept + -> basic_vector_nd { - return vec{lhs} / rhs; + return basic_vector_nd{lhs} / rhs; } private: struct invoke_op { template auto operator()(const P op, - const vec& lhs, + const basic_vector_nd& lhs, std::index_sequence) const noexcept - -> vec, N> + -> basic_vector_nd, N> { static_assert(sizeof...(Ns) == N); return {op(lhs.elems[Ns])...}; @@ -315,10 +327,10 @@ struct vec { template auto operator()(const P op, - const vec& lhs, - const vec& rhs, + const basic_vector_nd& lhs, + const basic_vector_nd& rhs, std::index_sequence) const noexcept - -> vec, N> + -> basic_vector_nd, N> { static_assert(sizeof...(Ns) == N); return {op(lhs.elems[Ns], rhs.elems[Ns])...}; @@ -352,51 +364,54 @@ struct vec { } template - auto negate(std::index_sequence) const noexcept -> vec + auto negate(std::index_sequence) const noexcept -> basic_vector_nd { - return vec{(-elems[Ns])...}; + return basic_vector_nd{(-elems[Ns])...}; } template - auto dot(const vec& other, std::index_sequence) const noexcept -> T + auto dot(const basic_vector_nd& other, std::index_sequence) const + noexcept -> T { return ((elems[Ns] * other.elems[Ns]) + ... + 0); } }; -} // namespace cppid::gm3d +} // namespace cppid::gm3d::detail namespace boost::qvm { template -struct vec_traits> { +struct vec_traits> { using scalar_type = T; static int const dim = N; template - static inline auto - write_element(cppid::gm3d::vec& v) noexcept -> scalar_type& + static inline auto write_element( + cppid::gm3d::basic_vector_nd& v) noexcept + -> scalar_type& { return v.elems[I]; } template - static inline auto - read_element(cppid::gm3d::vec const& v) noexcept + static inline auto read_element( + cppid::gm3d::basic_vector_nd const& v) noexcept -> scalar_type { return v.elems[I]; } - static inline auto - write_element_idx(int i, cppid::gm3d::vec& v) noexcept + static inline auto write_element_idx( + int i, cppid::gm3d::basic_vector_nd& v) noexcept -> scalar_type& { return v.elems[i]; } - static inline auto - read_element_idx(int i, cppid::gm3d::vec const& v) noexcept + static inline auto read_element_idx( + int i, + cppid::gm3d::basic_vector_nd const& v) noexcept -> scalar_type { return v.elems[i]; diff --git a/src/cppid/gm3d/vec2.hpp b/src/cppid/gm3d/vec2.hpp index 053ff08..26d189c 100644 --- a/src/cppid/gm3d/vec2.hpp +++ b/src/cppid/gm3d/vec2.hpp @@ -1,12 +1,12 @@ #ifndef CPPID_GM3D_VEC2_HPP #define CPPID_GM3D_VEC2_HPP -#include "vec.hpp" +#include "basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec2 = vec; +using vec2 = basic_vector_nd; } // namespace cppid::gm3d diff --git a/src/cppid/gm3d/vec3.hpp b/src/cppid/gm3d/vec3.hpp index 22aa39c..76b9cd2 100644 --- a/src/cppid/gm3d/vec3.hpp +++ b/src/cppid/gm3d/vec3.hpp @@ -1,12 +1,12 @@ #ifndef CPPID_GM3D_VEC3_HPP #define CPPID_GM3D_VEC3_HPP -#include "vec.hpp" +#include "basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec3 = vec; +using vec3 = basic_vector_nd; } // namespace cppid::gm3d From ef0017c9d31caeac8a3d873cd5d7baf870aa3416 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 11:26:42 +0800 Subject: [PATCH 10/19] refactor: move basic_vector_nd to detail namespace --- .../gm3d/{ => detail}/basic_vector_nd.hpp | 18 +++++++++--------- src/cppid/gm3d/vec2.hpp | 4 ++-- src/cppid/gm3d/vec3.hpp | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) rename src/cppid/gm3d/{ => detail}/basic_vector_nd.hpp (95%) diff --git a/src/cppid/gm3d/basic_vector_nd.hpp b/src/cppid/gm3d/detail/basic_vector_nd.hpp similarity index 95% rename from src/cppid/gm3d/basic_vector_nd.hpp rename to src/cppid/gm3d/detail/basic_vector_nd.hpp index d497703..5d45619 100644 --- a/src/cppid/gm3d/basic_vector_nd.hpp +++ b/src/cppid/gm3d/detail/basic_vector_nd.hpp @@ -1,5 +1,5 @@ -#ifndef CPPID_GM3D_BASIC_VECTOR_ND_HPP -#define CPPID_GM3D_BASIC_VECTOR_ND_HPP +#ifndef CPPID_GM3D_DETAIL_BASIC_VECTOR_ND_HPP +#define CPPID_GM3D_DETAIL_BASIC_VECTOR_ND_HPP #include #include @@ -11,9 +11,9 @@ #include -#include "detail/type_traits.hpp" +#include "type_traits.hpp" -namespace cppid::gm3d { +namespace cppid::gm3d::detail { template struct basic_vector_nd { @@ -381,14 +381,14 @@ struct basic_vector_nd { namespace boost::qvm { template -struct vec_traits> { +struct vec_traits> { using scalar_type = T; static int const dim = N; template static inline auto write_element( - cppid::gm3d::basic_vector_nd& v) noexcept + cppid::gm3d::detail::basic_vector_nd& v) noexcept -> scalar_type& { return v.elems[I]; @@ -396,14 +396,14 @@ struct vec_traits> { template static inline auto read_element( - cppid::gm3d::basic_vector_nd const& v) noexcept + cppid::gm3d::detail::basic_vector_nd const& v) noexcept -> scalar_type { return v.elems[I]; } static inline auto write_element_idx( - int i, cppid::gm3d::basic_vector_nd& v) noexcept + int i, cppid::gm3d::detail::basic_vector_nd& v) noexcept -> scalar_type& { return v.elems[i]; @@ -411,7 +411,7 @@ struct vec_traits> { static inline auto read_element_idx( int i, - cppid::gm3d::basic_vector_nd const& v) noexcept + cppid::gm3d::detail::basic_vector_nd const& v) noexcept -> scalar_type { return v.elems[i]; diff --git a/src/cppid/gm3d/vec2.hpp b/src/cppid/gm3d/vec2.hpp index 26d189c..b8959db 100644 --- a/src/cppid/gm3d/vec2.hpp +++ b/src/cppid/gm3d/vec2.hpp @@ -1,12 +1,12 @@ #ifndef CPPID_GM3D_VEC2_HPP #define CPPID_GM3D_VEC2_HPP -#include "basic_vector_nd.hpp" +#include "detail/basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec2 = basic_vector_nd; +using vec2 = detail::basic_vector_nd; } // namespace cppid::gm3d diff --git a/src/cppid/gm3d/vec3.hpp b/src/cppid/gm3d/vec3.hpp index 76b9cd2..d2fffa9 100644 --- a/src/cppid/gm3d/vec3.hpp +++ b/src/cppid/gm3d/vec3.hpp @@ -1,12 +1,12 @@ #ifndef CPPID_GM3D_VEC3_HPP #define CPPID_GM3D_VEC3_HPP -#include "basic_vector_nd.hpp" +#include "detail/basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec3 = basic_vector_nd; +using vec3 = detail::basic_vector_nd; } // namespace cppid::gm3d From ac2c0799239054e24d5893c40cce5b20f25ed423 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 16:01:21 +0800 Subject: [PATCH 11/19] test: add vec_traits test for scalar type and dimensions --- src/cppid/gm3d/detail/basic_vector_nd.hpp | 2 +- test/vector2.cpp | 6 ++++++ test/vector3.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cppid/gm3d/detail/basic_vector_nd.hpp b/src/cppid/gm3d/detail/basic_vector_nd.hpp index 5d45619..62a611f 100644 --- a/src/cppid/gm3d/detail/basic_vector_nd.hpp +++ b/src/cppid/gm3d/detail/basic_vector_nd.hpp @@ -384,7 +384,7 @@ template struct vec_traits> { using scalar_type = T; - static int const dim = N; + static constexpr int dim = N; template static inline auto write_element( diff --git a/test/vector2.cpp b/test/vector2.cpp index 9a8cebf..534bfa3 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -1,6 +1,8 @@ #include #include +#include + #define CATCH_CONFIG_MAIN #include @@ -14,6 +16,10 @@ TEST_CASE("float_vector2_test traits") REQUIRE(std::is_trivial_v); REQUIRE(std::is_standard_layout_v); REQUIRE(sizeof(vec2f) == (sizeof(float) * 2)); + + REQUIRE(( + std::is_same_v::scalar_type>)); + REQUIRE(boost::qvm::vec_traits::dim == 2); } TEST_CASE("float_vector2_test initialization") diff --git a/test/vector3.cpp b/test/vector3.cpp index 53d142a..ebad7a7 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -1,6 +1,8 @@ #include #include +#include + #define CATCH_CONFIG_MAIN #include @@ -14,6 +16,10 @@ TEST_CASE("float_vector3_test traits") REQUIRE(std::is_trivial_v); REQUIRE(std::is_standard_layout_v); REQUIRE(sizeof(vec3f) == (sizeof(float) * 3)); + + REQUIRE(( + std::is_same_v::scalar_type>)); + REQUIRE(boost::qvm::vec_traits::dim == 3); } TEST_CASE("float_vector3_test initialization") From 6bf4e86f00ff3ce02e35fc2f78853a5cb6436b78 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 17:12:59 +0800 Subject: [PATCH 12/19] refactor: create basic_point_vector class for base of vector and point --- src/cppid/gm3d/detail/basic_point_vector.hpp | 120 +++++++ src/cppid/gm3d/detail/basic_vector_nd.hpp | 317 ++++++++----------- 2 files changed, 254 insertions(+), 183 deletions(-) create mode 100644 src/cppid/gm3d/detail/basic_point_vector.hpp diff --git a/src/cppid/gm3d/detail/basic_point_vector.hpp b/src/cppid/gm3d/detail/basic_point_vector.hpp new file mode 100644 index 0000000..7faff21 --- /dev/null +++ b/src/cppid/gm3d/detail/basic_point_vector.hpp @@ -0,0 +1,120 @@ +#ifndef CPPID_GM3D_DETAIL_BASIC_POINT_VECTOR_HPP +#define CPPID_GM3D_DETAIL_BASIC_POINT_VECTOR_HPP + +#include +#include +#include + +#include + +#include "type_traits.hpp" + +namespace cppid::gm3d::detail { + +template +struct basic_point_vector { + + using scalar_type = T; + + static constexpr auto dimensions = N; + + scalar_type elems[dimensions]; + + basic_point_vector() noexcept = default; + + template< + typename... Us, + typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && + std::is_convertible_v)>> + basic_point_vector(Us... args) noexcept + : elems{scalar_type(args)...} + { + } + + void x(scalar_type val) noexcept + { + elems[0] = val; + } + + void y(scalar_type val) noexcept + { + elems[1] = val; + } + + template= 3)>* = nullptr> + void z(scalar_type val) noexcept + { + elems[2] = val; + } + + template= 4)>* = nullptr> + void w(scalar_type val) noexcept + { + elems[3] = val; + } + + auto x() const noexcept -> scalar_type + { + return elems[0]; + } + + auto y() const noexcept -> scalar_type + { + return elems[1]; + } + + template= 3)>* = nullptr> + auto z() const noexcept -> scalar_type + { + return elems[2]; + } + + template= 4)>* = nullptr> + auto w() const noexcept -> scalar_type + { + return elems[3]; + } +}; + +} // namespace cppid::gm3d::detail + +namespace boost::qvm { +template +struct vec_traits> { + using point_vector_type = cppid::gm3d::detail::basic_point_vector; + + using scalar_type = typename point_vector_type::scalar_type; + + static constexpr int dim = point_vector_type::dimensions; + + template + static inline auto write_element(point_vector_type& v) noexcept + -> scalar_type& + { + return v.elems[I]; + } + + template + static inline auto read_element(point_vector_type const& v) noexcept + -> scalar_type + { + return v.elems[I]; + } + + static inline auto write_element_idx(int i, point_vector_type& v) noexcept + -> scalar_type& + { + return v.elems[i]; + } + + static inline auto read_element_idx(int i, + point_vector_type const& v) noexcept + -> scalar_type + { + return v.elems[i]; + } +}; + +} // namespace boost::qvm + +#endif diff --git a/src/cppid/gm3d/detail/basic_vector_nd.hpp b/src/cppid/gm3d/detail/basic_vector_nd.hpp index 62a611f..0372a8e 100644 --- a/src/cppid/gm3d/detail/basic_vector_nd.hpp +++ b/src/cppid/gm3d/detail/basic_vector_nd.hpp @@ -11,129 +11,141 @@ #include +#include "basic_point_vector.hpp" #include "type_traits.hpp" namespace cppid::gm3d::detail { template -struct basic_vector_nd { - T elems[N]; +struct basic_vector_nd +: public basic_point_vector, T, N> { + using typename basic_point_vector, T, N>::scalar_type; + + using basic_point_vector, T, N>::dimensions; basic_vector_nd() noexcept = default; - explicit basic_vector_nd(T s) noexcept - : basic_vector_nd{s, std::make_index_sequence()} + explicit basic_vector_nd(scalar_type s) noexcept + : basic_vector_nd{s, std::make_index_sequence()} { } - template> - basic_vector_nd(T s, std::index_sequence) noexcept - : elems{(static_cast(Ns), s)...} + template> + basic_vector_nd(scalar_type s, std::index_sequence) noexcept + : basic_vector_nd{(static_cast(Ns), s)...} { } - template)>> + template< + typename... Us, + typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && + std::is_convertible_v)>> basic_vector_nd(Us... args) noexcept - : elems{T(args)...} + : basic_point_vector, T, N>::basic_point_vector{args...} { } - template< - typename U, - std::enable_if_t>* = nullptr> - explicit basic_vector_nd(basic_vector_nd v) noexcept - : basic_vector_nd{v, std::make_index_sequence()} + template>* = nullptr> + explicit basic_vector_nd(basic_vector_nd v) noexcept + : basic_vector_nd{v, std::make_index_sequence()} { } - template< - typename U, - std::size_t... Ns, - std::enable_if_t<(sizeof...(Ns) == N) && - detail::is_explicit_constructible_v>* = nullptr> - basic_vector_nd(basic_vector_nd v, std::index_sequence) noexcept - : elems{v.elems[Ns]...} + template>* = nullptr> + basic_vector_nd(basic_vector_nd v, + std::index_sequence) noexcept + : basic_vector_nd{v.elems[Ns]...} { } - template< - typename U, - std::enable_if_t>* = nullptr> - basic_vector_nd(basic_vector_nd v) noexcept - : basic_vector_nd{v, std::make_index_sequence()} + template>* = nullptr> + basic_vector_nd(basic_vector_nd v) noexcept + : basic_vector_nd{v, std::make_index_sequence()} { } - template< - typename U, - std::size_t... Ns, - std::enable_if_t<(sizeof...(Ns) == N) && - detail::is_implicit_constructible_v>* = nullptr> - basic_vector_nd(basic_vector_nd v, std::index_sequence) noexcept - : elems{T(v.elems[Ns])...} + template>* = nullptr> + basic_vector_nd(basic_vector_nd v, + std::index_sequence) noexcept + : basic_vector_nd{scalar_type(v.elems[Ns])...} { } - template>> - auto operator=(const basic_vector_nd rhs) noexcept -> basic_vector_nd& + template>> + auto operator=(const basic_vector_nd rhs) noexcept + -> basic_vector_nd& { - op_assign(rhs.elems, std::make_index_sequence()); + op_assign(rhs.elems, std::make_index_sequence()); return *this; } auto operator+=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { - op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); + op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); return *this; } - auto operator+=(T rhs) noexcept -> basic_vector_nd& + auto operator+=(scalar_type rhs) noexcept -> basic_vector_nd& { - op_assign(rhs, std::plus{}, std::make_index_sequence()); + op_assign(rhs, std::plus{}, std::make_index_sequence()); return *this; } auto operator-=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { - op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); + op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); return *this; } - auto operator-=(T rhs) noexcept -> basic_vector_nd& + auto operator-=(scalar_type rhs) noexcept -> basic_vector_nd& { - op_assign(rhs, std::minus{}, std::make_index_sequence()); + op_assign(rhs, std::minus{}, std::make_index_sequence()); return *this; } auto operator*=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { - op_assign(rhs.elems, std::multiplies{}, std::make_index_sequence()); + op_assign( + rhs.elems, std::multiplies{}, std::make_index_sequence()); return *this; } - auto operator*=(T rhs) noexcept -> basic_vector_nd& + auto operator*=(scalar_type rhs) noexcept -> basic_vector_nd& { - op_assign(rhs, std::multiplies{}, std::make_index_sequence()); + op_assign(rhs, std::multiplies{}, std::make_index_sequence()); return *this; } auto operator/=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& { - op_assign(rhs.elems, std::divides{}, std::make_index_sequence()); + op_assign( + rhs.elems, std::divides{}, std::make_index_sequence()); return *this; } - auto operator/=(T rhs) noexcept -> basic_vector_nd& + auto operator/=(scalar_type rhs) noexcept -> basic_vector_nd& { - op_assign(rhs, std::divides{}, std::make_index_sequence()); + op_assign(rhs, std::divides{}, std::make_index_sequence()); return *this; } auto operator==(const basic_vector_nd& rhs) const noexcept -> bool { - return is_equal(rhs.elems, std::make_index_sequence()); + return is_equal(rhs.elems, std::make_index_sequence()); } auto operator!=(const basic_vector_nd& rhs) const noexcept -> bool @@ -141,61 +153,17 @@ struct basic_vector_nd { return !((*this) == rhs); } - void x(T val) noexcept - { - elems[0] = val; - } - - void y(T val) noexcept - { - elems[1] = val; - } - - template= 3, V>* = nullptr> - void z(T val) noexcept - { - elems[2] = val; - } - - template= 4, V>* = nullptr> - void w(T val) noexcept - { - elems[3] = val; - } - - auto x() const noexcept -> T - { - return elems[0]; - } - - auto y() const noexcept -> T - { - return elems[1]; - } - - template= 3, V>* = nullptr> - auto z() const noexcept -> T + auto dot(const basic_vector_nd& other) const noexcept -> scalar_type { - return elems[2]; + return dot(other, std::make_index_sequence()); } - template= 4, V>* = nullptr> - auto w() const noexcept -> T - { - return elems[3]; - } - - auto dot(const basic_vector_nd& other) const noexcept -> T - { - return dot(other, std::make_index_sequence()); - } - - auto magnitude() const noexcept -> T + auto magnitude() const noexcept -> scalar_type { return std::sqrt(dot(*this)); } - auto magnitude_squared() const noexcept -> T + auto magnitude_squared() const noexcept -> scalar_type { return dot(*this); } @@ -210,7 +178,7 @@ struct basic_vector_nd { return *this - 2 * dot(n) * n; } - template* = nullptr> + template* = nullptr> auto cross(const basic_vector_nd& other) const noexcept -> basic_vector_nd { return boost::qvm::cross(*this, other); @@ -222,21 +190,24 @@ struct basic_vector_nd { } template, T, U>>> + typename = + std::enable_if_t, scalar_type, U>>> friend auto operator+(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept - -> basic_vector_nd, T, U>, N> + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, scalar_type, U>, + dimensions> { - return invoke_op{}(std::plus{}, lhs, rhs, std::make_index_sequence()); + return invoke_op{}( + std::plus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator+(const basic_vector_nd& lhs, T rhs) noexcept + friend auto operator+(const basic_vector_nd& lhs, scalar_type rhs) noexcept -> basic_vector_nd { return lhs + basic_vector_nd{rhs}; } - friend auto operator+(T lhs, const basic_vector_nd& rhs) noexcept + friend auto operator+(scalar_type lhs, const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} + rhs; @@ -244,70 +215,77 @@ struct basic_vector_nd { friend auto operator-(const basic_vector_nd& lhs) noexcept -> basic_vector_nd { - return invoke_op{}(std::negate{}, lhs, std::make_index_sequence()); + return invoke_op{}( + std::negate{}, lhs, std::make_index_sequence()); } template, T, U>>> + typename = + std::enable_if_t, scalar_type, U>>> friend auto operator-(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept - -> basic_vector_nd, T, U>, N> + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, scalar_type, U>, + dimensions> { - return invoke_op{}(std::minus{}, lhs, rhs, std::make_index_sequence()); + return invoke_op{}( + std::minus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator-(const basic_vector_nd& lhs, T rhs) noexcept + friend auto operator-(const basic_vector_nd& lhs, scalar_type rhs) noexcept -> basic_vector_nd { return lhs - basic_vector_nd{rhs}; } - friend auto operator-(T lhs, const basic_vector_nd& rhs) noexcept + friend auto operator-(scalar_type lhs, const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} - rhs; } - template< - typename U, - typename = std::enable_if_t, T, U>>> + template, scalar_type, U>>> friend auto operator*(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept - -> basic_vector_nd, T, U>, N> + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, scalar_type, U>, + dimensions> { return invoke_op{}( - std::multiplies{}, lhs, rhs, std::make_index_sequence()); + std::multiplies{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator*(const basic_vector_nd& lhs, T rhs) noexcept + friend auto operator*(const basic_vector_nd& lhs, scalar_type rhs) noexcept -> basic_vector_nd { return lhs * basic_vector_nd{rhs}; } - friend auto operator*(T lhs, const basic_vector_nd& rhs) noexcept + friend auto operator*(scalar_type lhs, const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} * rhs; } - template< - typename U, - typename = std::enable_if_t, T, U>>> + template, scalar_type, U>>> friend auto operator/(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept - -> basic_vector_nd, T, U>, N> + const basic_vector_nd& rhs) noexcept + -> basic_vector_nd, scalar_type, U>, + dimensions> { - return invoke_op{}(std::divides{}, lhs, rhs, std::make_index_sequence()); + return invoke_op{}( + std::divides{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator/(const basic_vector_nd& lhs, T rhs) noexcept + friend auto operator/(const basic_vector_nd& lhs, scalar_type rhs) noexcept -> basic_vector_nd { return lhs / basic_vector_nd{rhs}; } - friend auto operator/(T lhs, const basic_vector_nd& rhs) noexcept + friend auto operator/(scalar_type lhs, const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} / rhs; @@ -317,106 +295,79 @@ struct basic_vector_nd { struct invoke_op { template auto operator()(const P op, - const basic_vector_nd& lhs, + const basic_vector_nd& lhs, std::index_sequence) const noexcept - -> basic_vector_nd, N> + -> basic_vector_nd, dimensions> { - static_assert(sizeof...(Ns) == N); + static_assert(sizeof...(Ns) == dimensions); return {op(lhs.elems[Ns])...}; } template auto operator()(const P op, - const basic_vector_nd& lhs, - const basic_vector_nd& rhs, + const basic_vector_nd& lhs, + const basic_vector_nd& rhs, std::index_sequence) const noexcept - -> basic_vector_nd, N> + -> basic_vector_nd, dimensions> { - static_assert(sizeof...(Ns) == N); + static_assert(sizeof...(Ns) == dimensions); return {op(lhs.elems[Ns], rhs.elems[Ns])...}; } }; template - inline void - op_assign(const U (&rhs)[N], P op, std::index_sequence) noexcept + inline void op_assign(const U (&rhs)[dimensions], + P op, + std::index_sequence) noexcept { - ((elems[Ns] = op(elems[Ns], rhs[Ns])), ...); + ((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...); } template inline void op_assign(U rhs, P op, std::index_sequence) noexcept { - ((elems[Ns] = op(elems[Ns], rhs)), ...); + ((this->elems[Ns] = op(this->elems[Ns], rhs)), ...); } template - inline void op_assign(const U (&rhs)[N], std::index_sequence) noexcept + inline void op_assign(const U (&rhs)[dimensions], + std::index_sequence) noexcept { - ((elems[Ns] = rhs[Ns]), ...); + ((this->elems[Ns] = rhs[Ns]), ...); } template - auto is_equal(const U (&rhs)[N], std::index_sequence) const noexcept - -> bool + auto is_equal(const U (&rhs)[dimensions], std::index_sequence) const + noexcept -> bool { - return ((elems[Ns] == rhs[Ns]) && ... && true); + return ((this->elems[Ns] == rhs[Ns]) && ... && true); } template auto negate(std::index_sequence) const noexcept -> basic_vector_nd { - return basic_vector_nd{(-elems[Ns])...}; + return basic_vector_nd{(-this->elems[Ns])...}; } template auto dot(const basic_vector_nd& other, std::index_sequence) const - noexcept -> T + noexcept -> scalar_type { - return ((elems[Ns] * other.elems[Ns]) + ... + 0); + return ((this->elems[Ns] * other.elems[Ns]) + ... + 0); } }; } // namespace cppid::gm3d::detail namespace boost::qvm { -template -struct vec_traits> { - using scalar_type = T; - static constexpr int dim = N; - - template - static inline auto write_element( - cppid::gm3d::detail::basic_vector_nd& v) noexcept - -> scalar_type& - { - return v.elems[I]; - } - - template - static inline auto read_element( - cppid::gm3d::detail::basic_vector_nd const& v) noexcept - -> scalar_type - { - return v.elems[I]; - } - - static inline auto write_element_idx( - int i, cppid::gm3d::detail::basic_vector_nd& v) noexcept - -> scalar_type& - { - return v.elems[i]; - } - - static inline auto read_element_idx( - int i, - cppid::gm3d::detail::basic_vector_nd const& v) noexcept - -> scalar_type - { - return v.elems[i]; - } +template +struct vec_traits> +: public vec_traits< + cppid::gm3d::detail:: + basic_point_vector, T, N>> { }; } // namespace boost::qvm + #endif From 6ea2431167da793f365a2f2a99a9d1434276e9b5 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Sat, 23 Mar 2019 17:18:57 +0800 Subject: [PATCH 13/19] refactor: rename vec2 tp vector_2d and vec3 to vector_3d --- src/cppid/gm3d/all.hpp | 4 ++-- src/cppid/gm3d/mat4.hpp | 12 ++++++------ src/cppid/gm3d/{vec2.hpp => vector_2d.hpp} | 6 +++--- src/cppid/gm3d/{vec3.hpp => vector_3d.hpp} | 6 +++--- test/vector2.cpp | 12 ++++++------ test/vector3.cpp | 20 ++++++++++---------- 6 files changed, 30 insertions(+), 30 deletions(-) rename src/cppid/gm3d/{vec2.hpp => vector_2d.hpp} (51%) rename src/cppid/gm3d/{vec3.hpp => vector_3d.hpp} (51%) diff --git a/src/cppid/gm3d/all.hpp b/src/cppid/gm3d/all.hpp index 6e20f55..849b70c 100644 --- a/src/cppid/gm3d/all.hpp +++ b/src/cppid/gm3d/all.hpp @@ -4,7 +4,7 @@ #include "mat3.hpp" #include "mat4.hpp" #include "rgba.hpp" -#include "vec2.hpp" -#include "vec3.hpp" +#include "vector_2d.hpp" +#include "vector_3d.hpp" #endif diff --git a/src/cppid/gm3d/mat4.hpp b/src/cppid/gm3d/mat4.hpp index 9c4f9af..249dafd 100644 --- a/src/cppid/gm3d/mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -7,8 +7,8 @@ #include -#include "vec2.hpp" -#include "vec3.hpp" +#include "vector_2d.hpp" +#include "vector_3d.hpp" namespace cppid::gm3d { @@ -333,7 +333,7 @@ struct mat4 { return scale(s, s, s); } - auto scale(const vec3& v) noexcept -> mat4& + auto scale(const vector_3d& v) noexcept -> mat4& { return scale(v.x(), v.y(), v.z()); } @@ -352,7 +352,7 @@ struct mat4 { return *this; } - auto rotate(const vec3& origin, T a) noexcept -> mat4& + auto rotate(const vector_3d& origin, T a) noexcept -> mat4& { boost::qvm::rotate(*this, origin, a); return *this; @@ -383,7 +383,7 @@ struct mat4 { return *this; } - auto translate(const vec3& v) noexcept -> mat4& + auto translate(const vector_3d& v) noexcept -> mat4& { return translate(v.x(), v.y(), v.z()); } @@ -469,7 +469,7 @@ struct mat4 { return *this; } - auto lookat(vec3 e, vec3 l, vec3 u) noexcept -> mat4& + auto lookat(vector_3d e, vector_3d l, vector_3d u) noexcept -> mat4& { return lookat( e.x(), e.y(), e.z(), l.x(), l.y(), l.z(), u.x(), u.y(), u.z()); diff --git a/src/cppid/gm3d/vec2.hpp b/src/cppid/gm3d/vector_2d.hpp similarity index 51% rename from src/cppid/gm3d/vec2.hpp rename to src/cppid/gm3d/vector_2d.hpp index b8959db..d4447c4 100644 --- a/src/cppid/gm3d/vec2.hpp +++ b/src/cppid/gm3d/vector_2d.hpp @@ -1,12 +1,12 @@ -#ifndef CPPID_GM3D_VEC2_HPP -#define CPPID_GM3D_VEC2_HPP +#ifndef CPPID_GM3D_VECTOR_2D_HPP +#define CPPID_GM3D_VECTOR_2D_HPP #include "detail/basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec2 = detail::basic_vector_nd; +using vector_2d = detail::basic_vector_nd; } // namespace cppid::gm3d diff --git a/src/cppid/gm3d/vec3.hpp b/src/cppid/gm3d/vector_3d.hpp similarity index 51% rename from src/cppid/gm3d/vec3.hpp rename to src/cppid/gm3d/vector_3d.hpp index d2fffa9..7081d70 100644 --- a/src/cppid/gm3d/vec3.hpp +++ b/src/cppid/gm3d/vector_3d.hpp @@ -1,12 +1,12 @@ -#ifndef CPPID_GM3D_VEC3_HPP -#define CPPID_GM3D_VEC3_HPP +#ifndef CPPID_GM3D_VECTOR_3D_HPP +#define CPPID_GM3D_VECTOR_3D_HPP #include "detail/basic_vector_nd.hpp" namespace cppid::gm3d { template -using vec3 = detail::basic_vector_nd; +using vector_3d = detail::basic_vector_nd; } // namespace cppid::gm3d diff --git a/test/vector2.cpp b/test/vector2.cpp index 534bfa3..3b6984b 100644 --- a/test/vector2.cpp +++ b/test/vector2.cpp @@ -6,10 +6,10 @@ #define CATCH_CONFIG_MAIN #include -#include +#include -using cppid::gm3d::vec2; -using vec2f = vec2; +using cppid::gm3d::vector_2d; +using vec2f = vector_2d; TEST_CASE("float_vector2_test traits") { @@ -40,18 +40,18 @@ TEST_CASE("float_vector2_test initialization") REQUIRE(vt.y() == 2.3f); } { - auto vt = vec2f{vec2{0}}; + auto vt = vec2f{vector_2d{0}}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); } { auto vt = vec2f{0}; - vt = vec2{0}; + vt = vector_2d{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); } { - auto vd = vec2{0}; + auto vd = vector_2d{0}; vec2f vt = vd; CHECK(vt.x() == 0.0f); CHECK(vt.y() == 0.0f); diff --git a/test/vector3.cpp b/test/vector3.cpp index ebad7a7..195b294 100644 --- a/test/vector3.cpp +++ b/test/vector3.cpp @@ -6,10 +6,10 @@ #define CATCH_CONFIG_MAIN #include -#include +#include -using cppid::gm3d::vec3; -using vec3f = vec3; +using cppid::gm3d::vector_3d; +using vec3f = vector_3d; TEST_CASE("float_vector3_test traits") { @@ -43,20 +43,20 @@ TEST_CASE("float_vector3_test initialization") REQUIRE(vt.z() == 6.4f); } { - auto vt = vec3f{vec3{0}}; + auto vt = vec3f{vector_3d{0}}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); REQUIRE(vt.z() == 0.0f); } { auto vt = vec3f{0}; - vt = vec3{0}; + vt = vector_3d{0}; REQUIRE(vt.x() == 0.0f); REQUIRE(vt.y() == 0.0f); REQUIRE(vt.z() == 0.0f); } { - auto vd = vec3{0}; + auto vd = vector_3d{0}; vec3f vt = vd; CHECK(vt.x() == 0.0f); CHECK(vt.y() == 0.0f); @@ -109,7 +109,7 @@ TEST_CASE("float_vector3_test addition") REQUIRE(vt.z() == Approx(1.2f)); } { - auto vt = vec3{0} + vec3{0}; + auto vt = vector_3d{0} + vector_3d{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -151,7 +151,7 @@ TEST_CASE("float_vector3_test subtraction") REQUIRE(vt.z() == Approx(-6.4f)); } { - auto vt = vec3{0} - vec3{0}; + auto vt = vector_3d{0} - vector_3d{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -193,7 +193,7 @@ TEST_CASE("float_vector3_test multiplication") REQUIRE(vt.z() == Approx(15.4f)); } { - auto vt = vec3{0} * vec3{0}; + auto vt = vector_3d{0} * vector_3d{0}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); @@ -235,7 +235,7 @@ TEST_CASE("float_vector3_test division") REQUIRE(vt.z() == Approx(1.0f)); } { - auto vt = vec3{0} / vec3{1}; + auto vt = vector_3d{0} / vector_3d{1}; CHECK(vt.x() == Approx(0.)); CHECK(vt.y() == Approx(0.)); CHECK(vt.z() == Approx(0.)); From 1caa8face4e2fbc735fcb499d43b60410f04e1a9 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Mon, 1 Apr 2019 21:03:22 +0800 Subject: [PATCH 14/19] feat: add new type point_2d and point_3d --- CMakeLists.txt | 2 + src/cppid/gm3d/detail/basic_point_nd.hpp | 188 +++++++++++++++++++++++ src/cppid/gm3d/point_2d.hpp | 13 ++ src/cppid/gm3d/point_3d.hpp | 13 ++ test/point2.cpp | 68 ++++++++ test/point3.cpp | 74 +++++++++ 6 files changed, 358 insertions(+) create mode 100644 src/cppid/gm3d/detail/basic_point_nd.hpp create mode 100644 src/cppid/gm3d/point_2d.hpp create mode 100644 src/cppid/gm3d/point_3d.hpp create mode 100644 test/point2.cpp create mode 100644 test/point3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 74f0ee1..3a838d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,8 @@ if(GM3D_BUILD_TESTING) set(Gm3d_TEST_SRC_FILES "${PROJECT_SOURCE_DIR}/test/matrix3.cpp" "${PROJECT_SOURCE_DIR}/test/matrix4.cpp" + "${PROJECT_SOURCE_DIR}/test/point2.cpp" + "${PROJECT_SOURCE_DIR}/test/point3.cpp" "${PROJECT_SOURCE_DIR}/test/rgba_float.cpp" "${PROJECT_SOURCE_DIR}/test/rgba_uint8.cpp" "${PROJECT_SOURCE_DIR}/test/vector2.cpp" diff --git a/src/cppid/gm3d/detail/basic_point_nd.hpp b/src/cppid/gm3d/detail/basic_point_nd.hpp new file mode 100644 index 0000000..1fb49a5 --- /dev/null +++ b/src/cppid/gm3d/detail/basic_point_nd.hpp @@ -0,0 +1,188 @@ +#ifndef CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP +#define CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "basic_point_vector.hpp" +#include "type_traits.hpp" + +namespace cppid::gm3d::detail { + +template +struct basic_point_nd : public basic_point_vector, T, N> { + using typename basic_point_vector, T, N>::scalar_type; + + using basic_point_vector, T, N>::dimensions; + + basic_point_nd() noexcept = default; + + explicit basic_point_nd(scalar_type s) noexcept + : basic_point_nd{s, std::make_index_sequence()} + { + } + + template> + basic_point_nd(scalar_type s, std::index_sequence) noexcept + : basic_point_nd{(static_cast(Ns), s)...} + { + } + + template< + typename... Us, + typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && + std::is_convertible_v)>> + basic_point_nd(Us... args) noexcept + : basic_point_vector, T, N>::basic_point_vector{args...} + { + } + + template>* = nullptr> + explicit basic_point_nd(basic_point_nd v) noexcept + : basic_point_nd{v, std::make_index_sequence()} + { + } + + template>* = nullptr> + basic_point_nd(basic_point_nd v, + std::index_sequence) noexcept + : basic_point_nd{v.elems[Ns]...} + { + } + + template>* = nullptr> + basic_point_nd(basic_point_nd v) noexcept + : basic_point_nd{v, std::make_index_sequence()} + { + } + + template>* = nullptr> + basic_point_nd(basic_point_nd v, + std::index_sequence) noexcept + : basic_point_nd{scalar_type(v.elems[Ns])...} + { + } + + template>> + auto operator=(const basic_point_nd rhs) noexcept + -> basic_point_nd& + { + op_assign(rhs.elems, std::make_index_sequence()); + return *this; + } + + auto operator==(const basic_point_nd& rhs) const noexcept -> bool + { + return is_equal(rhs.elems, std::make_index_sequence()); + } + + auto operator!=(const basic_point_nd& rhs) const noexcept -> bool + { + return !(*this == rhs); + } + + friend auto operator+(const basic_point_nd& val) noexcept -> basic_point_nd + { + return val; + } + + friend auto operator-(const basic_point_nd& lhs) noexcept -> basic_point_nd + { + return invoke_op{}( + std::negate{}, lhs, std::make_index_sequence()); + } + +private: + struct invoke_op { + template + auto operator()(const P op, + const basic_point_nd& lhs, + std::index_sequence) const noexcept + -> basic_point_nd, dimensions> + { + static_assert(sizeof...(Ns) == dimensions); + return {op(lhs.elems[Ns])...}; + } + + template + auto operator()(const P op, + const basic_point_nd& lhs, + const basic_point_nd& rhs, + std::index_sequence) const noexcept + -> basic_point_nd, dimensions> + { + static_assert(sizeof...(Ns) == dimensions); + return {op(lhs.elems[Ns], rhs.elems[Ns])...}; + } + }; + + template + inline void op_assign(const U (&rhs)[dimensions], + P op, + std::index_sequence) noexcept + { + ((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...); + } + + template + inline void op_assign(U rhs, P op, std::index_sequence) noexcept + { + ((this->elems[Ns] = op(this->elems[Ns], rhs)), ...); + } + + template + inline void op_assign(const U (&rhs)[dimensions], + std::index_sequence) noexcept + { + ((this->elems[Ns] = rhs[Ns]), ...); + } + + template + auto is_equal(const U (&rhs)[dimensions], std::index_sequence) const + noexcept -> bool + { + return ((this->elems[Ns] == rhs[Ns]) && ... && true); + } + + template + auto negate(std::index_sequence) const noexcept -> basic_point_nd + { + return basic_point_nd{(-this->elems[Ns])...}; + } +}; + +} // namespace cppid::gm3d::detail + +namespace boost::qvm { + +template +struct vec_traits> +: public vec_traits< + cppid::gm3d::detail:: + basic_point_vector, T, N>> { +}; + +} // namespace boost::qvm + +#endif diff --git a/src/cppid/gm3d/point_2d.hpp b/src/cppid/gm3d/point_2d.hpp new file mode 100644 index 0000000..5d2d7d7 --- /dev/null +++ b/src/cppid/gm3d/point_2d.hpp @@ -0,0 +1,13 @@ +#ifndef CPPID_GM3D_POINT_2D_HPP +#define CPPID_GM3D_POINT_2D_HPP + +#include "detail/basic_point_nd.hpp" + +namespace cppid::gm3d { + +template +using point_2d = detail::basic_point_nd; + +} // namespace cppid::gm3d + +#endif diff --git a/src/cppid/gm3d/point_3d.hpp b/src/cppid/gm3d/point_3d.hpp new file mode 100644 index 0000000..f9b2c70 --- /dev/null +++ b/src/cppid/gm3d/point_3d.hpp @@ -0,0 +1,13 @@ +#ifndef CPPID_GM3D_POINT_3D_HPP +#define CPPID_GM3D_POINT_3D_HPP + +#include "detail/basic_point_nd.hpp" + +namespace cppid::gm3d { + +template +using point_3d = detail::basic_point_nd; + +} // namespace cppid::gm3d + +#endif diff --git a/test/point2.cpp b/test/point2.cpp new file mode 100644 index 0000000..6df5ee4 --- /dev/null +++ b/test/point2.cpp @@ -0,0 +1,68 @@ +#include +#include + +#include + +#define CATCH_CONFIG_MAIN +#include + +#include + +using cppid::gm3d::point_2d; +using point2f = point_2d; + +TEST_CASE("float_point2_test traits") +{ + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(point2f) == (sizeof(float) * 2)); + + REQUIRE(( + std::is_same_v::scalar_type>)); + REQUIRE(boost::qvm::vec_traits::dim == 2); +} + +TEST_CASE("float_point2_test initialization") +{ + { + auto vt = point2f{0}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + } + { + auto vt = point2f{1.5, 2.2}; + REQUIRE(vt.x() == 1.5f); + REQUIRE(vt.y() == 2.2f); + } + { + auto vt = point2f{point2f{1.5, 2.3}}; + REQUIRE(vt.x() == 1.5f); + REQUIRE(vt.y() == 2.3f); + } + { + auto vt = point2f{point_2d{0}}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + } + { + auto vt = point2f{0}; + vt = point_2d{0}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + } + { + auto vd = point_2d{0}; + point2f vt = vd; + CHECK(vt.x() == 0.0f); + CHECK(vt.y() == 0.0f); + } +} + +TEST_CASE("float_point2_test comparison") +{ + REQUIRE((point2f{0} == point2f{0, 0})); + REQUIRE((point2f{3.5} == point2f{3.5, 3.5})); + REQUIRE((point2f{-.5} == point2f{-.5, -.5})); + + REQUIRE((point2f{-.5} != point2f{-.5, -.1})); +} diff --git a/test/point3.cpp b/test/point3.cpp new file mode 100644 index 0000000..13f9c8f --- /dev/null +++ b/test/point3.cpp @@ -0,0 +1,74 @@ +#include +#include + +#include + +#define CATCH_CONFIG_MAIN +#include + +#include + +using cppid::gm3d::point_3d; +using point3f = point_3d; + +TEST_CASE("float_point3_test traits") +{ + REQUIRE(std::is_trivial_v); + REQUIRE(std::is_standard_layout_v); + REQUIRE(sizeof(point3f) == (sizeof(float) * 3)); + + REQUIRE(( + std::is_same_v::scalar_type>)); + REQUIRE(boost::qvm::vec_traits::dim == 3); +} + +TEST_CASE("float_point3_test initialization") +{ + { + auto vt = point3f{0}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + REQUIRE(vt.z() == 0.0f); + } + { + auto vt = point3f{1.5, 2.2, 8.9}; + REQUIRE(vt.x() == 1.5f); + REQUIRE(vt.y() == 2.2f); + REQUIRE(vt.z() == 8.9f); + } + { + auto vt = point3f{point3f{1.5, 2.3, 6.4}}; + REQUIRE(vt.x() == 1.5f); + REQUIRE(vt.y() == 2.3f); + REQUIRE(vt.z() == 6.4f); + } + { + auto vt = point3f{point_3d{0}}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + REQUIRE(vt.z() == 0.0f); + } + { + auto vt = point3f{0}; + vt = point_3d{0}; + REQUIRE(vt.x() == 0.0f); + REQUIRE(vt.y() == 0.0f); + REQUIRE(vt.z() == 0.0f); + } + { + auto vd = point_3d{0}; + point3f vt = vd; + CHECK(vt.x() == 0.0f); + CHECK(vt.y() == 0.0f); + CHECK(vt.z() == 0.0f); + } +} + +TEST_CASE("float_point3_test comparison") +{ + REQUIRE((point3f{0} == point3f{0, 0, 0})); + REQUIRE((point3f{3.5} == point3f{3.5, 3.5, 3.5})); + REQUIRE((point3f{-.5} == point3f{-.5, -.5, -.5})); + + REQUIRE((point3f{-.5} != point3f{-.5, -.1, -.5})); +} From f0193206f49b18e18dd6ac835689f63e9f917478 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Mon, 1 Apr 2019 21:18:35 +0800 Subject: [PATCH 15/19] refactor: move some contructors of vector and point to parent class --- src/cppid/gm3d/detail/basic_point_nd.hpp | 23 ++------------------ src/cppid/gm3d/detail/basic_point_vector.hpp | 12 ++++++++++ src/cppid/gm3d/detail/basic_vector_nd.hpp | 23 ++------------------ 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/src/cppid/gm3d/detail/basic_point_nd.hpp b/src/cppid/gm3d/detail/basic_point_nd.hpp index 1fb49a5..c73bc22 100644 --- a/src/cppid/gm3d/detail/basic_point_nd.hpp +++ b/src/cppid/gm3d/detail/basic_point_nd.hpp @@ -22,28 +22,9 @@ struct basic_point_nd : public basic_point_vector, T, N> { using basic_point_vector, T, N>::dimensions; - basic_point_nd() noexcept = default; - - explicit basic_point_nd(scalar_type s) noexcept - : basic_point_nd{s, std::make_index_sequence()} - { - } - - template> - basic_point_nd(scalar_type s, std::index_sequence) noexcept - : basic_point_nd{(static_cast(Ns), s)...} - { - } + using basic_point_vector, T, N>::basic_point_vector; - template< - typename... Us, - typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && - std::is_convertible_v)>> - basic_point_nd(Us... args) noexcept - : basic_point_vector, T, N>::basic_point_vector{args...} - { - } + basic_point_nd() noexcept = default; template()} + { + } + + template> + basic_point_vector(scalar_type s, std::index_sequence) noexcept + : basic_point_vector{(static_cast(Ns), s)...} + { + } + void x(scalar_type val) noexcept { elems[0] = val; diff --git a/src/cppid/gm3d/detail/basic_vector_nd.hpp b/src/cppid/gm3d/detail/basic_vector_nd.hpp index 0372a8e..84f5dc9 100644 --- a/src/cppid/gm3d/detail/basic_vector_nd.hpp +++ b/src/cppid/gm3d/detail/basic_vector_nd.hpp @@ -23,28 +23,9 @@ struct basic_vector_nd using basic_point_vector, T, N>::dimensions; - basic_vector_nd() noexcept = default; - - explicit basic_vector_nd(scalar_type s) noexcept - : basic_vector_nd{s, std::make_index_sequence()} - { - } - - template> - basic_vector_nd(scalar_type s, std::index_sequence) noexcept - : basic_vector_nd{(static_cast(Ns), s)...} - { - } + using basic_point_vector, T, N>::basic_point_vector; - template< - typename... Us, - typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && - std::is_convertible_v)>> - basic_vector_nd(Us... args) noexcept - : basic_point_vector, T, N>::basic_point_vector{args...} - { - } + basic_vector_nd() noexcept = default; template Date: Mon, 1 Apr 2019 22:16:23 +0800 Subject: [PATCH 16/19] refactor: add points to all.hpp --- src/cppid/gm3d/all.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cppid/gm3d/all.hpp b/src/cppid/gm3d/all.hpp index 849b70c..2630b1b 100644 --- a/src/cppid/gm3d/all.hpp +++ b/src/cppid/gm3d/all.hpp @@ -3,6 +3,8 @@ #include "mat3.hpp" #include "mat4.hpp" +#include "point_2d.hpp" +#include "point_3d.hpp" #include "rgba.hpp" #include "vector_2d.hpp" #include "vector_3d.hpp" From c6e695ac34c63a0d52edf5a080569a0ffe4b16a0 Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Mon, 1 Apr 2019 22:21:10 +0800 Subject: [PATCH 17/19] feat: constexpr member functions --- src/cppid/gm3d/detail/basic_point_nd.hpp | 60 +++---- src/cppid/gm3d/detail/basic_point_vector.hpp | 38 ++--- src/cppid/gm3d/detail/basic_rgba.hpp | 38 ++--- src/cppid/gm3d/detail/basic_vector_nd.hpp | 146 +++++++++-------- src/cppid/gm3d/mat3.hpp | 61 +++---- src/cppid/gm3d/mat4.hpp | 157 ++++++++++--------- src/cppid/gm3d/rgba.hpp | 4 +- 7 files changed, 268 insertions(+), 236 deletions(-) diff --git a/src/cppid/gm3d/detail/basic_point_nd.hpp b/src/cppid/gm3d/detail/basic_point_nd.hpp index c73bc22..f82d78c 100644 --- a/src/cppid/gm3d/detail/basic_point_nd.hpp +++ b/src/cppid/gm3d/detail/basic_point_nd.hpp @@ -24,12 +24,12 @@ struct basic_point_nd : public basic_point_vector, T, N> { using basic_point_vector, T, N>::basic_point_vector; - basic_point_nd() noexcept = default; + constexpr basic_point_nd() noexcept = default; template>* = nullptr> - explicit basic_point_nd(basic_point_nd v) noexcept + explicit constexpr basic_point_nd(basic_point_nd v) noexcept : basic_point_nd{v, std::make_index_sequence()} { } @@ -39,8 +39,8 @@ struct basic_point_nd : public basic_point_vector, T, N> { std::enable_if_t< (sizeof...(Ns) == dimensions) && detail::is_explicit_constructible_v>* = nullptr> - basic_point_nd(basic_point_nd v, - std::index_sequence) noexcept + constexpr basic_point_nd(basic_point_nd v, + std::index_sequence) noexcept : basic_point_nd{v.elems[Ns]...} { } @@ -48,7 +48,7 @@ struct basic_point_nd : public basic_point_vector, T, N> { template>* = nullptr> - basic_point_nd(basic_point_nd v) noexcept + constexpr basic_point_nd(basic_point_nd v) noexcept : basic_point_nd{v, std::make_index_sequence()} { } @@ -58,37 +58,39 @@ struct basic_point_nd : public basic_point_vector, T, N> { std::enable_if_t< (sizeof...(Ns) == dimensions) && detail::is_implicit_constructible_v>* = nullptr> - basic_point_nd(basic_point_nd v, - std::index_sequence) noexcept + constexpr basic_point_nd(basic_point_nd v, + std::index_sequence) noexcept : basic_point_nd{scalar_type(v.elems[Ns])...} { } template>> - auto operator=(const basic_point_nd rhs) noexcept + constexpr auto operator=(const basic_point_nd rhs) noexcept -> basic_point_nd& { op_assign(rhs.elems, std::make_index_sequence()); return *this; } - auto operator==(const basic_point_nd& rhs) const noexcept -> bool + constexpr auto operator==(const basic_point_nd& rhs) const noexcept -> bool { return is_equal(rhs.elems, std::make_index_sequence()); } - auto operator!=(const basic_point_nd& rhs) const noexcept -> bool + constexpr auto operator!=(const basic_point_nd& rhs) const noexcept -> bool { return !(*this == rhs); } - friend auto operator+(const basic_point_nd& val) noexcept -> basic_point_nd + friend constexpr auto operator+(const basic_point_nd& val) noexcept + -> basic_point_nd { return val; } - friend auto operator-(const basic_point_nd& lhs) noexcept -> basic_point_nd + friend constexpr auto operator-(const basic_point_nd& lhs) noexcept + -> basic_point_nd { return invoke_op{}( std::negate{}, lhs, std::make_index_sequence()); @@ -97,9 +99,9 @@ struct basic_point_nd : public basic_point_vector, T, N> { private: struct invoke_op { template - auto operator()(const P op, - const basic_point_nd& lhs, - std::index_sequence) const noexcept + constexpr auto operator()(const P op, + const basic_point_nd& lhs, + std::index_sequence) const noexcept -> basic_point_nd, dimensions> { static_assert(sizeof...(Ns) == dimensions); @@ -107,10 +109,10 @@ struct basic_point_nd : public basic_point_vector, T, N> { } template - auto operator()(const P op, - const basic_point_nd& lhs, - const basic_point_nd& rhs, - std::index_sequence) const noexcept + constexpr auto operator()(const P op, + const basic_point_nd& lhs, + const basic_point_nd& rhs, + std::index_sequence) const noexcept -> basic_point_nd, dimensions> { static_assert(sizeof...(Ns) == dimensions); @@ -119,35 +121,37 @@ struct basic_point_nd : public basic_point_vector, T, N> { }; template - inline void op_assign(const U (&rhs)[dimensions], - P op, - std::index_sequence) noexcept + inline constexpr void op_assign(const U (&rhs)[dimensions], + P op, + std::index_sequence) noexcept { ((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...); } template - inline void op_assign(U rhs, P op, std::index_sequence) noexcept + inline constexpr void + op_assign(U rhs, P op, std::index_sequence) noexcept { ((this->elems[Ns] = op(this->elems[Ns], rhs)), ...); } template - inline void op_assign(const U (&rhs)[dimensions], - std::index_sequence) noexcept + inline constexpr void op_assign(const U (&rhs)[dimensions], + std::index_sequence) noexcept { ((this->elems[Ns] = rhs[Ns]), ...); } template - auto is_equal(const U (&rhs)[dimensions], std::index_sequence) const - noexcept -> bool + constexpr auto is_equal(const U (&rhs)[dimensions], + std::index_sequence) const noexcept -> bool { return ((this->elems[Ns] == rhs[Ns]) && ... && true); } template - auto negate(std::index_sequence) const noexcept -> basic_point_nd + constexpr auto negate(std::index_sequence) const noexcept + -> basic_point_nd { return basic_point_nd{(-this->elems[Ns])...}; } diff --git a/src/cppid/gm3d/detail/basic_point_vector.hpp b/src/cppid/gm3d/detail/basic_point_vector.hpp index b24ac9e..b370e6d 100644 --- a/src/cppid/gm3d/detail/basic_point_vector.hpp +++ b/src/cppid/gm3d/detail/basic_point_vector.hpp @@ -13,76 +13,76 @@ namespace cppid::gm3d::detail { template struct basic_point_vector { - using scalar_type = T; static constexpr auto dimensions = N; scalar_type elems[dimensions]; - basic_point_vector() noexcept = default; + constexpr basic_point_vector() noexcept = default; template< typename... Us, typename = std::enable_if_t<((sizeof...(Us) == dimensions) && ... && std::is_convertible_v)>> - basic_point_vector(Us... args) noexcept + constexpr basic_point_vector(Us... args) noexcept : elems{scalar_type(args)...} { } - explicit basic_point_vector(scalar_type s) noexcept + explicit constexpr basic_point_vector(scalar_type s) noexcept : basic_point_vector{s, std::make_index_sequence()} { } template> - basic_point_vector(scalar_type s, std::index_sequence) noexcept + constexpr basic_point_vector(scalar_type s, + std::index_sequence) noexcept : basic_point_vector{(static_cast(Ns), s)...} { } - void x(scalar_type val) noexcept + constexpr void x(scalar_type val) noexcept { elems[0] = val; } - void y(scalar_type val) noexcept + constexpr void y(scalar_type val) noexcept { elems[1] = val; } template= 3)>* = nullptr> - void z(scalar_type val) noexcept + constexpr void z(scalar_type val) noexcept { elems[2] = val; } template= 4)>* = nullptr> - void w(scalar_type val) noexcept + constexpr void w(scalar_type val) noexcept { elems[3] = val; } - auto x() const noexcept -> scalar_type + constexpr auto x() const noexcept -> scalar_type { return elems[0]; } - auto y() const noexcept -> scalar_type + constexpr auto y() const noexcept -> scalar_type { return elems[1]; } template= 3)>* = nullptr> - auto z() const noexcept -> scalar_type + constexpr auto z() const noexcept -> scalar_type { return elems[2]; } template= 4)>* = nullptr> - auto w() const noexcept -> scalar_type + constexpr auto w() const noexcept -> scalar_type { return elems[3]; } @@ -100,28 +100,28 @@ struct vec_traits> { static constexpr int dim = point_vector_type::dimensions; template - static inline auto write_element(point_vector_type& v) noexcept + static inline constexpr auto write_element(point_vector_type& v) noexcept -> scalar_type& { return v.elems[I]; } template - static inline auto read_element(point_vector_type const& v) noexcept + static inline constexpr auto read_element(point_vector_type const& v) noexcept -> scalar_type { return v.elems[I]; } - static inline auto write_element_idx(int i, point_vector_type& v) noexcept + static inline constexpr auto write_element_idx(int i, + point_vector_type& v) noexcept -> scalar_type& { return v.elems[i]; } - static inline auto read_element_idx(int i, - point_vector_type const& v) noexcept - -> scalar_type + static inline constexpr auto + read_element_idx(int i, point_vector_type const& v) noexcept -> scalar_type { return v.elems[i]; } diff --git a/src/cppid/gm3d/detail/basic_rgba.hpp b/src/cppid/gm3d/detail/basic_rgba.hpp index 6b9bc11..8b443d0 100644 --- a/src/cppid/gm3d/detail/basic_rgba.hpp +++ b/src/cppid/gm3d/detail/basic_rgba.hpp @@ -8,22 +8,22 @@ class basic_rgba { public: using scalar_type = T; - basic_rgba() noexcept = default; + constexpr basic_rgba() noexcept = default; - explicit basic_rgba(scalar_type s) noexcept + explicit constexpr basic_rgba(scalar_type s) noexcept : basic_rgba{s, s, s, s} { } - basic_rgba(scalar_type s, scalar_type a) noexcept + constexpr basic_rgba(scalar_type s, scalar_type a) noexcept : basic_rgba{s, s, s, a} { } - basic_rgba(scalar_type r, - scalar_type g, - scalar_type b, - scalar_type a) noexcept + constexpr basic_rgba(scalar_type r, + scalar_type g, + scalar_type b, + scalar_type a) noexcept : r_{r} , g_{g} , b_{b} @@ -31,55 +31,55 @@ class basic_rgba { { } - void r(scalar_type val) noexcept + constexpr void r(scalar_type val) noexcept { r_ = val; } - void g(scalar_type val) noexcept + constexpr void g(scalar_type val) noexcept { g_ = val; } - void b(scalar_type val) noexcept + constexpr void b(scalar_type val) noexcept { b_ = val; } - void a(scalar_type val) noexcept + constexpr void a(scalar_type val) noexcept { a_ = val; } - auto r() const noexcept -> scalar_type + constexpr auto r() const noexcept -> scalar_type { return r_; } - auto g() const noexcept -> scalar_type + constexpr auto g() const noexcept -> scalar_type { return g_; } - auto b() const noexcept -> scalar_type + constexpr auto b() const noexcept -> scalar_type { return b_; } - auto a() const noexcept -> scalar_type + constexpr auto a() const noexcept -> scalar_type { return a_; } - friend auto operator==(const basic_rgba& lhs, const basic_rgba& rhs) noexcept - -> bool + friend constexpr auto operator==(const basic_rgba& lhs, + const basic_rgba& rhs) noexcept -> bool { return lhs.r() == rhs.r() && lhs.g() == rhs.g() && lhs.b() == rhs.b() && lhs.a() == rhs.a(); } - friend auto operator!=(const basic_rgba& lhs, const basic_rgba& rhs) noexcept - -> bool + friend constexpr auto operator!=(const basic_rgba& lhs, + const basic_rgba& rhs) noexcept -> bool { return !(lhs == rhs); } diff --git a/src/cppid/gm3d/detail/basic_vector_nd.hpp b/src/cppid/gm3d/detail/basic_vector_nd.hpp index 84f5dc9..5b6585e 100644 --- a/src/cppid/gm3d/detail/basic_vector_nd.hpp +++ b/src/cppid/gm3d/detail/basic_vector_nd.hpp @@ -25,12 +25,12 @@ struct basic_vector_nd using basic_point_vector, T, N>::basic_point_vector; - basic_vector_nd() noexcept = default; + constexpr basic_vector_nd() noexcept = default; template>* = nullptr> - explicit basic_vector_nd(basic_vector_nd v) noexcept + explicit constexpr basic_vector_nd(basic_vector_nd v) noexcept : basic_vector_nd{v, std::make_index_sequence()} { } @@ -40,8 +40,8 @@ struct basic_vector_nd std::enable_if_t< (sizeof...(Ns) == dimensions) && detail::is_explicit_constructible_v>* = nullptr> - basic_vector_nd(basic_vector_nd v, - std::index_sequence) noexcept + constexpr basic_vector_nd(basic_vector_nd v, + std::index_sequence) noexcept : basic_vector_nd{v.elems[Ns]...} { } @@ -49,7 +49,7 @@ struct basic_vector_nd template>* = nullptr> - basic_vector_nd(basic_vector_nd v) noexcept + constexpr basic_vector_nd(basic_vector_nd v) noexcept : basic_vector_nd{v, std::make_index_sequence()} { } @@ -59,113 +59,120 @@ struct basic_vector_nd std::enable_if_t< (sizeof...(Ns) == dimensions) && detail::is_implicit_constructible_v>* = nullptr> - basic_vector_nd(basic_vector_nd v, - std::index_sequence) noexcept + constexpr basic_vector_nd(basic_vector_nd v, + std::index_sequence) noexcept : basic_vector_nd{scalar_type(v.elems[Ns])...} { } template>> - auto operator=(const basic_vector_nd rhs) noexcept + constexpr auto operator=(const basic_vector_nd rhs) noexcept -> basic_vector_nd& { op_assign(rhs.elems, std::make_index_sequence()); return *this; } - auto operator+=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& + constexpr auto operator+=(const basic_vector_nd& rhs) noexcept + -> basic_vector_nd& { op_assign(rhs.elems, std::plus{}, std::make_index_sequence()); return *this; } - auto operator+=(scalar_type rhs) noexcept -> basic_vector_nd& + constexpr auto operator+=(scalar_type rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::plus{}, std::make_index_sequence()); return *this; } - auto operator-=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& + constexpr auto operator-=(const basic_vector_nd& rhs) noexcept + -> basic_vector_nd& { op_assign(rhs.elems, std::minus{}, std::make_index_sequence()); return *this; } - auto operator-=(scalar_type rhs) noexcept -> basic_vector_nd& + constexpr auto operator-=(scalar_type rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::minus{}, std::make_index_sequence()); return *this; } - auto operator*=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& + constexpr auto operator*=(const basic_vector_nd& rhs) noexcept + -> basic_vector_nd& { op_assign( rhs.elems, std::multiplies{}, std::make_index_sequence()); return *this; } - auto operator*=(scalar_type rhs) noexcept -> basic_vector_nd& + constexpr auto operator*=(scalar_type rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::multiplies{}, std::make_index_sequence()); return *this; } - auto operator/=(const basic_vector_nd& rhs) noexcept -> basic_vector_nd& + constexpr auto operator/=(const basic_vector_nd& rhs) noexcept + -> basic_vector_nd& { op_assign( rhs.elems, std::divides{}, std::make_index_sequence()); return *this; } - auto operator/=(scalar_type rhs) noexcept -> basic_vector_nd& + constexpr auto operator/=(scalar_type rhs) noexcept -> basic_vector_nd& { op_assign(rhs, std::divides{}, std::make_index_sequence()); return *this; } - auto operator==(const basic_vector_nd& rhs) const noexcept -> bool + constexpr auto operator==(const basic_vector_nd& rhs) const noexcept -> bool { return is_equal(rhs.elems, std::make_index_sequence()); } - auto operator!=(const basic_vector_nd& rhs) const noexcept -> bool + constexpr auto operator!=(const basic_vector_nd& rhs) const noexcept -> bool { return !((*this) == rhs); } - auto dot(const basic_vector_nd& other) const noexcept -> scalar_type + constexpr auto dot(const basic_vector_nd& other) const noexcept -> scalar_type { return dot(other, std::make_index_sequence()); } - auto magnitude() const noexcept -> scalar_type + constexpr auto magnitude() const noexcept -> scalar_type { return std::sqrt(dot(*this)); } - auto magnitude_squared() const noexcept -> scalar_type + constexpr auto magnitude_squared() const noexcept -> scalar_type { return dot(*this); } - auto to_unit() const noexcept -> basic_vector_nd + constexpr auto to_unit() const noexcept -> basic_vector_nd { return *this / magnitude(); } - auto reflect(const basic_vector_nd& n) const noexcept -> basic_vector_nd + constexpr auto reflect(const basic_vector_nd& n) const noexcept + -> basic_vector_nd { return *this - 2 * dot(n) * n; } template* = nullptr> - auto cross(const basic_vector_nd& other) const noexcept -> basic_vector_nd + constexpr auto cross(const basic_vector_nd& other) const noexcept + -> basic_vector_nd { return boost::qvm::cross(*this, other); } - friend auto operator+(const basic_vector_nd& val) noexcept -> basic_vector_nd + friend constexpr auto operator+(const basic_vector_nd& val) noexcept + -> basic_vector_nd { return val; } @@ -173,8 +180,9 @@ struct basic_vector_nd template, scalar_type, U>>> - friend auto operator+(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept + friend constexpr auto + operator+(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd, scalar_type, U>, dimensions> { @@ -182,19 +190,21 @@ struct basic_vector_nd std::plus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator+(const basic_vector_nd& lhs, scalar_type rhs) noexcept - -> basic_vector_nd + friend constexpr auto operator+(const basic_vector_nd& lhs, + scalar_type rhs) noexcept -> basic_vector_nd { return lhs + basic_vector_nd{rhs}; } - friend auto operator+(scalar_type lhs, const basic_vector_nd& rhs) noexcept + friend constexpr auto operator+(scalar_type lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} + rhs; } - friend auto operator-(const basic_vector_nd& lhs) noexcept -> basic_vector_nd + friend constexpr auto operator-(const basic_vector_nd& lhs) noexcept + -> basic_vector_nd { return invoke_op{}( std::negate{}, lhs, std::make_index_sequence()); @@ -203,8 +213,9 @@ struct basic_vector_nd template, scalar_type, U>>> - friend auto operator-(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept + friend constexpr auto + operator-(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd, scalar_type, U>, dimensions> { @@ -212,13 +223,14 @@ struct basic_vector_nd std::minus{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator-(const basic_vector_nd& lhs, scalar_type rhs) noexcept - -> basic_vector_nd + friend constexpr auto operator-(const basic_vector_nd& lhs, + scalar_type rhs) noexcept -> basic_vector_nd { return lhs - basic_vector_nd{rhs}; } - friend auto operator-(scalar_type lhs, const basic_vector_nd& rhs) noexcept + friend constexpr auto operator-(scalar_type lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} - rhs; @@ -227,8 +239,9 @@ struct basic_vector_nd template, scalar_type, U>>> - friend auto operator*(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept + friend constexpr auto + operator*(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd, scalar_type, U>, dimensions> { @@ -236,13 +249,14 @@ struct basic_vector_nd std::multiplies{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator*(const basic_vector_nd& lhs, scalar_type rhs) noexcept - -> basic_vector_nd + friend constexpr auto operator*(const basic_vector_nd& lhs, + scalar_type rhs) noexcept -> basic_vector_nd { return lhs * basic_vector_nd{rhs}; } - friend auto operator*(scalar_type lhs, const basic_vector_nd& rhs) noexcept + friend constexpr auto operator*(scalar_type lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} * rhs; @@ -251,8 +265,9 @@ struct basic_vector_nd template, scalar_type, U>>> - friend auto operator/(const basic_vector_nd& lhs, - const basic_vector_nd& rhs) noexcept + friend constexpr auto + operator/(const basic_vector_nd& lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd, scalar_type, U>, dimensions> { @@ -260,13 +275,14 @@ struct basic_vector_nd std::divides{}, lhs, rhs, std::make_index_sequence()); } - friend auto operator/(const basic_vector_nd& lhs, scalar_type rhs) noexcept - -> basic_vector_nd + friend constexpr auto operator/(const basic_vector_nd& lhs, + scalar_type rhs) noexcept -> basic_vector_nd { return lhs / basic_vector_nd{rhs}; } - friend auto operator/(scalar_type lhs, const basic_vector_nd& rhs) noexcept + friend constexpr auto operator/(scalar_type lhs, + const basic_vector_nd& rhs) noexcept -> basic_vector_nd { return basic_vector_nd{lhs} / rhs; @@ -275,9 +291,9 @@ struct basic_vector_nd private: struct invoke_op { template - auto operator()(const P op, - const basic_vector_nd& lhs, - std::index_sequence) const noexcept + constexpr auto operator()(const P op, + const basic_vector_nd& lhs, + std::index_sequence) const noexcept -> basic_vector_nd, dimensions> { static_assert(sizeof...(Ns) == dimensions); @@ -285,10 +301,10 @@ struct basic_vector_nd } template - auto operator()(const P op, - const basic_vector_nd& lhs, - const basic_vector_nd& rhs, - std::index_sequence) const noexcept + constexpr auto operator()(const P op, + const basic_vector_nd& lhs, + const basic_vector_nd& rhs, + std::index_sequence) const noexcept -> basic_vector_nd, dimensions> { static_assert(sizeof...(Ns) == dimensions); @@ -297,42 +313,44 @@ struct basic_vector_nd }; template - inline void op_assign(const U (&rhs)[dimensions], - P op, - std::index_sequence) noexcept + inline constexpr void op_assign(const U (&rhs)[dimensions], + P op, + std::index_sequence) noexcept { ((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...); } template - inline void op_assign(U rhs, P op, std::index_sequence) noexcept + inline constexpr void + op_assign(U rhs, P op, std::index_sequence) noexcept { ((this->elems[Ns] = op(this->elems[Ns], rhs)), ...); } template - inline void op_assign(const U (&rhs)[dimensions], - std::index_sequence) noexcept + inline constexpr void op_assign(const U (&rhs)[dimensions], + std::index_sequence) noexcept { ((this->elems[Ns] = rhs[Ns]), ...); } template - auto is_equal(const U (&rhs)[dimensions], std::index_sequence) const - noexcept -> bool + constexpr auto is_equal(const U (&rhs)[dimensions], + std::index_sequence) const noexcept -> bool { return ((this->elems[Ns] == rhs[Ns]) && ... && true); } template - auto negate(std::index_sequence) const noexcept -> basic_vector_nd + constexpr auto negate(std::index_sequence) const noexcept + -> basic_vector_nd { return basic_vector_nd{(-this->elems[Ns])...}; } template - auto dot(const basic_vector_nd& other, std::index_sequence) const - noexcept -> scalar_type + constexpr auto dot(const basic_vector_nd& other, + std::index_sequence) const noexcept -> scalar_type { return ((this->elems[Ns] * other.elems[Ns]) + ... + 0); } diff --git a/src/cppid/gm3d/mat3.hpp b/src/cppid/gm3d/mat3.hpp index 80e9f32..bb38a49 100644 --- a/src/cppid/gm3d/mat3.hpp +++ b/src/cppid/gm3d/mat3.hpp @@ -11,14 +11,15 @@ template struct mat3 { T m[9]; - mat3() noexcept = default; + constexpr mat3() noexcept = default; - explicit mat3(T s) noexcept + explicit constexpr mat3(T s) noexcept : mat3{s, 0, 0, 0, s, 0, 0, 0, s} { } - mat3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22) noexcept + constexpr mat3( + T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22) noexcept : m{m00, m01, m02, m10, m11, m12, m20, m21, m22} { } @@ -26,7 +27,7 @@ struct mat3 { template && !std::is_convertible_v>* = nullptr> - explicit mat3(const mat4& m4) noexcept + explicit constexpr mat3(const mat4& m4) noexcept : mat3(m4.m[0], m4.m[1], m4.m[2], @@ -58,7 +59,7 @@ struct mat3 { template && !std::is_convertible_v>* = nullptr> - explicit mat3(const mat3& m3) noexcept + explicit constexpr mat3(const mat3& m3) noexcept : mat3(m3.m[0], m3.m[1], m3.m[2], @@ -74,7 +75,7 @@ struct mat3 { template && std::is_convertible_v>* = nullptr> - mat3(const mat3& m3) noexcept + constexpr mat3(const mat3& m3) noexcept : mat3(m3.m[0], m3.m[1], m3.m[2], @@ -87,92 +88,92 @@ struct mat3 { { } - void m00(T val) noexcept + constexpr void m00(T val) noexcept { m[0] = val; } - void m01(T val) noexcept + constexpr void m01(T val) noexcept { m[1] = val; } - void m02(T val) noexcept + constexpr void m02(T val) noexcept { m[2] = val; } - void m10(T val) noexcept + constexpr void m10(T val) noexcept { m[3] = val; } - void m11(T val) noexcept + constexpr void m11(T val) noexcept { m[4] = val; } - void m12(T val) noexcept + constexpr void m12(T val) noexcept { m[5] = val; } - void m20(T val) noexcept + constexpr void m20(T val) noexcept { m[6] = val; } - void m21(T val) noexcept + constexpr void m21(T val) noexcept { m[7] = val; } - void m22(T val) noexcept + constexpr void m22(T val) noexcept { m[8] = val; } - auto m00() const noexcept -> T + constexpr auto m00() const noexcept -> T { return m[0]; } - auto m01() const noexcept -> T + constexpr auto m01() const noexcept -> T { return m[1]; } - auto m02() const noexcept -> T + constexpr auto m02() const noexcept -> T { return m[2]; } - auto m10() const noexcept -> T + constexpr auto m10() const noexcept -> T { return m[3]; } - auto m11() const noexcept -> T + constexpr auto m11() const noexcept -> T { return m[4]; } - auto m12() const noexcept -> T + constexpr auto m12() const noexcept -> T { return m[5]; } - auto m20() const noexcept -> T + constexpr auto m20() const noexcept -> T { return m[6]; } - auto m21() const noexcept -> T + constexpr auto m21() const noexcept -> T { return m[7]; } - auto m22() const noexcept -> T + constexpr auto m22() const noexcept -> T { return m[8]; } @@ -189,25 +190,29 @@ struct mat_traits> { static int const cols = 3; template - static scalar_type read_element(cppid::gm3d::mat3 const& x) + static constexpr auto read_element(cppid::gm3d::mat3 const& x) + -> scalar_type { return x.m[Row * 3 + Col]; } template - static scalar_type& write_element(cppid::gm3d::mat3& x) + static constexpr auto write_element(cppid::gm3d::mat3& x) + -> scalar_type& { return x.m[Row * 3 + Col]; } - static scalar_type + static constexpr auto read_element_idx(int row, int col, cppid::gm3d::mat3 const& x) + -> scalar_type { return x.m[row * 3 + col]; } - static scalar_type& + static constexpr auto write_element_idx(int row, int col, cppid::gm3d::mat3& x) + -> scalar_type& { return x.m[row * 3 + col]; } diff --git a/src/cppid/gm3d/mat4.hpp b/src/cppid/gm3d/mat4.hpp index 249dafd..954010f 100644 --- a/src/cppid/gm3d/mat4.hpp +++ b/src/cppid/gm3d/mat4.hpp @@ -16,29 +16,29 @@ template struct mat4 { T m[16]; - mat4() noexcept = default; + constexpr mat4() noexcept = default; - explicit mat4(T s) noexcept + explicit constexpr mat4(T s) noexcept : mat4{s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, s} { } - mat4(T m00, - T m01, - T m02, - T m03, - T m10, - T m11, - T m12, - T m13, - T m20, - T m21, - T m22, - T m23, - T m30, - T m31, - T m32, - T m33) noexcept + constexpr mat4(T m00, + T m01, + T m02, + T m03, + T m10, + T m11, + T m12, + T m13, + T m20, + T m21, + T m22, + T m23, + T m30, + T m31, + T m32, + T m33) noexcept : m{m00, m01, m02, @@ -61,7 +61,7 @@ struct mat4 { template && !std::is_convertible_v>* = nullptr> - explicit mat4(const mat4& m) noexcept + explicit constexpr mat4(const mat4& m) noexcept : mat4(m.m[0], m.m[1], m.m[2], @@ -84,7 +84,7 @@ struct mat4 { template && std::is_convertible_v>* = nullptr> - explicit mat4(const mat4& m) noexcept + explicit constexpr mat4(const mat4& m) noexcept : mat4(m.m[0], m.m[1], m.m[2], @@ -104,7 +104,7 @@ struct mat4 { { } - auto operator*=(const mat4& m4) noexcept -> mat4& + constexpr auto operator*=(const mat4& m4) noexcept -> mat4& { const auto m00 = m[0], m01 = m[1], m02 = m[2], m03 = m[3], m10 = m[4], m11 = m[5], m12 = m[6], m13 = m[7], m20 = m[8], m21 = m[9], @@ -136,12 +136,12 @@ struct mat4 { return *this; } - auto operator*(const mat4& m4) const noexcept -> mat4 + constexpr auto operator*(const mat4& m4) const noexcept -> mat4 { return mat4{*this} *= m4; } - auto operator*=(T s) noexcept -> mat4& + constexpr auto operator*=(T s) noexcept -> mat4& { m[0] *= s; m[1] *= s; @@ -163,182 +163,182 @@ struct mat4 { return *this; } - auto operator*(T s) const noexcept -> mat4 + constexpr auto operator*(T s) const noexcept -> mat4 { return mat4{*this} *= s; } - void m00(T val) noexcept + constexpr void m00(T val) noexcept { m[0] = val; } - void m01(T val) noexcept + constexpr void m01(T val) noexcept { m[1] = val; } - void m02(T val) noexcept + constexpr void m02(T val) noexcept { m[2] = val; } - void m03(T val) noexcept + constexpr void m03(T val) noexcept { m[3] = val; } - void m10(T val) noexcept + constexpr void m10(T val) noexcept { m[4] = val; } - void m11(T val) noexcept + constexpr void m11(T val) noexcept { m[5] = val; } - void m12(T val) noexcept + constexpr void m12(T val) noexcept { m[6] = val; } - void m13(T val) noexcept + constexpr void m13(T val) noexcept { m[7] = val; } - void m20(T val) noexcept + constexpr void m20(T val) noexcept { m[8] = val; } - void m21(T val) noexcept + constexpr void m21(T val) noexcept { m[9] = val; } - void m22(T val) noexcept + constexpr void m22(T val) noexcept { m[10] = val; } - void m23(T val) noexcept + constexpr void m23(T val) noexcept { m[11] = val; } - void m30(T val) noexcept + constexpr void m30(T val) noexcept { m[12] = val; } - void m31(T val) noexcept + constexpr void m31(T val) noexcept { m[13] = val; } - void m32(T val) noexcept + constexpr void m32(T val) noexcept { m[14] = val; } - void m33(T val) noexcept + constexpr void m33(T val) noexcept { m[15] = val; } - auto m00() const noexcept -> T + constexpr auto m00() const noexcept -> T { return m[0]; } - auto m01() const noexcept -> T + constexpr auto m01() const noexcept -> T { return m[1]; } - auto m02() const noexcept -> T + constexpr auto m02() const noexcept -> T { return m[2]; } - auto m03() const noexcept -> T + constexpr auto m03() const noexcept -> T { return m[3]; } - auto m10() const noexcept -> T + constexpr auto m10() const noexcept -> T { return m[4]; } - auto m11() const noexcept -> T + constexpr auto m11() const noexcept -> T { return m[5]; } - auto m12() const noexcept -> T + constexpr auto m12() const noexcept -> T { return m[6]; } - auto m13() const noexcept -> T + constexpr auto m13() const noexcept -> T { return m[7]; } - auto m20() const noexcept -> T + constexpr auto m20() const noexcept -> T { return m[8]; } - auto m21() const noexcept -> T + constexpr auto m21() const noexcept -> T { return m[9]; } - auto m22() const noexcept -> T + constexpr auto m22() const noexcept -> T { return m[10]; } - auto m23() const noexcept -> T + constexpr auto m23() const noexcept -> T { return m[11]; } - auto m30() const noexcept -> T + constexpr auto m30() const noexcept -> T { return m[12]; } - auto m31() const noexcept -> T + constexpr auto m31() const noexcept -> T { return m[13]; } - auto m32() const noexcept -> T + constexpr auto m32() const noexcept -> T { return m[14]; } - auto m33() const noexcept -> T + constexpr auto m33() const noexcept -> T { return m[15]; } - auto scale(T s) noexcept -> mat4& + constexpr auto scale(T s) noexcept -> mat4& { return scale(s, s, s); } - auto scale(const vector_3d& v) noexcept -> mat4& + constexpr auto scale(const vector_3d& v) noexcept -> mat4& { return scale(v.x(), v.y(), v.z()); } - auto scale(T x, T y, T z) noexcept -> mat4& + constexpr auto scale(T x, T y, T z) noexcept -> mat4& { m[0] *= x; m[5] *= y; @@ -346,19 +346,19 @@ struct mat4 { return *this; } - auto identity() noexcept -> mat4& + constexpr auto identity() noexcept -> mat4& { boost::qvm::set_identity(*this); return *this; } - auto rotate(const vector_3d& origin, T a) noexcept -> mat4& + constexpr auto rotate(const vector_3d& origin, T a) noexcept -> mat4& { boost::qvm::rotate(*this, origin, a); return *this; } - auto translate(T x, T y, T z) noexcept -> mat4& + constexpr auto translate(T x, T y, T z) noexcept -> mat4& { const auto m03 = m[3]; const auto m13 = m[7]; @@ -383,12 +383,12 @@ struct mat4 { return *this; } - auto translate(const vector_3d& v) noexcept -> mat4& + constexpr auto translate(const vector_3d& v) noexcept -> mat4& { return translate(v.x(), v.y(), v.z()); } - auto frustum(T l, T r, T b, T t, T n, T f) noexcept -> mat4& + constexpr auto frustum(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 * n / (r - l); m[5] = 2 * n / (t - b); @@ -408,7 +408,7 @@ struct mat4 { return *this; } - auto orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> mat4& + constexpr auto orthogonal(T l, T r, T b, T t, T n, T f) noexcept -> mat4& { m[0] = 2 / (r - l); m[5] = 2 / (t - b); @@ -423,8 +423,8 @@ struct mat4 { return *this; } - auto lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept - -> mat4& + constexpr auto + lookat(T ex, T ey, T ez, T lx, T ly, T lz, T ux, T uy, T uz) noexcept -> mat4& { auto fx = ex - lx; auto fy = ey - ly; @@ -469,28 +469,29 @@ struct mat4 { return *this; } - auto lookat(vector_3d e, vector_3d l, vector_3d u) noexcept -> mat4& + constexpr auto lookat(vector_3d e, vector_3d l, vector_3d u) noexcept + -> mat4& { return lookat( e.x(), e.y(), e.z(), l.x(), l.y(), l.z(), u.x(), u.y(), u.z()); } - auto perspective(T fov, T a, T n, T f) noexcept -> mat4& + constexpr auto perspective(T fov, T a, T n, T f) noexcept -> mat4& { return *this = boost::qvm::perspective_rh(fov, a, n, f); } - auto is_invertible() const noexcept -> bool + constexpr auto is_invertible() const noexcept -> bool { return determinant() != T{0}; } - auto inverse() noexcept -> mat4& + constexpr auto inverse() noexcept -> mat4& { return *this = boost::qvm::inverse(*this); } - auto transpose() noexcept -> mat4& + constexpr auto transpose() noexcept -> mat4& { *this = {m[0], m[4], @@ -528,25 +529,29 @@ struct mat_traits> { static int const cols = 4; template - static scalar_type read_element(cppid::gm3d::mat4 const& x) + static constexpr auto read_element(cppid::gm3d::mat4 const& x) + -> scalar_type { return x.m[Row * 4 + Col]; } template - static scalar_type& write_element(cppid::gm3d::mat4& x) + static constexpr auto write_element(cppid::gm3d::mat4& x) + -> scalar_type& { return x.m[Row * 4 + Col]; } - static scalar_type + static constexpr auto read_element_idx(int row, int col, cppid::gm3d::mat4 const& x) + -> scalar_type { return x.m[row * 4 + col]; } - static scalar_type& + static constexpr auto write_element_idx(int row, int col, cppid::gm3d::mat4& x) + -> scalar_type { return x.m[row * 4 + col]; } diff --git a/src/cppid/gm3d/rgba.hpp b/src/cppid/gm3d/rgba.hpp index d9dd4ac..eabf9f4 100644 --- a/src/cppid/gm3d/rgba.hpp +++ b/src/cppid/gm3d/rgba.hpp @@ -20,9 +20,9 @@ class rgba using detail::basic_rgba, std::uint8_t>::basic_rgba; - rgba() noexcept = default; + constexpr rgba() noexcept = default; - rgba(scalar_type r, scalar_type g, scalar_type b) noexcept + constexpr rgba(scalar_type r, scalar_type g, scalar_type b) noexcept : rgba{r, g, b, 0xFF} { } From 02ae000912ca6a5ee86aa3631ea58e15846499bd Mon Sep 17 00:00:00 2001 From: Januar Andaria Date: Mon, 1 Apr 2019 22:23:06 +0800 Subject: [PATCH 18/19] build: capitalize namespace Cppid in cmake --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a838d3..91f5e0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if(NOT Boost_FOUND) endif() add_library(cppid-gm3d INTERFACE) -add_library(cppid::gm3d ALIAS cppid-gm3d) +add_library(Cppid::gm3d ALIAS cppid-gm3d) target_include_directories(cppid-gm3d INTERFACE @@ -66,7 +66,7 @@ if(GM3D_BUILD_TESTING) target_link_libraries(${Gm3d_TARGET_NAME} PRIVATE - cppid::gm3d + Cppid::gm3d Catch2::Catch2 ) From 98b56079ab810fb0b39b2e61df519de10e4f9ec6 Mon Sep 17 00:00:00 2001 From: "Januar C. Andaria" Date: Tue, 2 Apr 2019 09:39:14 +0800 Subject: [PATCH 19/19] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 8f0916f..a918a2a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.0 +0.6.0