Skip to content

Commit 05ce017

Browse files
authored
Merge pull request #59 from cppid/rc-0.6.0
Rc 0.6.0
2 parents 32f09d5 + 01e2510 commit 05ce017

32 files changed

Lines changed: 2023 additions & 1658 deletions

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ AllowShortFunctionsOnASingleLine: None
1313
AllowShortIfStatementsOnASingleLine: false
1414
AllowShortLoopsOnASingleLine: false
1515
AlwaysBreakAfterDefinitionReturnType: None
16-
AlwaysBreakAfterReturnType: All
16+
AlwaysBreakAfterReturnType: None
1717
AlwaysBreakBeforeMultilineStrings: false
1818
AlwaysBreakTemplateDeclarations: Yes
1919
BinPackArguments: false

CMakeLists.txt

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
1-
cmake_minimum_required(VERSION 3.11)
1+
cmake_minimum_required(VERSION 3.13)
22
project(Gm3d)
33

4-
set(CMAKE_CXX_STANDARD 17)
5-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6-
set(CMAKE_CXX_EXTENSIONS OFF)
4+
find_package(Boost)
5+
6+
if(NOT Boost_FOUND)
7+
add_library(Boost::boost INTERFACE IMPORTED)
8+
if(BOOST_ROOT)
9+
target_include_directories(Boost::boost INTERFACE ${BOOST_ROOT}/include)
10+
elseif(BOOST_INCLUDEDIR)
11+
target_include_directories(Boost::boost INTERFACE ${BOOST_INCLUDEDIR})
12+
else()
13+
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.")
14+
endif()
15+
endif()
716

8-
set(Gm3d_WARNING_OPTIONS "-Wall" "-Wpedantic")
17+
add_library(cppid-gm3d INTERFACE)
18+
add_library(Cppid::gm3d ALIAS cppid-gm3d)
919

10-
add_library(gm3d INTERFACE)
20+
target_include_directories(cppid-gm3d
21+
INTERFACE
22+
"${PROJECT_SOURCE_DIR}/src"
23+
)
1124

12-
target_include_directories(gm3d
13-
INTERFACE
14-
"${PROJECT_SOURCE_DIR}/src/"
25+
target_link_libraries(cppid-gm3d
26+
INTERFACE
27+
Boost::boost
1528
)
1629

17-
target_compile_options(gm3d INTERFACE ${Gm3d_WARNING_OPTIONS} "-stdlib=libc++")
30+
target_compile_options(cppid-gm3d
31+
INTERFACE
32+
-Wall
33+
-Wpedantic
34+
-pedantic-errors
35+
-fno-rtti
36+
)
1837

38+
target_compile_features(cppid-gm3d
39+
INTERFACE
40+
cxx_std_17
41+
)
1942

2043
if(GM3D_BUILD_TESTING)
2144
enable_testing()
@@ -25,6 +48,8 @@ if(GM3D_BUILD_TESTING)
2548
set(Gm3d_TEST_SRC_FILES
2649
"${PROJECT_SOURCE_DIR}/test/matrix3.cpp"
2750
"${PROJECT_SOURCE_DIR}/test/matrix4.cpp"
51+
"${PROJECT_SOURCE_DIR}/test/point2.cpp"
52+
"${PROJECT_SOURCE_DIR}/test/point3.cpp"
2853
"${PROJECT_SOURCE_DIR}/test/rgba_float.cpp"
2954
"${PROJECT_SOURCE_DIR}/test/rgba_uint8.cpp"
3055
"${PROJECT_SOURCE_DIR}/test/vector2.cpp"
@@ -35,16 +60,15 @@ if(GM3D_BUILD_TESTING)
3560

3661
get_filename_component(Gm3d_NAME ${Gm3d_FILES} NAME_WE)
3762

38-
set(Gm3d_TARGET_NAME "gm3d-test-${Gm3d_NAME}")
63+
set(Gm3d_TARGET_NAME "cppid-gm3d-test-${Gm3d_NAME}")
3964

4065
add_executable(${Gm3d_TARGET_NAME} ${Gm3d_FILES})
4166

42-
target_link_libraries(${Gm3d_TARGET_NAME} PRIVATE gm3d)
43-
44-
target_link_libraries(${Gm3d_TARGET_NAME} PRIVATE gm3d Catch2)
45-
46-
target_compile_options(
47-
${Gm3d_TARGET_NAME} PRIVATE ${Gm3d_WARNING_OPTIONS} "-stdlib=libc++")
67+
target_link_libraries(${Gm3d_TARGET_NAME}
68+
PRIVATE
69+
Cppid::gm3d
70+
Catch2::Catch2
71+
)
4872

4973
add_test(
5074
NAME ${Gm3d_TARGET_NAME}
@@ -54,5 +78,3 @@ if(GM3D_BUILD_TESTING)
5478
endforeach()
5579

5680
endif()
57-
58-

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.5.1
1+
0.6.0

src/cppid/gm3d/all.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef CPPID_GM3D_ALL_HPP
2+
#define CPPID_GM3D_ALL_HPP
3+
4+
#include "mat3.hpp"
5+
#include "mat4.hpp"
6+
#include "point_2d.hpp"
7+
#include "point_3d.hpp"
8+
#include "rgba.hpp"
9+
#include "vector_2d.hpp"
10+
#include "vector_3d.hpp"
11+
12+
#endif
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#ifndef CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP
2+
#define CPPID_GM3D_DETAIL_BASIC_POINT_ND_HPP
3+
4+
#include <algorithm>
5+
#include <cmath>
6+
#include <cstddef>
7+
#include <functional>
8+
#include <numeric>
9+
#include <type_traits>
10+
#include <utility>
11+
12+
#include <boost/qvm/all.hpp>
13+
14+
#include "basic_point_vector.hpp"
15+
#include "type_traits.hpp"
16+
17+
namespace cppid::gm3d::detail {
18+
19+
template<typename T, std::size_t N>
20+
struct basic_point_nd : public basic_point_vector<basic_point_nd<T, N>, T, N> {
21+
using typename basic_point_vector<basic_point_nd<T, N>, T, N>::scalar_type;
22+
23+
using basic_point_vector<basic_point_nd<T, N>, T, N>::dimensions;
24+
25+
using basic_point_vector<basic_point_nd<T, N>, T, N>::basic_point_vector;
26+
27+
constexpr basic_point_nd() noexcept = default;
28+
29+
template<typename U,
30+
std::enable_if_t<
31+
detail::is_explicit_constructible_v<scalar_type, U>>* = nullptr>
32+
explicit constexpr basic_point_nd(basic_point_nd<U, dimensions> v) noexcept
33+
: basic_point_nd{v, std::make_index_sequence<dimensions>()}
34+
{
35+
}
36+
37+
template<typename U,
38+
std::size_t... Ns,
39+
std::enable_if_t<
40+
(sizeof...(Ns) == dimensions) &&
41+
detail::is_explicit_constructible_v<scalar_type, U>>* = nullptr>
42+
constexpr basic_point_nd(basic_point_nd<U, dimensions> v,
43+
std::index_sequence<Ns...>) noexcept
44+
: basic_point_nd{v.elems[Ns]...}
45+
{
46+
}
47+
48+
template<typename U,
49+
std::enable_if_t<
50+
detail::is_implicit_constructible_v<scalar_type, U>>* = nullptr>
51+
constexpr basic_point_nd(basic_point_nd<U, dimensions> v) noexcept
52+
: basic_point_nd{v, std::make_index_sequence<dimensions>()}
53+
{
54+
}
55+
56+
template<typename U,
57+
std::size_t... Ns,
58+
std::enable_if_t<
59+
(sizeof...(Ns) == dimensions) &&
60+
detail::is_implicit_constructible_v<scalar_type, U>>* = nullptr>
61+
constexpr basic_point_nd(basic_point_nd<U, dimensions> v,
62+
std::index_sequence<Ns...>) noexcept
63+
: basic_point_nd{scalar_type(v.elems[Ns])...}
64+
{
65+
}
66+
67+
template<typename U,
68+
typename = std::enable_if_t<std::is_convertible_v<U, scalar_type>>>
69+
constexpr auto operator=(const basic_point_nd<U, dimensions> rhs) noexcept
70+
-> basic_point_nd&
71+
{
72+
op_assign(rhs.elems, std::make_index_sequence<dimensions>());
73+
return *this;
74+
}
75+
76+
constexpr auto operator==(const basic_point_nd& rhs) const noexcept -> bool
77+
{
78+
return is_equal(rhs.elems, std::make_index_sequence<dimensions>());
79+
}
80+
81+
constexpr auto operator!=(const basic_point_nd& rhs) const noexcept -> bool
82+
{
83+
return !(*this == rhs);
84+
}
85+
86+
friend constexpr auto operator+(const basic_point_nd& val) noexcept
87+
-> basic_point_nd
88+
{
89+
return val;
90+
}
91+
92+
friend constexpr auto operator-(const basic_point_nd& lhs) noexcept
93+
-> basic_point_nd
94+
{
95+
return invoke_op{}(
96+
std::negate{}, lhs, std::make_index_sequence<dimensions>());
97+
}
98+
99+
private:
100+
struct invoke_op {
101+
template<typename P, typename U, std::size_t... Ns>
102+
constexpr auto operator()(const P op,
103+
const basic_point_nd<U, dimensions>& lhs,
104+
std::index_sequence<Ns...>) const noexcept
105+
-> basic_point_nd<std::invoke_result_t<P, U>, dimensions>
106+
{
107+
static_assert(sizeof...(Ns) == dimensions);
108+
return {op(lhs.elems[Ns])...};
109+
}
110+
111+
template<typename P, typename U, typename V, std::size_t... Ns>
112+
constexpr auto operator()(const P op,
113+
const basic_point_nd<U, dimensions>& lhs,
114+
const basic_point_nd<V, dimensions>& rhs,
115+
std::index_sequence<Ns...>) const noexcept
116+
-> basic_point_nd<std::invoke_result_t<P, U, V>, dimensions>
117+
{
118+
static_assert(sizeof...(Ns) == dimensions);
119+
return {op(lhs.elems[Ns], rhs.elems[Ns])...};
120+
}
121+
};
122+
123+
template<typename U, typename P, std::size_t... Ns>
124+
inline constexpr void op_assign(const U (&rhs)[dimensions],
125+
P op,
126+
std::index_sequence<Ns...>) noexcept
127+
{
128+
((this->elems[Ns] = op(this->elems[Ns], rhs[Ns])), ...);
129+
}
130+
131+
template<typename U, typename P, std::size_t... Ns>
132+
inline constexpr void
133+
op_assign(U rhs, P op, std::index_sequence<Ns...>) noexcept
134+
{
135+
((this->elems[Ns] = op(this->elems[Ns], rhs)), ...);
136+
}
137+
138+
template<typename U, std::size_t... Ns>
139+
inline constexpr void op_assign(const U (&rhs)[dimensions],
140+
std::index_sequence<Ns...>) noexcept
141+
{
142+
((this->elems[Ns] = rhs[Ns]), ...);
143+
}
144+
145+
template<typename U, std::size_t... Ns>
146+
constexpr auto is_equal(const U (&rhs)[dimensions],
147+
std::index_sequence<Ns...>) const noexcept -> bool
148+
{
149+
return ((this->elems[Ns] == rhs[Ns]) && ... && true);
150+
}
151+
152+
template<std::size_t... Ns>
153+
constexpr auto negate(std::index_sequence<Ns...>) const noexcept
154+
-> basic_point_nd
155+
{
156+
return basic_point_nd{(-this->elems[Ns])...};
157+
}
158+
};
159+
160+
} // namespace cppid::gm3d::detail
161+
162+
namespace boost::qvm {
163+
164+
template<typename T, std::size_t N>
165+
struct vec_traits<cppid::gm3d::detail::basic_point_nd<T, N>>
166+
: public vec_traits<
167+
cppid::gm3d::detail::
168+
basic_point_vector<cppid::gm3d::detail::basic_point_nd<T, N>, T, N>> {
169+
};
170+
171+
} // namespace boost::qvm
172+
173+
#endif

0 commit comments

Comments
 (0)