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
Smallest node spacing accepted by SampleCurve(IReadOnlyList<Vector2>, float, List<Vector2>, List<int>, List<float>).
public const float MinNodeSpacing = 0.05
Field Value
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
p0Vector2p1Vector2p2Vector2p3Vector2ufloat
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
controlSpacingIReadOnlyList<float>defaultSpacingfloatspanFractionsIReadOnlyList<float>outputList<float>
Length(IReadOnlyList<Vector2>)
Total length of a polyline.
public static float Length(IReadOnlyList<Vector2> line)
Parameters
lineIReadOnlyList<Vector2>
Returns
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
lineIReadOnlyList<Vector2>pointVector2distancefloatsegmentint
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
pathsIReadOnlyList<PathData>pointVector2nearestVector2pathIndexint
Returns
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
controlsIReadOnlyList<Vector2>Control points, from entry to exit.
nodeSpacingfloatTarget distance between nodes.
outputList<Vector2>Receives the nodes (cleared first).
controlNodesList<int>Optional: receives the node index of each control point.
spanFractionsList<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
spriteSpritepivotPositionVector2
Returns
- Rect