PolygonParts
namespace Griff.Scenes;
public sealed class PolygonPartsThe 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.
Properties
Section titled “Properties”public float Area { get; }Its area, in its own units.
Centroid
Section titled “Centroid”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.
InnerReversed
Section titled “InnerReversed”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.
Outline
Section titled “Outline”public Vector2[] Outline { get; }The shape’s corners, anticlockwise, in the collider’s own units round its offset.
Pieces
Section titled “Pieces”public int[][] Pieces { get; }Its convex pieces, each the corners of Outline it’s made of (by number), anticlockwise.
Problem
Section titled “Problem”public string? Problem { get; }What was wrong with the points and how it was fixed, or null when they make a proper shape.
Methods
Section titled “Methods”Format
Section titled “Format”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.
Fields
Section titled “Fields”FlatThickness
Section titled “FlatThickness”public const float FlatThicknessHow thick a shape with no area (its points all in a line) is made.
MaxCorners
Section titled “MaxCorners”public const int MaxCornersThe most corners one convex piece has (what physics works with at once).
MaxPoints
Section titled “MaxPoints”public const int MaxPointsThe most points a polygon uses: those after it are left out.