ConcavePolygonShape2D
A set of segments for boundary-only 2D collision; the interior is empty.
ConcavePolygonShape2D stores independent segments rather than a filled polygon. Segments=[A,B,C,D] defines only A–B and C–D. Connections B–C and D–A are not added automatically. Even when segments form a closed contour, a small shape entirely inside it does not intersect the boundary and produces no overlap in a direct query.
For four corners A,B,C,D, a closed contour requires [A,B,B,C,C,D,D,A]. This complete executed helper builds it from a corner list. Supply each corner once, without repeating the first at the end. The caller owns the returned resource:
using System;
using Reckfell;
public static class ContourFactory2D
{
// Boundary only: this does not fill the enclosed area or check self-intersections.
// Supply each corner once; the last edge is added here. Caller owns the resource.
public static ConcavePolygonShape2D Closed(ReadOnlySpan<Vector2> corners)
{
if (corners.Length < 3)
throw new ArgumentException("At least three corners are required.", nameof(corners));
var segments = new Vector2[checked(corners.Length * 2)];
for (int i = 0; i < corners.Length; i++)
{
Vector2 a = corners[i];
Vector2 b = corners[(i + 1) % corners.Length];
if (!float.IsFinite(a.X) || !float.IsFinite(a.Y) || a == b)
throw new ArgumentException("Corners must be finite and adjacent corners distinct.", nameof(corners));
segments[2 * i] = a;
segments[2 * i + 1] = b;
}
var shape = new ConcavePolygonShape2D();
shape.SetSegments(segments.AsSpan());
return shape;
}
}The helper validates corner count, finite coordinates and nonzero edge lengths. It does not validate self-intersections, area or artistic contour correctness, and does not fill the contour. Use ConvexPolygonShape2D for a filled convex object; split a filled concave shape into convex pieces.
A new resource is empty. Segments must have an even element count; an empty array clears geometry. The getter returns an independent array that must be assigned back after editing. Both SetSegments overloads copy input. Changed is emitted even for repeated data. GetRect() encloses all endpoints in local coordinates, but a point inside those bounds does not necessarily collide with a segment.
For a collider, assign the resource to Shape on CollisionShape2D, which must be a direct child Entity of CollisionObject2D. A resource alone adds no body to the world.
Arrays and ReadOnlySpan, independent copies, clearing, local bounds, Changed and the exact helper were checked. Direct queries confirmed an empty closed-square interior, collision at its edge and no collision with a separated circle. Body movement, continuous fast-collision detection, performance and drawing were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
ConcavePolygonShape2DConstructor
public ConcavePolygonShape2D();Creates a resource with an empty segment array and empty local bounds. The shape describes segments only, with no filled area.
Properties1
SegmentsProperty
public Vector2[] Segments { get; set; }Endpoint pairs for independent segments: [A,B,C,D] defines A–B and C–D. This is not a corner sequence; B–C and D–A are not added. An empty array clears geometry. Element count must be even; use finite coordinates and distinct endpoints for each segment. The setter copies data and emits Changed even on repetition; the getter returns an independent array. A closed set of segments does not fill its interior.
Methods3
GetSegmentsVector2[]
public Vector2[] GetSegments();Independent copy of segment endpoint pairs, or an empty array. To change geometry, assign data back through Segments or SetSegments.
Vector2[]Independent copy of segment endpoint pairs, or an empty array. To change geometry, assign data back through Segments or SetSegments.
SetSegments2 overloads
public void SetSegments(Vector2[] segments);Endpoint pairs for independent segments: [A,B,C,D] defines A–B and C–D. This is not a corner sequence; B–C and D–A are not added. An empty array clears geometry. Element count must be even; use finite coordinates and distinct endpoints for each segment. The setter copies data and emits Changed even on repetition; the getter returns an independent array. A closed set of segments does not fill its interior.
| Name | Type | Default |
|---|---|---|
segments | Vector2[] | — |
segmentsEven count of finite coordinates, with two distinct endpoints per segment. Empty input clears the shape. Neighboring pairs are not automatically connected.
public void SetSegments(ReadOnlySpan<Vector2> segments);Endpoint pairs for independent segments: [A,B,C,D] defines A–B and C–D. This is not a corner sequence; B–C and D–A are not added. An empty array clears geometry. Element count must be even; use finite coordinates and distinct endpoints for each segment. The setter copies data and emits Changed even on repetition; the getter returns an independent array. A closed set of segments does not fill its interior.
| Name | Type | Default |
|---|---|---|
segments | ReadOnlySpan<Vector2> | — |
segmentsEven count of finite coordinates, with two distinct endpoints per segment. Empty input clears the shape. Neighboring pairs are not automatically connected.