Class PathGeometry

Namespace
TDMaker.Unity.Authoring
Assembly
TDMaker.Unity.dll

Authoring geometry helpers: smooth curves (centripetal Catmull-Rom) sampled into simulation nodes, and nearest-point queries on path center lines. Used by PathAuthoring curve mode and the editor's Map Editor.

public static class PathGeometry
Inheritance
PathGeometry
Inherited Members

Fields

MinNodeSpacing

public const float MinNodeSpacing = 0.05

Field Value

float

Methods

Evaluate(Vector2, Vector2, Vector2, Vector2, float)

Point on the centripetal Catmull-Rom span between p1 and p2 at u (0..1).

public static Vector2 Evaluate(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, float u)

Parameters

p0 Vector2
p1 Vector2
p2 Vector2
p3 Vector2
u float

Returns

Vector2

InterpolateSpacing(IReadOnlyList<float>, float, IReadOnlyList<float>, List<float>)

Per-node lane spacing for a sampled curve: control values (non-positive = defaultSpacing) interpolated by arc length within each span. Leaves output empty when no control overrides the default.

public static void InterpolateSpacing(IReadOnlyList<float> controlSpacing, float defaultSpacing, IReadOnlyList<float> spanFractions, List<float> output)

Parameters

controlSpacing IReadOnlyList<float>
defaultSpacing float
spanFractions IReadOnlyList<float>
output List<float>

Length(IReadOnlyList<Vector2>)

Total length of a polyline.

public static float Length(IReadOnlyList<Vector2> line)

Parameters

line IReadOnlyList<Vector2>

Returns

float

NearestOnPolyline(IReadOnlyList<Vector2>, Vector2, out float, out int)

Closest point on a polyline and its distance; segment is the index of the segment's first node.

public static Vector2 NearestOnPolyline(IReadOnlyList<Vector2> line, Vector2 point, out float distance, out int segment)

Parameters

line IReadOnlyList<Vector2>
point Vector2
distance float
segment int

Returns

Vector2

NearestPathPoint(IReadOnlyList<PathData>, Vector2, out Vector2, out int)

Closest point on the nearest path's center line (between its entry and exit nodes). Air routes are skipped while any ground path exists, since soldiers rally on roads. Returns false when there is no usable path.

public static bool NearestPathPoint(IReadOnlyList<PathData> paths, Vector2 point, out Vector2 nearest, out int pathIndex)

Parameters

paths IReadOnlyList<PathData>
point Vector2
nearest Vector2
pathIndex int

Returns

bool

SampleCurve(IReadOnlyList<Vector2>, float, List<Vector2>, List<int>, List<float>)

Samples a smooth centripetal Catmull-Rom curve through controls into nodes about nodeSpacing apart (measured along the curve). Every control point is emitted exactly as a node, so the curve passes through them; each span gets max(1, round(length / spacing)) equal arc-length steps.

public static void SampleCurve(IReadOnlyList<Vector2> controls, float nodeSpacing, List<Vector2> output, List<int> controlNodes = null, List<float> spanFractions = null)

Parameters

controls IReadOnlyList<Vector2>

Control points, from entry to exit.

nodeSpacing float

Target distance between nodes.

output List<Vector2>

Receives the nodes (cleared first).

controlNodes List<int>

Optional: receives the node index of each control point.

spanFractions List<float>

Optional: receives, per node, its span index plus the arc-length fraction within the span.

SpriteRect(Sprite, Vector2)

World rectangle covered by sprite when its pivot sits at pivotPosition (pixels-per-unit aware).

public static Rect SpriteRect(Sprite sprite, Vector2 pivotPosition)

Parameters

sprite Sprite
pivotPosition Vector2

Returns

Rect