Add 2D convex bodies interface & constexpr dimension retrieveing function
This commit is contained in:
parent
1c4fbb1618
commit
fc9e603a13
5 changed files with 80 additions and 2 deletions
|
|
@ -12,7 +12,13 @@
|
|||
namespace psemek::cg
|
||||
{
|
||||
|
||||
/* The basic interface of a 3D body is
|
||||
/* The basic interface of a 2D body is
|
||||
* constexpr dimension(body) -> 2
|
||||
* vertices(body) -> [point]
|
||||
* edges(body) -> [(index, index)]
|
||||
*
|
||||
* The basic interface of a 3D body is
|
||||
* constexpr dimension(body) -> 3
|
||||
* vertices(body) -> [point]
|
||||
* edges(body) -> [(index, index)]
|
||||
* faces(body) -> [[index]]
|
||||
|
|
@ -24,7 +30,11 @@ namespace psemek::cg
|
|||
* However, it is possible that edges(body).size() != edge_directions(body).size,
|
||||
* if there are many collinear edges.
|
||||
*
|
||||
* Minimal set of required functions:
|
||||
* Minimal set of required functions for 2D body:
|
||||
* vertices
|
||||
* edges
|
||||
*
|
||||
* Minimal set of required functions for 3D body:
|
||||
* vertices
|
||||
* edges
|
||||
* faces/triangles
|
||||
|
|
|
|||
|
|
@ -13,6 +13,56 @@ namespace psemek::cg
|
|||
template <typename T, std::size_t N>
|
||||
box(geom::box<T, N>) -> box<T, N>;
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
constexpr std::size_t dimension(box<T, N> const &)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct box<T, 2>
|
||||
{
|
||||
box() = default;
|
||||
box(geom::box<T, 2> const & b);
|
||||
|
||||
std::array<geom::point<T, 2>, 4> vertices;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
box<T, 2>::box(geom::box<T, 2> const & b)
|
||||
{
|
||||
for (std::size_t y = 0; y < 2; ++y)
|
||||
{
|
||||
for (std::size_t x = 0; x < 2; ++x)
|
||||
{
|
||||
std::size_t i = y * 2 + x;
|
||||
|
||||
vertices[i][0] = (x == 0) ? b[0].min : b[0].max;
|
||||
vertices[i][1] = (y == 0) ? b[1].min : b[1].max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto const & vertices(box<T, 2> const & b)
|
||||
{
|
||||
return b.vertices;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto const & edges(box<T, 2> const &)
|
||||
{
|
||||
static const std::array<geom::segment<std::uint8_t>, 12> result =
|
||||
{{
|
||||
{ 0b00, 0b01 },
|
||||
{ 0b01, 0b11 },
|
||||
{ 0b11, 0b10 },
|
||||
{ 0b10, 0b00 },
|
||||
}};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct box<T, 3>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,12 @@ namespace psemek::cg
|
|||
std::array<geom::point<T, 3>, 8> vertices;
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
constexpr std::size_t dimension(frustum<T, N> const &)
|
||||
{
|
||||
return N;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
frustum<T, 3>::frustum(geom::matrix<T, 4, 4> const & m)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,12 @@ namespace psemek::cg
|
|||
std::array<geom::point<T, 3>, 12> vertices;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t dimension(icosahedron<T> const &)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
icosahedron<T>::icosahedron(geom::point<T, 3> const & origin, T radius)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ namespace psemek::cg
|
|||
std::array<geom::vector<T, 3>, 4> edge_directions;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr std::size_t dimension(triangular_prism<T> const &)
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
triangular_prism<T>::triangular_prism(geom::triangle<geom::point<T, 3>> const & t, geom::vector<T, 3> const & d)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue