Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
44a96c0
build: update CMakeLists.txt to use alias namespace cppid::gm3d
janucaria Mar 22, 2019
24bda60
refactor: edit namespace to cppid::gm3d and edit header guard macro
janucaria Mar 22, 2019
ab0f551
refactor: move project folders to src/cppid/gm3d
janucaria Mar 22, 2019
6a3b9f3
Merge branch 'refactor.cppid-namespace' into develop
janucaria Mar 22, 2019
7ab3426
refactor: change file names to lowercase
janucaria Mar 22, 2019
4a2b704
refactor: change style of types name to lowercase_snake_case style
janucaria Mar 22, 2019
e0da7ca
Merge branch 'refactor.lowercase-snake-case-styles' into develop
janucaria Mar 23, 2019
4eb6b4d
style: change clang-format configuration and apply format to all files
janucaria Mar 23, 2019
4b5f999
refactor: use Boost.QVM with vector customisation point
janucaria Mar 23, 2019
043aee1
refactor: use Boost.QVM with matrix customisation point
janucaria Mar 23, 2019
d01b511
Merge branch 'refactor.use-boost-qvm' into develop
janucaria Mar 23, 2019
2e7639f
refactor: rename vec class to basic_vector_nd
janucaria Mar 23, 2019
ef0017c
refactor: move basic_vector_nd to detail namespace
janucaria Mar 23, 2019
ac2c079
test: add vec_traits test for scalar type and dimensions
janucaria Mar 23, 2019
6bf4e86
refactor: create basic_point_vector class for base of vector and point
janucaria Mar 23, 2019
6ea2431
refactor: rename vec2 tp vector_2d and vec3 to vector_3d
janucaria Mar 23, 2019
1caa8fa
feat: add new type point_2d and point_3d
janucaria Apr 1, 2019
f019320
refactor: move some contructors of vector and point to parent class
janucaria Apr 1, 2019
4f5ca74
refactor: add points to all.hpp
janucaria Apr 1, 2019
658bdf7
Merge branch 'feat.strongly-type-vector-and-point' into develop
janucaria Apr 1, 2019
c6e695a
feat: constexpr member functions
janucaria Apr 1, 2019
02ae000
build: capitalize namespace Cppid in cmake
janucaria Apr 1, 2019
75e1d25
Merge pull request #58 from janucaria/develop
janucaria Apr 1, 2019
98b5607
Update VERSION
janucaria Apr 2, 2019
01e2510
Merge branch 'master' into rc-0.6.0
janucaria Apr 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: All
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
Expand Down
60 changes: 41 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
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)
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()

set(Gm3d_WARNING_OPTIONS "-Wall" "-Wpedantic")
add_library(cppid-gm3d INTERFACE)
add_library(Cppid::gm3d ALIAS cppid-gm3d)

add_library(gm3d INTERFACE)
target_include_directories(cppid-gm3d
INTERFACE
"${PROJECT_SOURCE_DIR}/src"
)

target_include_directories(gm3d
INTERFACE
"${PROJECT_SOURCE_DIR}/src/"
target_link_libraries(cppid-gm3d
INTERFACE
Boost::boost
)

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()
Expand All @@ -25,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"
Expand All @@ -35,16 +60,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}
Expand All @@ -54,5 +78,3 @@ if(GM3D_BUILD_TESTING)
endforeach()

endif()


2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.1
0.6.0
12 changes: 12 additions & 0 deletions src/cppid/gm3d/all.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CPPID_GM3D_ALL_HPP
#define CPPID_GM3D_ALL_HPP

#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"

#endif
173 changes: 173 additions & 0 deletions src/cppid/gm3d/detail/basic_point_nd.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#ifndef CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP
#define CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP

#include <algorithm>
#include <cmath>
#include <cstddef>
#include <functional>
#include <numeric>
#include <type_traits>
#include <utility>

#include <boost/qvm/all.hpp>

#include "basic_point_vector.hpp"
#include "type_traits.hpp"

namespace cppid::gm3d::detail {

template<typename T, std::size_t N>
struct basic_point_nd : public basic_point_vector<basic_point_nd<T, N>, T, N> {
using typename basic_point_vector<basic_point_nd<T, N>, T, N>::scalar_type;

using basic_point_vector<basic_point_nd<T, N>, T, N>::dimensions;

using basic_point_vector<basic_point_nd<T, N>, T, N>::basic_point_vector;

constexpr basic_point_nd() noexcept = default;

template<typename U,
std::enable_if_t<
detail::is_explicit_constructible_v<scalar_type, U>>* = nullptr>
explicit constexpr basic_point_nd(basic_point_nd<U, dimensions> v) noexcept
: basic_point_nd{v, std::make_index_sequence<dimensions>()}
{
}

template<typename U,
std::size_t... Ns,
std::enable_if_t<
(sizeof...(Ns) == dimensions) &&
detail::is_explicit_constructible_v<scalar_type, U>>* = nullptr>
constexpr basic_point_nd(basic_point_nd<U, dimensions> v,
std::index_sequence<Ns...>) noexcept
: basic_point_nd{v.elems[Ns]...}
{
}

template<typename U,
std::enable_if_t<
detail::is_implicit_constructible_v<scalar_type, U>>* = nullptr>
constexpr basic_point_nd(basic_point_nd<U, dimensions> v) noexcept
: basic_point_nd{v, std::make_index_sequence<dimensions>()}
{
}

template<typename U,
std::size_t... Ns,
std::enable_if_t<
(sizeof...(Ns) == dimensions) &&
detail::is_implicit_constructible_v<scalar_type, U>>* = nullptr>
constexpr basic_point_nd(basic_point_nd<U, dimensions> v,
std::index_sequence<Ns...>) noexcept
: basic_point_nd{scalar_type(v.elems[Ns])...}
{
}

template<typename U,
typename = std::enable_if_t<std::is_convertible_v<U, scalar_type>>>
constexpr auto operator=(const basic_point_nd<U, dimensions> rhs) noexcept
-> basic_point_nd&
{
op_assign(rhs.elems, std::make_index_sequence<dimensions>());
return *this;
}

constexpr auto operator==(const basic_point_nd& rhs) const noexcept -> bool
{
return is_equal(rhs.elems, std::make_index_sequence<dimensions>());
}

constexpr auto operator!=(const basic_point_nd& rhs) const noexcept -> bool
{
return !(*this == rhs);
}

friend constexpr auto operator+(const basic_point_nd& val) noexcept
-> basic_point_nd
{
return val;
}

friend constexpr auto operator-(const basic_point_nd& lhs) noexcept
-> basic_point_nd
{
return invoke_op{}(
std::negate{}, lhs, std::make_index_sequence<dimensions>());
}

private:
struct invoke_op {
template<typename P, typename U, std::size_t... Ns>
constexpr auto operator()(const P op,
const basic_point_nd<U, dimensions>& lhs,
std::index_sequence<Ns...>) const noexcept
-> basic_point_nd<std::invoke_result_t<P, U>, dimensions>
{
static_assert(sizeof...(Ns) == dimensions);
return {op(lhs.elems[Ns])...};
}

template<typename P, typename U, typename V, std::size_t... Ns>
constexpr auto operator()(const P op,
const basic_point_nd<U, dimensions>& lhs,
const basic_point_nd<V, dimensions>& rhs,
std::index_sequence<Ns...>) const noexcept
-> basic_point_nd<std::invoke_result_t<P, U, V>, dimensions>
{
static_assert(sizeof...(Ns) == dimensions);
return {op(lhs.elems[Ns], rhs.elems[Ns])...};
}
};

template<typename U, typename P, std::size_t... Ns>
inline constexpr void op_assign(const U (&rhs)[dimensions],
P op,
std::index_sequence<Ns...>) noexcept
{
((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...);
}

template<typename U, typename P, std::size_t... Ns>
inline constexpr void
op_assign(U rhs, P op, std::index_sequence<Ns...>) noexcept
{
((this->elems[Ns] = op(this->elems[Ns], rhs)), ...);
}

template<typename U, std::size_t... Ns>
inline constexpr void op_assign(const U (&rhs)[dimensions],
std::index_sequence<Ns...>) noexcept
{
((this->elems[Ns] = rhs[Ns]), ...);
}

template<typename U, std::size_t... Ns>
constexpr auto is_equal(const U (&rhs)[dimensions],
std::index_sequence<Ns...>) const noexcept -> bool
{
return ((this->elems[Ns] == rhs[Ns]) && ... && true);
}

template<std::size_t... Ns>
constexpr auto negate(std::index_sequence<Ns...>) const noexcept
-> basic_point_nd
{
return basic_point_nd{(-this->elems[Ns])...};
}
};

} // namespace cppid::gm3d::detail

namespace boost::qvm {

template<typename T, std::size_t N>
struct vec_traits<cppid::gm3d::detail::basic_point_nd<T, N>>
: public vec_traits<
cppid::gm3d::detail::
basic_point_vector<cppid::gm3d::detail::basic_point_nd<T, N>, T, N>> {
};

} // namespace boost::qvm

#endif
Loading