GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::physics::ShapeView< N > Class Template Reference

View of a generic shape. More...

#include <GREM/physics/Shape.hpp>

Inheritance diagram for grem::physics::ShapeView< N >:

Public Types

using value_type = typename Shape<N>::value_type
 Underling shape variant type.
using index_type = value_type::index_type
 Index type used to encode the active shape type.

Public Member Functions

template<typename T>
requires (same_as<T, Shape<N>>)
GREM_ALWAYS_INLINE constexpr ShapeView (const T &shape) noexcept
 Construct a shape view.
template<typename T>
requires (!same_as<T, Shape<N>> && variant_has_alternative_v<T, value_type>)
GREM_ALWAYS_INLINE constexpr ShapeView (const T &shape) noexcept
 Construct a shape view.
GREM_ALWAYS_INLINE constexpr const void * data () const noexcept
 Get an untyped pointer to the data of the underlying shape.
GREM_ALWAYS_INLINE constexpr index_type index () const noexcept
 Get the type index of the underlying shape.
constexpr bool valueless_by_exception () const noexcept
 Check if the shape view is in the valueless by exception state.
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
constexpr bool is () const noexcept
 Check if the shape view currently references the alternative with the given type.
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
constexpr const T & as () const &noexcept
 Access the underlying value with the given type without a safety check.
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
constexpr const T & get () const &
 Access the underlying value with the given type.
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
constexpr const T * get_if () const noexcept
 Access the underlying shape with the given type if it is the currently active alternative.
bool isConvexShapeType () const noexcept
 Check if the shape held by this wrapper is a convex shape type.
bool isConvexPolytopeShapeType () const noexcept
 Check if the shape held by this wrapper is a convex polytope shape type.
Volume calculateVolume () const
 Calculate an estimate of the volume of the shape.
PrincipalMomentsOfInertia< N > calculatePrincipalMomentsOfInertia (Mass mass) const
 Calculate an estimate of the local moment of inertia of the shape given a certain mass.
Optional< Box< N > > getBoundingBox (const Transformation< N > &transformation) const
 Get the axis-aligned bounding box of the shape given its position and orientation in the world.
Optional< Distance > getBoundingRadius (const Basis< N > &basis) const
 Get the radius of the bounding sphere of the shape.
Optional< Area > getReferenceArea (const Basis< N > &basis, Direction< N > direction) const
 Get an estimate of the reference area of the shape for a certain direction, typically calculated as the area of the largest cross section orthogonal to the given direction.
RaycastResult< N > castLocalRay (Length< N > localRayOrigin, Direction< N > localRayDirection, Distance maxLocalRayDistance) const
 Find the closest intersection of this shape with a given ray in local space.

Detailed Description

template<size_t N>
class grem::physics::ShapeView< N >

View of a generic shape.

Template Parameters
Nnumber of dimensions of the world space (must be 2 or 3).

Member Typedef Documentation

◆ value_type

template<size_t N>
using grem::physics::ShapeView< N >::value_type = typename Shape<N>::value_type

Underling shape variant type.

◆ index_type

template<size_t N>
using grem::physics::ShapeView< N >::index_type = value_type::index_type

Index type used to encode the active shape type.

Constructor & Destructor Documentation

◆ ShapeView() [1/2]

template<size_t N>
template<typename T>
requires (same_as<T, Shape<N>>)
GREM_ALWAYS_INLINE constexpr grem::physics::ShapeView< N >::ShapeView ( const T & shape)
inlineconstexprnoexcept

Construct a shape view.

Parameters
shapereference to the shape to construct the view over. Must outlive its use in the view.

◆ ShapeView() [2/2]

template<size_t N>
template<typename T>
requires (!same_as<T, Shape<N>> && variant_has_alternative_v<T, value_type>)
GREM_ALWAYS_INLINE constexpr grem::physics::ShapeView< N >::ShapeView ( const T & shape)
inlineconstexprnoexcept

Construct a shape view.

Parameters
shapereference to the shape to construct the view over. Must outlive its use in the view.

Member Function Documentation

◆ data()

template<size_t N>
GREM_ALWAYS_INLINE constexpr const void * grem::physics::ShapeView< N >::data ( ) const
inlinenodiscardconstexprnoexcept

Get an untyped pointer to the data of the underlying shape.

Returns
a non-owning read-only pointer to the data of the underlying shape alternative.

◆ index()

template<size_t N>
GREM_ALWAYS_INLINE constexpr index_type grem::physics::ShapeView< N >::index ( ) const
inlinenodiscardconstexprnoexcept

Get the type index of the underlying shape.

Returns
the type index of the underlying Shape<N> variant.

◆ valueless_by_exception()

template<size_t N>
bool grem::physics::ShapeView< N >::valueless_by_exception ( ) const
inlinenodiscardconstexprnoexcept

Check if the shape view is in the valueless by exception state.

Returns
true if the shape view is in the valueless by exception state, false otherwise.

◆ is()

template<size_t N>
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
bool grem::physics::ShapeView< N >::is ( ) const
inlinenodiscardconstexprnoexcept

Check if the shape view currently references the alternative with the given type.

Template Parameters
Talternative type to check for. Must be one of Shape<N>'s listed alternative types.
Returns
true if the shape view references a value of the given type, false otherwise.

