Replace cg::body_traits::dimension with constexpr dimension template variable
This commit is contained in:
parent
eff7f397b4
commit
ae4ee3488a
7 changed files with 5 additions and 35 deletions
|
|
@ -70,15 +70,15 @@ namespace psemek::cg
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Body>
|
|
||||||
struct body_traits;
|
|
||||||
|
|
||||||
template <typename Body>
|
template <typename Body>
|
||||||
auto vertices(Body const & b)
|
auto vertices(Body const & b)
|
||||||
{
|
{
|
||||||
return b.vertices;
|
return b.vertices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Body>
|
||||||
|
constexpr std::size_t dimension = std::decay_t<decltype(vertices(std::declval<Body>())[0])>::static_dimension;
|
||||||
|
|
||||||
template <typename Body>
|
template <typename Body>
|
||||||
auto faces(Body const & b)
|
auto faces(Body const & b)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -13,12 +13,6 @@ namespace psemek::cg
|
||||||
template <typename T, std::size_t N>
|
template <typename T, std::size_t N>
|
||||||
box(geom::box<T, N>) -> box<T, N>;
|
box(geom::box<T, N>) -> box<T, N>;
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
struct body_traits<box<T, N>>
|
|
||||||
{
|
|
||||||
static constexpr std::size_t dimension = N;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct box<T, 2>
|
struct box<T, 2>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,6 @@ namespace psemek::cg
|
||||||
std::array<geom::point<T, 3>, 8> vertices;
|
std::array<geom::point<T, 3>, 8> vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
struct body_traits<frustum<T, N>>
|
|
||||||
{
|
|
||||||
static constexpr std::size_t dimension = N;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
frustum<T, 3>::frustum(geom::matrix<T, 4, 4> const & m)
|
frustum<T, 3>::frustum(geom::matrix<T, 4, 4> const & m)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,6 @@ namespace psemek::cg
|
||||||
std::array<geom::point<T, 3>, 12> vertices;
|
std::array<geom::point<T, 3>, 12> vertices;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct body_traits<icosahedron<T>>
|
|
||||||
{
|
|
||||||
static constexpr std::size_t dimension = 3;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
icosahedron<T>::icosahedron(geom::point<T, 3> const & origin, T radius)
|
icosahedron<T>::icosahedron(geom::point<T, 3> const & origin, T radius)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,6 @@ namespace psemek::cg
|
||||||
edges[i].points = {i, (i + 1) % vertices.size()};
|
edges[i].points = {i, (i + 1) % vertices.size()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct body_traits<polygon<T>>
|
|
||||||
{
|
|
||||||
static constexpr std::size_t dimension = 2;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto const & vertices(polygon<T> const & p)
|
auto const & vertices(polygon<T> const & p)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,6 @@ namespace psemek::cg
|
||||||
std::array<geom::vector<T, 3>, 4> edge_directions;
|
std::array<geom::vector<T, 3>, 4> edge_directions;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct body_traits<triangular_prism<T>>
|
|
||||||
{
|
|
||||||
static constexpr std::size_t dimension = 3;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
triangular_prism<T>::triangular_prism(geom::triangle<geom::point<T, 3>> const & t, geom::vector<T, 3> const & d)
|
triangular_prism<T>::triangular_prism(geom::triangle<geom::point<T, 3>> const & t, geom::vector<T, 3> const & d)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -173,8 +173,8 @@ namespace psemek::cg
|
||||||
template <typename Body1, typename Body2>
|
template <typename Body1, typename Body2>
|
||||||
auto separation(Body1 const & b1, Body2 const & b2)
|
auto separation(Body1 const & b1, Body2 const & b2)
|
||||||
{
|
{
|
||||||
constexpr auto dim1 = body_traits<Body1>::dimension;
|
constexpr auto dim1 = dimension<Body1>;
|
||||||
constexpr auto dim2 = body_traits<Body2>::dimension;
|
constexpr auto dim2 = dimension<Body2>;
|
||||||
|
|
||||||
static_assert(dim1 == dim2);
|
static_assert(dim1 == dim2);
|
||||||
static_assert(dim1 == 2 || dim1 == 3);
|
static_assert(dim1 == 2 || dim1 == 3);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue