Curve2D
Cubic Bezier segments and a 2D distance cache.
AddPoint uses relative @in/@out handles. Sample(idx,t) uses a segment parameter; SampleBaked(offset) uses approximate baked-path distance. Equal t steps do not imply constant speed.
BakeInterval controls cache density, not the original handles. For a closed route, coordinate endpoints and tangents. A curve does not perform physics motion or query obstacles.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Curve2DConstructor
public Curve2D();Creates an owned empty 2D curve resource with BakeInterval=5. Add control points before position queries. Stores local data rather than an automatically moving Entity and creates no collisions. Dispose the resource after use.
Properties3
BakeIntervalProperty
public float BakeInterval { get; set; }Positive finite CPU-cache density scale in local units, default 5. Smaller usually produces more samples and memory/CPU work; neither exact analytic length nor perfectly equal spacing is promised. Subdivision depth is bounded. The setter validates neither positivity nor finiteness and invalidates the cache even for the same value.
PointCountProperty
public int PointCount { get; set; }Control-point count, not baked-sample count. Growth appends zero positions/handles and can emit Changed per point; shrinking truncates the end. Not an atomic replacement curve. Prepare a separate resource before assigning Path2D.Curve when replacing a finished path.
_DataProperty
public Reckfell.Collections.Dictionary _Data { get; set; }Internal Dictionary snapshot containing points:Vector2[] triplets of in/out/position. Setter requires a length divisible by 3; a valid roundtrip copies control data rather than sharing geometry between Curve2D instances. Not a complete external resource format or an untrusted-input container. Use point methods ordinarily; dispose the owned Dictionary wrapper after reading.
Methods23
AddPointvoid
public void AddPoint(Vector2 position, Vector2? @in = default, Vector2? @out = default, int index = -1);Adds a position and relative @in/@out handles. An absolute segment control point is its endpoint position plus the corresponding handle.
| Name | Type | Default |
|---|---|---|
position | Vector2 | — |
in | Vector2? | default |
out | Vector2? | default |
index | int | -1 |
positionFinite local position; SetPointIn/Out take a relative handle.
inRelative incoming handle; null/default gives Vector2.Zero.
outRelative outgoing handle; null/default gives Vector2.Zero.
indexInsert-before index; negative/out-of-range appends.
ClearPointsvoid
public void ClearPoints();Removes control points; baked data clear on the next query. Retains BakeInterval. Empty GetBakedLength yields 0 and GetBakedPoints yields an empty array; do not call Sample or orientation sampling before adding points.
GetBakeIntervalfloat
public float GetBakeInterval();Reads BakeInterval. Positive finite CPU-cache density scale in local units, default 5. Smaller usually produces more samples and memory/CPU work; neither exact analytic length nor perfectly equal spacing is promised. Subdivision depth is bounded. The setter validates neither positivity nor finiteness and invalidates the cache even for the same value.
floatStored cache-density scale, default 5 local units.
GetBakedLengthfloat
public float GetBakedLength();Lazily rebuilds a dirty cache and returns approximate polyline length in local units. Empty/single-point curves yield 0. Path2D scale/rotation are not automatically applied; not world length.
floatApproximate local baked-polyline length; 0 for an empty/single-point curve.
GetBakedPointsVector2[]
public Vector2[] GetBakedPoints();Returns an independent C# array of local baked positions, rebuilding if needed. Array indices are not control-point indices. Editing the array does not edit Curve2D.
Vector2[]New independent C# array of local approximation positions.
GetClosestOffsetfloat
public float GetClosestOffset(Vector2 toPoint);Returns local distance along the baked path to the closest toPoint projection, not perpendicular distance to the curve or t. A single point yields 0; account for a full segment scan on large caches.
| Name | Type | Default |
|---|---|---|
toPoint | Vector2 | — |
toPointFinite point in the same local coordinate system as Curve2D positions.
floatLocal distance along the path to the closest projection.
GetClosestPointVector2
public Vector2 GetClosestPoint(Vector2 toPoint);Scans baked-polyline segments for the closest local projection. An approximation rather than an exact original-Bezier solution or physics raycast. Convert world input with Path2D.ToLocal and the result with ToGlobal when needed. Degenerate segments were not separately accepted.
| Name | Type | Default |
|---|---|---|
toPoint | Vector2 | — |
toPointFinite point in the same local coordinate system as Curve2D positions.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
GetPointCountint
public int GetPointCount();Reads control-point count, not segment or baked-position count. An ordinary Curve2D with N≥2 points has N−1 segments.
intControl-point count, not baked-sample count.
GetPointInVector2
public Vector2 GetPointIn(int idx);Reads a relative incoming handle. Absolute Bezier control position is GetPointPosition(idx)+GetPointIn(idx). At an open path first point it defines no preceding segment.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxExisting control-point index; Sample takes a segment index.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
GetPointOutVector2
public Vector2 GetPointOut(int idx);Reads a relative outgoing handle. At the last point it creates no additional segment; explicitly coordinate endpoint geometry for a loop.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxExisting control-point index; Sample takes a segment index.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
GetPointPositionVector2
public Vector2 GetPointPosition(int idx);Reads an existing control point local position rather than world coordinates or a baked sample. Use the owning Path2D transform for world coordinates.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxExisting control-point index; Sample takes a segment index.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
RemovePointvoid
public void RemovePoint(int idx);Removes an existing index, shifts subsequent indices and invalidates the cache. Does not automatically close geometry into a loop.
| Name | Type | Default |
|---|---|---|
idx | int | — |
idxExisting control-point index; Sample takes a segment index.
SampleVector2
public Vector2 Sample(int idx, float t);Samples segment idx at parameter t. Equal t steps do not imply equal path distances.
| Name | Type | Default |
|---|---|---|
idx | int | — |
t | float | — |
idxExisting control-point index; Sample takes a segment index.
tFinite segment parameter, normally 0..1; neither distance nor elapsed seconds. Do not assume automatic t clamping.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
SampleBakedVector2
public Vector2 SampleBaked(float offset = 0f, bool cubic = false);Samples baked-cache distance offset. Length is approximate; match cubic with PathFollow2D when comparing.
| Name | Type | Default |
|---|---|---|
offset | float | 0f |
cubic | bool | false |
offsetFinite local baked-cache distance clamped to 0..GetBakedLength().
cubictrue interpolates the cache cubically; default false uses linear interpolation. Sparse-cache positions can differ even on a straight path.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
SampleBakedWithRotationTransform2D
public Transform2D SampleBakedWithRotation(float offset = 0f, bool cubic = false);Returns a local Transform2D: Origin is the sampled baked position, +X the tangent and +Y its perpendicular. offset is finite distance clamped to 0..length; cubic changes position interpolation. Orientation needs at least two nondegenerate points; one produces diagnostics. Applies no Path2D transform and assigns no Entity position automatically.
| Name | Type | Default |
|---|---|---|
offset | float | 0f |
cubic | bool | false |
offsetFinite local baked-cache distance clamped to 0..GetBakedLength().
cubictrue interpolates the cache cubically; default false uses linear interpolation. Sparse-cache positions can differ even on a straight path.
Transform2DLocal Transform2D with +X along the tangent, not a world transform.
SamplefVector2
public Vector2 Samplef(float fofs);Integer fofs is the segment index and its fraction is t. Neither a normalized whole-curve ratio nor a local-unit distance. Out-of-range values return endpoints without looping. Use valid segments 0..PointCount−2 for ordinary sampling.
| Name | Type | Default |
|---|---|---|
fofs | float | — |
fofsSegment index plus fractional t, not a normalized whole-curve ratio.
Vector2Local vector/position; a diagnosed zero fallback does not establish success.
SetBakeIntervalvoid
public void SetBakeInterval(float distance);Sets BakeInterval. Positive finite CPU-cache density scale in local units, default 5. Smaller usually produces more samples and memory/CPU work; neither exact analytic length nor perfectly equal spacing is promised. Subdivision depth is bounded. The setter validates neither positivity nor finiteness and invalidates the cache even for the same value.
| Name | Type | Default |
|---|---|---|
distance | float | — |
distancePositive finite local-unit BakeInterval; validate in caller code.
SetPointCountvoid
public void SetPointCount(int count);Sets PointCount. Control-point count, not baked-sample count. Growth appends zero positions/handles and can emit Changed per point; shrinking truncates the end. Not an atomic replacement curve. Prepare a separate resource before assigning Path2D.Curve when replacing a finished path.
| Name | Type | Default |
|---|---|---|
count | int | — |
countNonnegative control-point count; growth appends zero data.
SetPointInvoid
public void SetPointIn(int idx, Vector2 position);Sets an existing point relative incoming handle and invalidates the cache. Neither world coordinates nor the neighboring endpoint.
| Name | Type | Default |
|---|---|---|
idx | int | — |
position | Vector2 | — |
idxExisting control-point index; Sample takes a segment index.
positionFinite local position; SetPointIn/Out take a relative handle.
SetPointOutvoid
public void SetPointOut(int idx, Vector2 position);Sets an existing point relative outgoing handle and invalidates the cache. Add it to that point position for the absolute control position.
| Name | Type | Default |
|---|---|---|
idx | int | — |
position | Vector2 | — |
idxExisting control-point index; Sample takes a segment index.
positionFinite local position; SetPointIn/Out take a relative handle.
SetPointPositionvoid
public void SetPointPosition(int idx, Vector2 position);Changes an existing point local position while retaining its relative handles. Invalidates the cache and emits Changed; all owners see a shared-resource edit.
| Name | Type | Default |
|---|---|---|
idx | int | — |
position | Vector2 | — |
idxExisting control-point index; Sample takes a segment index.
positionFinite local position; SetPointIn/Out take a relative handle.
TessellateVector2[]
public Vector2[] Tessellate(int maxStages = 5, float toleranceDegrees = 4f);Returns a local polyline from adaptive angular toleranceDegrees subdivision. maxStages limits depth rather than point count. Edits no control data and promises neither equal spacing nor exact length.
| Name | Type | Default |
|---|---|---|
maxStages | int | 5 |
toleranceDegrees | float | 4f |
maxStagesSensible nonnegative subdivision depth, not output point count.
toleranceDegreesPositive finite angular criterion in degrees, bounded by maxStages.
Vector2[]New independent C# array of local approximation positions.
TessellateEvenLengthVector2[]
public Vector2[] TessellateEvenLength(int maxStages = 5, float toleranceLength = 20f);Returns a local polyline using toleranceLength, whose public SDK 1.0.0 default is 20 local units. Do not confuse it with Curve3D default 0.2. maxStages bounds depth: perfectly equal spacing or meeting tolerance is not guaranteed. Requires at least two points.
| Name | Type | Default |
|---|---|---|
maxStages | int | 5 |
toleranceLength | float | 20f |
maxStagesSensible nonnegative subdivision depth, not output point count.
toleranceLengthPositive finite local-unit length criterion; public default 20.
Vector2[]New independent C# array of local approximation positions.