4#ifndef GREM_CORE_DATA_CONVEX_POLYTOPE_HPP
5#define GREM_CORE_DATA_CONVEX_POLYTOPE_HPP
42template <
size_t N,
typename Scalar>
51template <
size_t N,
typename Scalar>
54template <
typename Scalar>
57template <
typename Scalar>
91template <
size_t N,
typename Scalar>
94template <
typename Scalar>
103template <
typename Scalar>
124template <
size_t N,
typename Scalar>
125struct ConvexPolytopeData {
126 Allocation<ConvexPolytopeVertex<N, Scalar>> vertices{};
127 [[no_unique_address]] std::conditional_t<N == 3, Allocation<ConvexPolytopeEdgeIndex>, NoEdges> vertexEdgeIndices{};
128 [[no_unique_address]] std::conditional_t<N == 3, Allocation<ConvexPolytopeEdge<3, Scalar>>, NoEdges> edges{};
129 Allocation<ConvexPolytopeFace<N, Scalar>> faces{};
144template <
size_t N,
typename Scalar>
147 if constexpr (
N == 2) {
148 if constexpr (same_as<Scalar, float>) {
149 return buildConvexHull2DFloat(vertices, transformation, maxVertexCount);
151 return buildConvexHull2DDouble(vertices, transformation, maxVertexCount);
154 if constexpr (same_as<Scalar, float>) {
155 return buildConvexHull3DFloat(vertices, transformation, maxVertexCount);
157 return buildConvexHull3DDouble(vertices, transformation, maxVertexCount);
170template <
size_t N,
typename Scalar>
191 : data{.vertices = std::
move(vertices), .faces = std::
move(faces)}
192 , boundingBox(boundingBox)
193 , boundingRadius(boundingRadius) {}
211 const Box<3, Scalar>& boundingBox, Scalar boundingRadius)
requires(N == 3)
212 : data{.vertices = std::
move(vertices), .vertexEdgeIndices = std::
move(vertexEdgeIndices), .edges = std::
move(edges), .faces = std::
move(faces)}
213 , boundingBox(boundingBox)
214 , boundingRadius(boundingRadius) {}
230 : data(detail::buildConvexHull<N>(vertices, transformation, maxVertexCount))
246 :
ConvexPolytope(vertices,
mat<N + 1, N + 1, Scalar>{Scalar{1}}, maxVertexCount) {}
254 return data.vertices;
263 return data.vertexEdgeIndices;
300 return boundingRadius;
304 detail::ConvexPolytopeData<N, Scalar> data{};
305 Box<N, Scalar> boundingBox{};
Definition Allocation.hpp:25
Span< const ConvexPolytopeEdgeIndex > getVertexEdgeIndices() const noexcept
Get the vertex edge indices of the convex polytope.
Definition ConvexPolytope.hpp:262
Box< N, Scalar > getBoundingBox() const noexcept
Get the bounding box of the convex polytope.
Definition ConvexPolytope.hpp:290
ConvexPolytopeFace< N, Scalar > Face
Face type of the convex polytope.
Definition ConvexPolytope.hpp:175
ConvexPolytopeEdge< N, Scalar > Edge
Edge type of the convex polytope.
Definition ConvexPolytope.hpp:174
ConvexPolytope(Allocation< Vertex > vertices, Allocation< Face > faces, const Box< 2, Scalar > &boundingBox, Scalar boundingRadius)
Construct a convex polygon from pre-calculated data.
Definition ConvexPolytope.hpp:190
Scalar getBoundingRadius() const noexcept
Get the bounding radius of the convex polytope.
Definition ConvexPolytope.hpp:299
Span< const Edge > getEdges() const noexcept
Get the edges of the convex polytope.
Definition ConvexPolytope.hpp:271
ConvexPolytopeVertex< N, Scalar > Vertex
Vertex type of the convex polytope.
Definition ConvexPolytope.hpp:173
ConvexPolytope(Span< const Vertex > vertices, ConvexPolytopeVertexIndex maxVertexCount=Limits< ConvexPolytopeVertexIndex >::MAX)
Construct a convex polytope from a set of vertices.
Definition ConvexPolytope.hpp:245
Span< const Face > getFaces() const noexcept
Get the faces of the convex polytope.
Definition ConvexPolytope.hpp:280
ConvexPolytope(Allocation< Vertex > vertices, Allocation< ConvexPolytopeEdgeIndex > vertexEdgeIndices, Allocation< Edge > edges, Allocation< Face > faces, const Box< 3, Scalar > &boundingBox, Scalar boundingRadius)
Construct a convex polyhedron from pre-calculated data.
Definition ConvexPolytope.hpp:210
ConvexPolytope(Span< const Vertex > vertices, const mat< N+1, N+1, Scalar > &transformation, ConvexPolytopeVertexIndex maxVertexCount=Limits< ConvexPolytopeVertexIndex >::MAX)
Construct a convex polytope from the convex hull of a set of vertices.
Definition ConvexPolytope.hpp:229
Span< const Vertex > getVertices() const noexcept
Get the vertices of the convex polytope.
Definition ConvexPolytope.hpp:253
@ N
'n'
Definition keyboard.hpp:84
float Scalar
Underlying scalar type of physics quantity components.
Definition quantities.hpp:1480
uint8_t ConvexPolytopeEdgeIndex
Index of an edge in a convex polytope.
Definition ConvexPolytope.hpp:29
vec< N, Scalar > ConvexPolytopeVertex
Vertex of a convex polytope.
Definition ConvexPolytope.hpp:43
constexpr T calculateBoundingRadius(StridedSpan< const Point< N, T > > points) noexcept
Calculate the bounding radius from the origin of a set of points.
Definition geometry.hpp:1618
uint8_t ConvexPolytopeVertexIndex
Index of a vertex in a convex polytope.
Definition ConvexPolytope.hpp:24
mat< 4, 4, double > dmat4
Definition math.hpp:810
constexpr auto move(input_range auto &&range, auto outputIterator)
Definition algorithms.hpp:669
mat< 3, 3, float > mat3
Definition math.hpp:805
Span(R &&range) -> Span< std::remove_reference_t< decltype(*std::data(range))> >
mat< 3, 3, double > dmat3
Definition math.hpp:809
uint8_t ConvexPolytopeFaceIndex
Index of a face in a convex polytope.
Definition ConvexPolytope.hpp:34
mat< 4, 4, float > mat4
Definition math.hpp:806
constexpr Box< N, T > calculateBoundingBox(StridedSpan< const Point< N, T > > points) noexcept
Calculate the axis-aligned bounding box of a set of points.
Definition geometry.hpp:1595
Generic axis-aligned box shape with minimum and maximum extents in N-dimensional space.
Definition geometry.hpp:149
ConvexPolytopeVertexIndex vertexIndex
Index of the vertex corresponding to the first point of the edge.
Definition ConvexPolytope.hpp:65
ConvexPolytopeFaceIndex faceIndex
The index of the face that this edge belongs to.
Definition ConvexPolytope.hpp:73
ConvexPolytopeEdgeIndex nextEdgeIndex
Index of the next edge on the face, which will eventually loop back around to this edge again.
Definition ConvexPolytope.hpp:82
Edge of a convex polytope.
Definition ConvexPolytope.hpp:52
vec< 2, Scalar > normal
Direction perpendicular to the face, pointing outwards from the center of the shape.
Definition ConvexPolytope.hpp:100
vec< 3, Scalar > normal
Direction perpendicular to the face, pointing outwards from the center of the shape.
Definition ConvexPolytope.hpp:109
ConvexPolytopeEdgeIndex firstEdgeIndex
Index of the first edge that makes up the face.
Definition ConvexPolytope.hpp:117
Face on a convex polytope.
Definition ConvexPolytope.hpp:92
static constexpr T MAX
Definition fundamentals.hpp:29