Skip to content

PolygonParts

namespace Griff.Scenes;
public sealed class PolygonParts

The shape a PolygonCollider’s points make, as physics uses it: fixed up where the points don’t make a proper shape (too few, all in a line, sides crossing), going round anticlockwise without repeated points or points along a straight side, and split into convex pieces of at most MaxCorners corners each, so a concave shape (an L, a cup, a crescent of rock) collides as the pieces it’s made of. Worked out once when the points change; the same points always make the same pieces.

public float Area { get; }

Its area, in its own units.

public Vector2 Centroid { get; }

Its middle (where it balances), in its own units.

public uint[] Inner { get; }

For each piece, the sides (bit i: from its corner i to the next) inside the shape, where pieces meet.

public uint[] InnerReversed { get; }

The same, for each piece with its corners in the opposite order (when the shape is mirrored).

public Vector2 Max { get; }
public Vector2 Min { get; }

The corners of the box round it, in its own units.

public Vector2[] Outline { get; }

The shape’s corners, anticlockwise, in the collider’s own units round its offset.

public int[][] Pieces { get; }

Its convex pieces, each the corners of Outline it’s made of (by number), anticlockwise.

public string? Problem { get; }

What was wrong with the points and how it was fixed, or null when they make a proper shape.

public static string Format(IEnumerable<Vector2> points)

“x y; x y; x y”, on hundredths, as Parse reads it.

public static PolygonParts Of(IReadOnlyList<Vector2> given)

The shape given make, fixed up where they don’t make a proper one.

public static List<Vector2> Parse(string? text)

Reads “x y; x y; x y” (commas work between the numbers too); anything that isn’t a pair of numbers is skipped.

public const float FlatThickness

How thick a shape with no area (its points all in a line) is made.

public const int MaxCorners

The most corners one convex piece has (what physics works with at once).

public const int MaxPoints

The most points a polygon uses: those after it are left out.