Polygon shape configuration. More...

#include <PolygonShapeConf.hpp>

Public Member Functions

 PolygonShapeConf ()
 
 PolygonShapeConf (Length hx, Length hy, const PolygonShapeConf &conf=GetDefaultConf()) noexcept
 Initializing constructor for a 4-sided box polygon. More...
 
 PolygonShapeConf (Span< const Length2 > points, const PolygonShapeConf &conf=GetDefaultConf()) noexcept
 Creates a convex hull from the given array of local points. More...
 
PolygonShapeConfUseVertexRadius (NonNegative< Length > value) noexcept
 Uses the given vertex radius. More...
 
PolygonShapeConfUseVertices (const std::vector< Length2 > &verts) noexcept
 Uses the given vertices. More...
 
PolygonShapeConfSetAsBox (Length hx, Length hy) noexcept
 Sets the vertices to represent an axis-aligned box centered on the local origin. More...
 
PolygonShapeConfSetAsBox (Length hx, Length hy, Length2 center, Angle angle) noexcept
 Sets the vertices for the described box. More...
 
PolygonShapeConfSet (Span< const Length2 > verts) noexcept
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfSet (const VertexSet &points) noexcept
 Sets the vertices to a convex hull of the given ones. More...
 
PolygonShapeConfTransform (Transformation xfm) noexcept
 Transforms the vertices by the given transformation. More...
 
PolygonShapeConfTransform (const Mat22 &m) noexcept
 Transforms the vertices by the given transformation matrix. More...
 
VertexCounter GetVertexCount () const noexcept
 
Length2 GetVertex (VertexCounter index) const
 
UnitVec GetNormal (VertexCounter index) const
 
Span< const Length2GetVertices () const noexcept
 
Span< const UnitVecGetNormals () const noexcept
 Gets the span of normals. More...
 
Length2 GetCentroid () const noexcept
 Gets the centroid. More...
 
- Public Member Functions inherited from playrho::d2::ShapeBuilder< PolygonShapeConf >
PLAYRHO_CONSTEXPR ShapeBuilder ()=default
 Default constructor. More...
 
PLAYRHO_CONSTEXPR ShapeBuilder (const BaseShapeConf &value) noexcept
 Initializing constructor. More...
 
PLAYRHO_CONSTEXPR PolygonShapeConfUseFriction (NonNegative< Real > value) noexcept
 Uses the given friction. More...
 
PLAYRHO_CONSTEXPR PolygonShapeConfUseRestitution (Finite< Real > value) noexcept
 Uses the given restitution. More...
 
PLAYRHO_CONSTEXPR PolygonShapeConfUseDensity (NonNegative< AreaDensity > value) noexcept
 Uses the given density. More...
 

Static Public Member Functions

static PLAYRHO_CONSTEXPR NonNegative< LengthGetDefaultVertexRadius () noexcept
 Gets the default vertex radius for the PolygonShapeConf. More...
 
static PolygonShapeConf GetDefaultConf () noexcept
 Gets the default configuration for a PolygonShapeConf. More...
 

Public Attributes

NonNegative< LengthvertexRadius = GetDefaultVertexRadius()
 Vertex radius. More...
 
- Public Attributes inherited from playrho::d2::BaseShapeConf
NonNegative< Realfriction = NonNegative<Real>{Real{2} / Real{10}}
 Friction coefficient. More...
 
Finite< Realrestitution = Finite<Real>{0}
 Restitution (elasticity) of the associated shape. More...
 
NonNegative< AreaDensitydensity = NonNegative<AreaDensity>{0_kgpm2}
 Area density of the associated shape. More...
 

Friends

bool operator== (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept
 Equality operator. More...
 
bool operator!= (const PolygonShapeConf &lhs, const PolygonShapeConf &rhs) noexcept
 Inequality operator. More...
 

Related Functions

(Note that these are not member functions.)

Length2 GetEdge (const PolygonShapeConf &shape, VertexCounter index)
 

Detailed Description

Polygon shape configuration.

A convex polygon. The interior of the polygon is to the left of each edge. Polygons maximum number of vertices is defined by MaxShapeVertices. In most cases you should not need many vertices for a convex polygon.

Note
This data structure is 64-bytes large (with 4-byte Real).
Examples
HelloWorld.cpp, and World.cpp.

Definition at line 41 of file PolygonShapeConf.hpp.

Constructor & Destructor Documentation

◆ PolygonShapeConf() [1/3]

playrho::d2::PolygonShapeConf::PolygonShapeConf ( )
default

◆ PolygonShapeConf() [2/3]

playrho::d2::PolygonShapeConf::PolygonShapeConf ( Length  hx,
Length  hy,
const PolygonShapeConf conf = GetDefaultConf() 
)
noexcept

Initializing constructor for a 4-sided box polygon.

Definition at line 28 of file PolygonShapeConf.cpp.

◆ PolygonShapeConf() [3/3]

playrho::d2::PolygonShapeConf::PolygonShapeConf ( Span< const Length2 points,
const PolygonShapeConf conf = GetDefaultConf() 
)
explicitnoexcept

Creates a convex hull from the given array of local points.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
the points may be re-ordered, even if they form a convex polygon
collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

Definition at line 35 of file PolygonShapeConf.cpp.

Member Function Documentation

◆ GetDefaultVertexRadius()

static PLAYRHO_CONSTEXPR NonNegative<Length> playrho::d2::PolygonShapeConf::GetDefaultVertexRadius ( )
inlinestaticnoexcept

Gets the default vertex radius for the PolygonShapeConf.

Definition at line 45 of file PolygonShapeConf.hpp.

◆ GetDefaultConf()

static PolygonShapeConf playrho::d2::PolygonShapeConf::GetDefaultConf ( )
inlinestaticnoexcept

Gets the default configuration for a PolygonShapeConf.

Definition at line 51 of file PolygonShapeConf.hpp.

◆ UseVertexRadius()

PolygonShapeConf & playrho::d2::PolygonShapeConf::UseVertexRadius ( NonNegative< Length value)
inlinenoexcept

Uses the given vertex radius.

Examples
World.cpp.

Definition at line 191 of file PolygonShapeConf.hpp.

◆ UseVertices()

PolygonShapeConf & playrho::d2::PolygonShapeConf::UseVertices ( const std::vector< Length2 > &  verts)
noexcept

Uses the given vertices.

Definition at line 69 of file PolygonShapeConf.cpp.

◆ SetAsBox() [1/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::SetAsBox ( Length  hx,
Length  hy 
)
noexcept

Sets the vertices to represent an axis-aligned box centered on the local origin.

Parameters
hxthe half-width.
hythe half-height.
Examples
HelloWorld.cpp, and World.cpp.

Definition at line 42 of file PolygonShapeConf.cpp.

◆ SetAsBox() [2/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::SetAsBox ( Length  hx,
Length  hy,
Length2  center,
Angle  angle 
)
noexcept

Sets the vertices for the described box.

Definition at line 74 of file PolygonShapeConf.cpp.

◆ Set() [1/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Set ( Span< const Length2 verts)
noexcept

Sets the vertices to a convex hull of the given ones.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
Points may be re-ordered, even if they form a convex polygon
Collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

Definition at line 104 of file PolygonShapeConf.cpp.

◆ Set() [2/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Set ( const VertexSet points)
noexcept

Sets the vertices to a convex hull of the given ones.

Note
The size of the span must be in the range [1, MaxShapeVertices].
Warning
Points may be re-ordered, even if they form a convex polygon
Collinear points are handled but not removed. Collinear points may lead to poor stacking behavior.

Definition at line 115 of file PolygonShapeConf.cpp.

◆ Transform() [1/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Transform ( Transformation  xfm)
noexcept

Transforms the vertices by the given transformation.

Definition at line 82 of file PolygonShapeConf.cpp.

◆ Transform() [2/2]

PolygonShapeConf & playrho::d2::PolygonShapeConf::Transform ( const Mat22 m)
noexcept

Transforms the vertices by the given transformation matrix.

See also
https://en.wikipedia.org/wiki/Transformation_matrix

Definition at line 93 of file PolygonShapeConf.cpp.

◆ GetVertexCount()

VertexCounter playrho::d2::PolygonShapeConf::GetVertexCount ( ) const
inlinenoexcept

Gets the vertex count.

Returns
value between 0 and MaxShapeVertices inclusive.
See also
MaxShapeVertices

Definition at line 123 of file PolygonShapeConf.hpp.

◆ GetVertex()

Length2 playrho::d2::PolygonShapeConf::GetVertex ( VertexCounter  index) const
inline

Gets a vertex by index.

Vertices go counter-clockwise.

Definition at line 130 of file PolygonShapeConf.hpp.

◆ GetNormal()

UnitVec playrho::d2::PolygonShapeConf::GetNormal ( VertexCounter  index) const
inline

Gets a normal by index.

These are 90-degree clockwise-rotated (outward-facing) unit-vectors of the edges defined by consecutive pairs of vertices starting with vertex 0.

Parameters
indexIndex of the normal to get.
Returns
Normal for the given index.

Definition at line 142 of file PolygonShapeConf.hpp.

◆ GetVertices()

Span<const Length2> playrho::d2::PolygonShapeConf::GetVertices ( ) const
inlinenoexcept

Gets the span of vertices.

Vertices go counter-clockwise.

Definition at line 150 of file PolygonShapeConf.hpp.

◆ GetNormals()

Span<const UnitVec> playrho::d2::PolygonShapeConf::GetNormals ( ) const
inlinenoexcept

Gets the span of normals.

Definition at line 156 of file PolygonShapeConf.hpp.

◆ GetCentroid()

Length2 playrho::d2::PolygonShapeConf::GetCentroid ( ) const
inlinenoexcept

Gets the centroid.

Definition at line 162 of file PolygonShapeConf.hpp.

Friends And Related Function Documentation

◆ operator==

bool operator== ( const PolygonShapeConf lhs,
const PolygonShapeConf rhs 
)
friend

Equality operator.

Definition at line 106 of file PolygonShapeConf.hpp.

◆ operator!=

bool operator!= ( const PolygonShapeConf lhs,
const PolygonShapeConf rhs 
)
friend

Inequality operator.

Definition at line 115 of file PolygonShapeConf.hpp.

◆ GetEdge()

Length2 GetEdge ( const PolygonShapeConf shape,
VertexCounter  index 
)
related

Gets the identified edge of the given polygon shape.

Note
This must not be called for shapes with less than 2 vertices.
Warning
Behavior is undefined if called for a shape with less than 2 vertices.

Definition at line 157 of file PolygonShapeConf.cpp.

Member Data Documentation

◆ vertexRadius

NonNegative<Length> playrho::d2::PolygonShapeConf::vertexRadius = GetDefaultVertexRadius()

Vertex radius.

This is 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.

Note
This should be a non-negative value.

Definition at line 175 of file PolygonShapeConf.hpp.


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