Shape.
More...
#include <Shape.hpp>
|
| Shape () noexcept=default |
| Default constructor. More...
|
|
| Shape (const Shape &other)=default |
| Copy constructor.
|
|
| Shape (Shape &&other) noexcept=default |
| Move constructor.
|
|
template<typename T , typename Tp = DecayedTypeIfNotSelf<T>, typename = std::enable_if_t<std::is_copy_constructible<Tp>::value>> |
| Shape (T &&arg) |
| Initializing constructor. More...
|
|
Shape & | operator= (const Shape &other)=default |
| Copy assignment operator.
|
|
Shape & | operator= (Shape &&other)=default |
| Move assignment operator.
|
|
template<typename T , typename Tp = DecayedTypeIfNotSelf<T>, typename = std::enable_if_t<std::is_copy_constructible<Tp>::value>> |
Shape & | operator= (T &&other) |
| Move assignment operator. More...
|
|
void | swap (Shape &other) noexcept |
| Swap support.
|
|
bool | has_value () const noexcept |
| Checks whether this instance contains a value.
|
|
|
template<typename Type , typename DecayedType = std::decay_t<Type>> |
using | DecayedTypeIfNotSelf = std::enable_if_t<!std::is_same_v< DecayedType, Shape >, DecayedType > |
| Decayed type if not same as this class. More...
|
|
Shape.
A shape is used for collision detection. You can create a shape from any supporting type. Shapes are conceptually made up of zero or more convex child shapes where each child shape is made up of zero or more vertices and an associated radius called its "vertex radius".
- Note
- This class's design provides a "polymorphic value type" offering polymorphism without public inheritance. This is based on a technique that's described by Sean Parent in his January 2017 Norwegian Developers Conference London talk "Better Code: Runtime
Polymorphism". With this implementation, different shapes types can be had by constructing instances of this class with the different types that provide the required support. Different shapes of a given type meanwhile are had by providing different values for the type.
-
A shape can be constructor from or have its value set to any value whose type
T
has at least the following function definitions available for it:
bool operator==(const T& lhs, const T& rhs) noexcept;
ChildCounter GetChildCount(const T&) noexcept;
DistanceProxy GetChild(const T&, ChildCounter index);
MassData GetMassData(const T&) noexcept;
NonNegative<Length> GetVertexRadius(const T&, ChildCounter idx);
NonNegative<AreaDensity> GetDensity(const T&) noexcept;
Real GetFriction(const T&) noexcept;
Real GetRestitution(const T&) noexcept;
void Transform(T&, const Mat22& value);
- See also
- FixtureConf
-
https://youtu.be/QGcVXgEVMJg
-
https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Polymorphic_Value_Types
- Examples
- DistanceJoint.cpp, FrictionJoint.cpp, GearJoint.cpp, HelloWorld.cpp, MotorJoint.cpp, PrismaticJoint.cpp, RevoluteJoint.cpp, RopeJoint.cpp, Shape.cpp, WeldJoint.cpp, WheelJoint.cpp, World.cpp, WorldBody.cpp, WorldContact.cpp, and WorldFixture.cpp.
◆ DecayedTypeIfNotSelf
template<typename Type , typename DecayedType = std::decay_t<Type>>
Decayed type if not same as this class.
- Note
- This is done separately from other checks to ensure order of compiler's SFINAE processing and to ensure elimination of self class before attempting to process other checks like is_copy_constructible. This prevents a compiler error that started showing up in gcc-9.
◆ Shape() [1/2]
playrho::d2::Shape::Shape |
( |
| ) |
|
|
defaultnoexcept |
◆ Shape() [2/2]
template<typename T , typename Tp = DecayedTypeIfNotSelf<T>, typename = std::enable_if_t<std::is_copy_constructible<Tp>::value>>
playrho::d2::Shape::Shape |
( |
T && |
arg | ) |
|
|
inlineexplicit |
Initializing constructor.
- Parameters
-
arg | Configuration value to construct a shape instance for. |
- Note
- See the class notes section for an explanation of requirements on a type
T
for its values to be valid candidates for this function.
- Postcondition
has_value()
returns true.
- Exceptions
-
std::bad_alloc | if there's a failure allocating storage. |
◆ operator=()
template<typename T , typename Tp = DecayedTypeIfNotSelf<T>, typename = std::enable_if_t<std::is_copy_constructible<Tp>::value>>
Shape& playrho::d2::Shape::operator= |
( |
T && |
other | ) |
|
|
inline |
Move assignment operator.
- Postcondition
has_value()
returns true.
◆ GetChild
Gets the "child" for the given index.
- Parameters
-
shape | Shape to get "child" shape of. |
index | Index to a child element of the shape. Value must be less than the number of child primitives of the shape. |
- Note
- The shape must remain in scope while the proxy is in use.
- Exceptions
-
- See also
- GetChildCount
Referenced by playrho::d2::Shape::Model< T >::GetChild_().
◆ GetChildCount
◆ GetData
const void* GetData |
( |
const Shape & |
shape | ) |
|
|
friend |
Gets a pointer to the underlying data.
- Note
- Provided for introspective purposes like visitation.
◆ GetDensity
◆ GetFriction
◆ GetMassData
◆ GetType
Gets the type info of the use of the given shape.
- Note
- This is not the same as calling
GetTypeID<Shape>()
.
- Returns
- Type info of the underlying value's type.
◆ GetVertexRadius
Gets the vertex radius of the indexed child of the given shape.
This gets the radius from the vertex that the shape's "skin" should extend outward by. While any edges - line segments between multiple vertices - are straight, corners between them (the vertices) are rounded and treated as rounded. Shapes with larger vertex radiuses compared to edge lengths therefore will be more prone to rolling or having other shapes more prone to roll off of them. Here's an image of a shape configured via a PolygonShapeConf
with it's skin drawn:
- Parameters
-
shape | Shape to get child's vertex radius for. |
idx | Child index to get vertex radius for.
|
- Note
- This must be a non-negative value.
- See also
- UseVertexRadius
- Exceptions
-
Referenced by playrho::d2::Shape::Model< T >::GetVertexRadius_().
◆ Transform
◆ TypeCast() [1/2]
template<typename T >
T TypeCast |
( |
const Shape & |
value | ) |
|
|
related |
Casts the specified instance into the template specified type.
- Exceptions
-
std::bad_cast | If the template specified type is not the type of data underlying the given instance. |
- See also
- GetType(const Shape&)
◆ TypeCast [2/2]
template<typename T >
std::add_pointer_t<std::add_const_t<T> > TypeCast |
( |
const Shape * |
value | ) |
|
|
friend |
Converts the given shape into its current configuration value.
- Note
- The design for this was based off the design of the C++17
std::any
class and its associated std::any_cast
function. The code for this is based off of the std::any
code from the LLVM Project.
- See also
- https://llvm.org/
-
GetType(const Shape&)
The documentation for this class was generated from the following files:
- Shape.hpp
- AABB.hpp
- RayCastOutput.hpp