◆ as()

template<size_t N>
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
const T & grem::physics::ShapeView< N >::as ( ) const &
inlinenodiscardconstexprnoexcept

Access the underlying value with the given type without a safety check.

Template Parameters
Ttype of the currently active value to get. Must be one of Shape<N>'s listed alternative types.
Returns
a read-only reference to the value referenced by the shape view.
Warning
The behavior of accessing the underlying value using the incorrect alternative type which is not currently active is undefined. The active alternative type must be known in advance in order to use this function safely, for example by checking if the shape view contains the expected alternative using the is() function.
Remarks
Rather than using this function in conjunction with is(), it is usually more appropriate to use get() or to call get_if() and make sure that the returned pointer is not nullptr. This function is only meant for the cases where it is absolutely certain which alternative the shape view currently references.
See also
get()
get_if()

◆ get()

template<size_t N>
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
const T & grem::physics::ShapeView< N >::get ( ) const &
inlinenodiscardconstexpr

Access the underlying value with the given type.

Template Parameters
Ttype of the currently active value to get. Must be one of Shape<N>'s listed alternative types.
Returns
a read-only reference to the value referenced by the shape view.
Exceptions
BadVariantAccessif the shape view does not currently reference a value of the given type.
See also
as()
get_if()

◆ get_if()

template<size_t N>
template<typename T>
requires (variant_has_alternative_v<T, value_type>)
const T * grem::physics::ShapeView< N >::get_if ( ) const
inlinenodiscardconstexprnoexcept

Access the underlying shape with the given type if it is the currently active alternative.

Template Parameters
Ttype of the value to get. Must be one of Shape<N>'s listed alternative types.
Returns
a non-owning read-only pointer to the value referenced by the shape view, or nullptr if the shape view does not currently reference a value of the given type.
See also
as()
get()

◆ isConvexShapeType()

template<size_t N>
bool grem::physics::ShapeView< N >::isConvexShapeType ( ) const
nodiscardnoexcept

Check if the shape held by this wrapper is a convex shape type.

Returns
true if the underlying shape satisfies the convex_shape concept, false otherwise.

◆ isConvexPolytopeShapeType()

template<size_t N>
bool grem::physics::ShapeView< N >::isConvexPolytopeShapeType ( ) const
nodiscardnoexcept

Check if the shape held by this wrapper is a convex polytope shape type.

Returns
true if the underlying shape satisfies the convex_polytope_shape concept, false otherwise.

◆ calculateVolume()

template<size_t N>
Volume grem::physics::ShapeView< N >::calculateVolume ( ) const
nodiscard

Calculate an estimate of the volume of the shape.

Returns
the estimated volume of the shape.

◆ calculatePrincipalMomentsOfInertia()

template<size_t N>
PrincipalMomentsOfInertia< N > grem::physics::ShapeView< N >::calculatePrincipalMomentsOfInertia ( Mass mass) const
nodiscard

Calculate an estimate of the local moment of inertia of the shape given a certain mass.

Parameters
massassumed mass of the shape.
Returns
the estimated moment of inertia in shape-local space.

◆ getBoundingBox()

template<size_t N>
Optional< Box< N > > grem::physics::ShapeView< N >::getBoundingBox ( const Transformation< N > & transformation) const
nodiscard

Get the axis-aligned bounding box of the shape given its position and orientation in the world.

Parameters
transformationtransformation of the shape in world space.
Returns
an axis-aligned bounding box in world space that would contain the entire shape if the shape was at the given position and orientation in the world, or an empty optional if the shape extends infinitely and cannot be fit inside a finite box.

◆ getBoundingRadius()

template<size_t N>
Optional< Distance > grem::physics::ShapeView< N >::getBoundingRadius ( const Basis< N > & basis) const
nodiscard

Get the radius of the bounding sphere of the shape.

Parameters
basistransformation basis of the shape in world space.
Returns
the maximum distance from the origin of any point on the shape, or an empty optional if the shape extends infinitely and cannot be fit inside a finite sphere.

◆ getReferenceArea()

template<size_t N>
Optional< Area > grem::physics::ShapeView< N >::getReferenceArea ( const Basis< N > & basis,
Direction< N > direction ) const
nodiscard

Get an estimate of the reference area of the shape for a certain direction, typically calculated as the area of the largest cross section orthogonal to the given direction.

Parameters
basistransformation basis of the shape in world space.
directiondirection to get the reference area for.
Returns
the reference area, or an empty optional if an area cannot be determined, e.g. because the shape is infinite.

◆ castLocalRay()

template<size_t N>
RaycastResult< N > grem::physics::ShapeView< N >::castLocalRay ( Length< N > localRayOrigin,
Direction< N > localRayDirection,
Distance maxLocalRayDistance ) const
nodiscard

Find the closest intersection of this shape with a given ray in local space.

Parameters
localRayOriginoffset of the ray origin in shape-local space.
localRayDirectionunit direction vector of the ray in shape-local space. Must be a unit vector.
maxLocalRayDistancemaximum hit distance of the ray in shape-local space. Must be non-negative.
Returns
the result of the raycast.

The documentation for this class was generated from the following file: