reckfellENGINE

Curve2D

Cubic Bezier segments and a 2D distance cache.

On this page
class Curve2DReckfellSharpInherits Resource

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.

Practical guide.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

Curve2DConstructor
# Curve2D
C#
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
# BakeInterval
C#
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
# PointCount
C#
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
# _Data
C#
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
# AddPoint
C#
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.

Parameters
NameTypeDefault
positionVector2—
inVector2?default
outVector2?default
indexint-1
position

Finite local position; SetPointIn/Out take a relative handle.

in

Relative incoming handle; null/default gives Vector2.Zero.

out

Relative outgoing handle; null/default gives Vector2.Zero.

index

Insert-before index; negative/out-of-range appends.

ClearPointsvoid
# ClearPoints
C#
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
# GetBakeInterval
C#
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.

Returns float

Stored cache-density scale, default 5 local units.

GetBakedLengthfloat
# GetBakedLength
C#
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.

Returns float

Approximate local baked-polyline length; 0 for an empty/single-point curve.

GetBakedPointsVector2[]
# GetBakedPoints
C#
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.

Returns Vector2[]

New independent C# array of local approximation positions.

GetClosestOffsetfloat
# GetClosestOffset
C#
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.

Parameters
NameTypeDefault
toPointVector2—
toPoint

Finite point in the same local coordinate system as Curve2D positions.

Returns float

Local distance along the path to the closest projection.

GetClosestPointVector2
# GetClosestPoint
C#
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.

Parameters
NameTypeDefault
toPointVector2—
toPoint

Finite point in the same local coordinate system as Curve2D positions.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

GetPointCountint
# GetPointCount
C#
public int GetPointCount();

Reads control-point count, not segment or baked-position count. An ordinary Curve2D with N≥2 points has N−1 segments.

Returns int

Control-point count, not baked-sample count.

GetPointInVector2
# GetPointIn
C#
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.

Parameters
NameTypeDefault
idxint—
idx

Existing control-point index; Sample takes a segment index.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

GetPointOutVector2
# GetPointOut
C#
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.

Parameters
NameTypeDefault
idxint—
idx

Existing control-point index; Sample takes a segment index.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

GetPointPositionVector2
# GetPointPosition
C#
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.

Parameters
NameTypeDefault
idxint—
idx

Existing control-point index; Sample takes a segment index.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

RemovePointvoid
# RemovePoint
C#
public void RemovePoint(int idx);

Removes an existing index, shifts subsequent indices and invalidates the cache. Does not automatically close geometry into a loop.

Parameters
NameTypeDefault
idxint—
idx

Existing control-point index; Sample takes a segment index.

SampleVector2
# Sample
C#
public Vector2 Sample(int idx, float t);

Samples segment idx at parameter t. Equal t steps do not imply equal path distances.

Parameters
NameTypeDefault
idxint—
tfloat—
idx

Existing control-point index; Sample takes a segment index.

t

Finite segment parameter, normally 0..1; neither distance nor elapsed seconds. Do not assume automatic t clamping.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

SampleBakedVector2
# SampleBaked
C#
public Vector2 SampleBaked(float offset = 0f, bool cubic = false);

Samples baked-cache distance offset. Length is approximate; match cubic with PathFollow2D when comparing.

Parameters
NameTypeDefault
offsetfloat0f
cubicboolfalse
offset

Finite local baked-cache distance clamped to 0..GetBakedLength().

cubic

true interpolates the cache cubically; default false uses linear interpolation. Sparse-cache positions can differ even on a straight path.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

SampleBakedWithRotationTransform2D
# SampleBakedWithRotation
C#
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.

Parameters
NameTypeDefault
offsetfloat0f
cubicboolfalse
offset

Finite local baked-cache distance clamped to 0..GetBakedLength().

cubic

true interpolates the cache cubically; default false uses linear interpolation. Sparse-cache positions can differ even on a straight path.

Returns Transform2D

Local Transform2D with +X along the tangent, not a world transform.

SamplefVector2
# Samplef
C#
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.

Parameters
NameTypeDefault
fofsfloat—
fofs

Segment index plus fractional t, not a normalized whole-curve ratio.

Returns Vector2

Local vector/position; a diagnosed zero fallback does not establish success.

SetBakeIntervalvoid
# SetBakeInterval
C#
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.

Parameters
NameTypeDefault
distancefloat—
distance

Positive finite local-unit BakeInterval; validate in caller code.

SetPointCountvoid
# SetPointCount
C#
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.

Parameters
NameTypeDefault
countint—
count

Nonnegative control-point count; growth appends zero data.

SetPointInvoid
# SetPointIn
C#
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.

Parameters
NameTypeDefault
idxint—
positionVector2—
idx

Existing control-point index; Sample takes a segment index.

position

Finite local position; SetPointIn/Out take a relative handle.

SetPointOutvoid
# SetPointOut
C#
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.

Parameters
NameTypeDefault
idxint—
positionVector2—
idx

Existing control-point index; Sample takes a segment index.

position

Finite local position; SetPointIn/Out take a relative handle.

SetPointPositionvoid
# SetPointPosition
C#
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.

Parameters
NameTypeDefault
idxint—
positionVector2—
idx

Existing control-point index; Sample takes a segment index.

position

Finite local position; SetPointIn/Out take a relative handle.

TessellateVector2[]
# Tessellate
C#
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.

Parameters
NameTypeDefault
maxStagesint5
toleranceDegreesfloat4f
maxStages

Sensible nonnegative subdivision depth, not output point count.

toleranceDegrees

Positive finite angular criterion in degrees, bounded by maxStages.

Returns Vector2[]

New independent C# array of local approximation positions.

TessellateEvenLengthVector2[]
# TessellateEvenLength
C#
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.

Parameters
NameTypeDefault
maxStagesint5
toleranceLengthfloat20f
maxStages

Sensible nonnegative subdivision depth, not output point count.

toleranceLength

Positive finite local-unit length criterion; public default 20.

Returns Vector2[]

New independent C# array of local approximation positions.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.