Change cg::dimension(body) to cg::body_traits<Body>::dimension
This commit is contained in:
parent
5e62e6fa26
commit
2b8814e472
7 changed files with 27 additions and 21 deletions
|
|
@ -13,12 +13,12 @@ namespace psemek::cg
|
|||
{
|
||||
|
||||
/* The basic interface of a 2D body is
|
||||
* constexpr dimension(body) -> 2
|
||||
* body_traits<Body>::static dimension -> 2
|
||||
* vertices(body) -> [point]
|
||||
* edges(body) -> [(index, index)]
|
||||
*
|
||||
* The basic interface of a 3D body is
|
||||
* constexpr dimension(body) -> 3
|
||||
* body_traits<Body>::static dimension -> 3
|
||||
* vertices(body) -> [point]
|
||||
* edges(body) -> [(index, index)]
|
||||
* faces(body) -> [[index]]
|
||||
|
|
@ -70,6 +70,9 @@ namespace psemek::cg
|
|||
|
||||
}
|
||||
|
||||
template <typename Body>
|
||||
struct body_traits;
|
||||
|
||||
template <typename Body>
|
||||
auto faces(Body const & b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ namespace psemek::cg
|
|||
box(geom::box<T, N>) -> box<T, N>;
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
constexpr std::size_t dimension(box<T, N> const &)
|
||||
struct body_traits<box<T, N>>
|
||||
{
|
||||
return N;
|
||||
}
|
||||
static constexpr std::size_t dimension = N;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct box<T, 2>
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ namespace psemek::cg
|
|||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
constexpr std::size_t dimension(frustum<T, N> const &)
|
||||
struct body_traits<frustum<T, N>>
|
||||
{
|
||||
return N;
|
||||
}
|
||||
static constexpr std::size_t dimension = N;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
frustum<T, 3>::frustum(geom::matrix<T, 4, 4> const & m)
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ namespace psemek::cg
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t dimension(icosahedron<T> const &)
|
||||
struct body_traits<icosahedron<T>>
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
static constexpr std::size_t dimension = 3;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
icosahedron<T>::icosahedron(geom::point<T, 3> const & origin, T radius)
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ namespace psemek::cg
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t dimension(polygon<T> const &)
|
||||
struct body_traits<polygon<T>>
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
static constexpr std::size_t dimension = 2;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
auto const & vertices(polygon<T> const & p)
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ namespace psemek::cg
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t dimension(triangular_prism<T> const &)
|
||||
struct body_traits<triangular_prism<T>>
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
static constexpr std::size_t dimension = 3;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
triangular_prism<T>::triangular_prism(geom::triangle<geom::point<T, 3>> const & t, geom::vector<T, 3> const & d)
|
||||
|
|
|
|||
|
|
@ -173,14 +173,17 @@ namespace psemek::cg
|
|||
template <typename Body1, typename Body2>
|
||||
auto separation(Body1 const & b1, Body2 const & b2)
|
||||
{
|
||||
static_assert(dimension(b1) == dimension(b2));
|
||||
static_assert(dimension(b1) == 2 || dimension(b1) == 3);
|
||||
constexpr auto dim1 = body_traits<Body1>::dimension;
|
||||
constexpr auto dim2 = body_traits<Body2>::dimension;
|
||||
|
||||
if constexpr (dimension(b1) == 2)
|
||||
static_assert(dim1 == dim2);
|
||||
static_assert(dim1 == 2 || dim1 == 3);
|
||||
|
||||
if constexpr (dim1 == 2)
|
||||
{
|
||||
return detail::separation_2d(b1, b2);
|
||||
}
|
||||
else if constexpr (dimension(b1) == 3)
|
||||
else if constexpr (dim1 == 3)
|
||||
{
|
||||
return detail::separation_3d(b1, b2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue