IndexPair.hpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3  * Modified work Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 
22 #ifndef PLAYRHO_COLLISION_INDEXPAIR_HPP
23 #define PLAYRHO_COLLISION_INDEXPAIR_HPP
24 
26 #include <array>
27 #include <utility>
28 
29 namespace playrho {
30 
36 using IndexPair = std::pair<VertexCounter, VertexCounter>;
37 
41 };
42 
47 using IndexPair3 = std::array<IndexPair, MaxSimplexEdges>;
48 
52 }};
53 
54 static_assert(MaxSimplexEdges == 3, "Invalid assumption about size of MaxSimplexEdges");
55 
60 PLAYRHO_CONSTEXPR inline std::size_t GetNumValidIndices(IndexPair3 pairs) noexcept
61 {
62  return std::size_t{3}
63  - ((std::get<0>(pairs) == InvalidIndexPair)? 1u: 0u)
64  - ((std::get<1>(pairs) == InvalidIndexPair)? 1u: 0u)
65  - ((std::get<2>(pairs) == InvalidIndexPair)? 1u: 0u);
66 }
67 
69 PLAYRHO_CONSTEXPR inline bool empty(IndexPair3 pairs) noexcept
70 {
71  return GetNumValidIndices(pairs) == 0;
72 }
73 
77 PLAYRHO_CONSTEXPR inline auto size(IndexPair3 pairs) -> decltype(GetNumValidIndices(pairs))
78 {
79  return GetNumValidIndices(pairs);
80 }
81 
84 PLAYRHO_CONSTEXPR inline auto max_size(IndexPair3 pairs) -> decltype(pairs.max_size())
85 {
86  return pairs.max_size();
87 }
88 
90 template <std::size_t N>
91 using VertexCounterArray = std::array<VertexCounter, N>;
92 
95 
96 namespace detail {
97 
99 template <std::size_t N>
101 {
104 };
105 
107 template <std::size_t N>
109 {
113 };
114 
115 } // namespace detail
116 
118 template <std::size_t N>
120 {
121  return info.firstShape;
122 }
123 
125 template <VertexCounter M, std::size_t N>
127 {
128  return std::get<M>(info.secondShape);
129 }
130 
136 {
137  Length distance = GetInvalid<Length>();
139 };
140 
141 namespace d2 {
142 
145 
148 
149 } // namespace 2d
150 } // namespace playrho
151 
152 #endif // PLAYRHO_COLLISION_INDEXPAIR_HPP