reckfellENGINE

Curve

A cubic Y-from-X function with tangents and a sampling cache.

On this page
class CurveReckfellSharpInherits Resource

Curve stores (X, Y) points and tangent slopes dy/dx. Sample evaluates the original curve; SampleBaked uses a uniform cache with linear interpolation. This is not a Curve2D/Curve3D path. Sampling coordinates use domain units; the default domain is 0…1.

Use Linear for a straight transition: default zero Free tangents produce a smooth cubic curve. Complete example:

C#
using Reckfell;

public static class UnitRamp
{
    public static Curve Create()
    {
        var curve = new Curve { BakeResolution = 128 };
        curve.AddPoint(Vector2.Zero,
            leftMode: Curve.TangentMode.Linear, rightMode: Curve.TangentMode.Linear);
        curve.AddPoint(Vector2.One,
            leftMode: Curve.TangentMode.Linear, rightMode: Curve.TangentMode.Linear);
        return curve;
    }
}

AddPoint clamps the position to bounds, SetPointValue does not clamp Y, and SetPointOffset re-clamps both coordinates and returns a new index. Do not treat indices as permanent identifiers. Value bounds do not clamp cubic overshoot.

BakeResolution changes cache accuracy but does not emit Changed. Call EmitChanged() after editing it if a connected CurveTexture must refresh. Resolution 1 produces a constant cache equal to the last Y.

Known current-version defect: CleanDupes also removes points with distinct X values. Do not call it on working data. This checked helper preserves distinct positions and removes the right point only when adjacent X values are exactly equal; it neither merges nearby values nor fixes the native method:

C#
using System;
using Reckfell;

public static class CurveTools
{
    // Removes the right-hand point only when adjacent X values are exactly equal.
    public static int RemoveExactDuplicateOffsets(Curve curve)
    {
        ArgumentNullException.ThrowIfNull(curve);
        int removed = 0;
        for (int i = curve.GetPointCount() - 1; i > 0; i--)
        {
            if (curve.GetPointPosition(i).X == curve.GetPointPosition(i - 1).X)
            {
                curve.RemovePoint(i);
                removed++;
            }
        }
        return removed;
    }
}

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

Constructors1

CurveConstructor
# Curve
C#
public Curve();

Creates an empty curve with domain and value range 0…1 and BakeResolution=100.

Properties8

BakeResolutionProperty
# BakeResolution
C#
public int BakeResolution { get; set; }

Baked cache sample count, 1…1000, initially 100. Use at least 2 for a varying value. The setter invalidates the cache but does not emit Changed: call EmitChanged() to refresh a connected CurveTexture after this edit.

MaxDomainProperty
# MaxDomain
C#
public float MaxDomain { get; set; }

Upper X bound, initially 1. The setter preserves the last point and at least a 0.01 gap to MinDomain; it does not scale points. Invalidates the cache and emits Changed and DomainChanged.

MaxValueProperty
# MaxValue
C#
public float MaxValue { get; set; }

Upper bound for newly added Y values, initially 1. The setter preserves existing point maxima and at least a 0.01 gap to MinValue. Tangents can produce samples above this bound; emits RangeChanged without Changed.

MinDomainProperty
# MinDomain
C#
public float MinDomain { get; set; }

Lower X bound, initially 0. The setter preserves the first point and at least a 0.01 gap to MaxDomain; it does not move points. Invalidates the cache and emits Changed and DomainChanged.

MinValueProperty
# MinValue
C#
public float MinValue { get; set; }

Lower bound for newly added Y values, initially 0. The setter preserves existing point minima and at least a 0.01 gap to MaxValue. It does not clamp cubic interpolation output; emits RangeChanged without Changed.

PointCountProperty
# PointCount
C#
public int PointCount { get; set; }

Point count, initially 0. Shrinking discards trailing points. Growing does not space X evenly: new X values are domain-clamped zero for an empty curve, otherwise MaxDomain. Use AddPoint for deliberate point placement.

_DataProperty
# _Data
C#
public Reckfell.Collections.Array _Data { get; set; }

Internal serialization property: five elements per point — Vector2, left/right tangents and left/right modes. The getter returns an independent container. The setter neither sorts nor clamps positions; use point methods in application code rather than editing storage format.

_LimitsProperty
# _Limits
C#
public Reckfell.Collections.Array _Limits { get; set; }

Internal serialization property: [MinValue, MaxValue, MinDomain, MaxDomain]. The getter returns an independent container. Its loading setter bypasses public constraints and notifications; change bounds through public properties.

Methods32

AddPointint
# AddPoint
C#
public int AddPoint(Vector2 position, float leftTangent = 0f, float rightTangent = 0f, Curve.TangentMode leftMode = Curve.TangentMode.Free, Curve.TangentMode rightMode = Curve.TangentMode.Free);

Clamps X to the domain and Y to the value range, then inserts in X order. Returns the current index. Default zero Free tangents produce a smooth cubic transition rather than a straight line; set both sides to Linear for a straight segment.

Parameters
NameTypeDefault
positionVector2—
leftTangentfloat0f
rightTangentfloat0f
leftModeCurve.TangentModeCurve.TangentMode.Free
rightModeCurve.TangentModeCurve.TangentMode.Free
position

Finite X and Y; AddPoint clamps them to current bounds.

leftTangent

Left tangent slope dy/dx; defaults to 0.

rightTangent

Right tangent slope dy/dx; defaults to 0.

leftMode

Free or Linear for the left side.

rightMode

Free or Linear for the right side.

Returns int

The point’s new insertion index; other indices can change.

Bakevoid
# Bake
C#
public void Bake();

Rebuilds the uniform cache over the current domain using BakeResolution. SampleBaked also rebuilds a dirty cache on demand; Sample uses the original curve.

CleanDupesvoid
# CleanDupes
C#
public void CleanDupes();

Do not use in the current version: a check with three distinct X values retained only one point. The native comparison also removes distinct adjacent positions. The engine defect is not fixed; RemoveExactDuplicateOffsets in the class example removes only exactly equal X values.

ClearPointsvoid
# ClearPoints
C#
public void ClearPoints();

Removes all points. Sample and SampleBaked return 0 after clearing.

GetBakeResolutionint
# GetBakeResolution
C#
public int GetBakeResolution();

Baked cache sample count, 1…1000, initially 100. Use at least 2 for a varying value. The setter invalidates the cache but does not emit Changed: call EmitChanged() to refresh a connected CurveTexture after this edit.

Returns int

Baked cache sample count, 1…1000, initially 100. Use at least 2 for a varying value. The setter invalidates the cache but does not emit Changed: call EmitChanged() to refresh a connected CurveTexture after this edit.

GetDomainRangefloat
# GetDomainRange
C#
public float GetDomainRange();

Returns MaxDomain − MinDomain in X-coordinate units.

Returns float

Returns MaxDomain − MinDomain in X-coordinate units.

GetMaxDomainfloat
# GetMaxDomain
C#
public float GetMaxDomain();

Upper X bound, initially 1. The setter preserves the last point and at least a 0.01 gap to MinDomain; it does not scale points. Invalidates the cache and emits Changed and DomainChanged.

Returns float

Upper X bound, initially 1. The setter preserves the last point and at least a 0.01 gap to MinDomain; it does not scale points. Invalidates the cache and emits Changed and DomainChanged.

GetMaxValuefloat
# GetMaxValue
C#
public float GetMaxValue();

Upper bound for newly added Y values, initially 1. The setter preserves existing point maxima and at least a 0.01 gap to MinValue. Tangents can produce samples above this bound; emits RangeChanged without Changed.

Returns float

Upper bound for newly added Y values, initially 1. The setter preserves existing point maxima and at least a 0.01 gap to MinValue. Tangents can produce samples above this bound; emits RangeChanged without Changed.

GetMinDomainfloat
# GetMinDomain
C#
public float GetMinDomain();

Lower X bound, initially 0. The setter preserves the first point and at least a 0.01 gap to MaxDomain; it does not move points. Invalidates the cache and emits Changed and DomainChanged.

Returns float

Lower X bound, initially 0. The setter preserves the first point and at least a 0.01 gap to MaxDomain; it does not move points. Invalidates the cache and emits Changed and DomainChanged.

GetMinValuefloat
# GetMinValue
C#
public float GetMinValue();

Lower bound for newly added Y values, initially 0. The setter preserves existing point minima and at least a 0.01 gap to MaxValue. It does not clamp cubic interpolation output; emits RangeChanged without Changed.

Returns float

Lower bound for newly added Y values, initially 0. The setter preserves existing point minima and at least a 0.01 gap to MaxValue. It does not clamp cubic interpolation output; emits RangeChanged without Changed.

GetPointCountint
# GetPointCount
C#
public int GetPointCount();

Point count, initially 0. Shrinking discards trailing points. Growing does not space X evenly: new X values are domain-clamped zero for an empty curve, otherwise MaxDomain. Use AddPoint for deliberate point placement.

Returns int

Point count, initially 0. Shrinking discards trailing points. Growing does not space X evenly: new X values are domain-clamped zero for an empty curve, otherwise MaxDomain. Use AddPoint for deliberate point placement.

GetPointLeftModeCurve.TangentMode
# GetPointLeftMode
C#
public Curve.TangentMode GetPointLeftMode(int index);

Returns an existing point’s tangent mode: Free or Linear.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Returns Curve.TangentMode

Returns an existing point’s tangent mode: Free or Linear.

GetPointLeftTangentfloat
# GetPointLeftTangent
C#
public float GetPointLeftTangent(int index);

Returns an existing point’s tangent slope dy/dx, not an angle in degrees.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Returns float

Returns an existing point’s tangent slope dy/dx, not an angle in degrees.

GetPointPositionVector2
# GetPointPosition
C#
public Vector2 GetPointPosition(int index);

Returns an existing point’s (X, Y). Insertion, removal and SetPointOffset can change indices.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Returns Vector2

Returns an existing point’s (X, Y). Insertion, removal and SetPointOffset can change indices.

GetPointRightModeCurve.TangentMode
# GetPointRightMode
C#
public Curve.TangentMode GetPointRightMode(int index);

Returns an existing point’s tangent mode: Free or Linear.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Returns Curve.TangentMode

Returns an existing point’s tangent mode: Free or Linear.

GetPointRightTangentfloat
# GetPointRightTangent
C#
public float GetPointRightTangent(int index);

Returns an existing point’s tangent slope dy/dx, not an angle in degrees.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Returns float

Returns an existing point’s tangent slope dy/dx, not an angle in degrees.

GetValueRangefloat
# GetValueRange
C#
public float GetValueRange();

Returns MaxValue − MinValue; this is not the actual interpolated curve amplitude.

Returns float

Returns MaxValue − MinValue; this is not the actual interpolated curve amplitude.

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

Removes an existing point by index and updates neighboring automatic tangents. Removing the last point is allowed.

Parameters
NameTypeDefault
indexint—
index

An existing point index: 0 ≤ index < PointCount.

Samplefloat
# Sample
C#
public float Sample(float offset);

Evaluates the cubic curve at a finite domain coordinate, not necessarily 0…1. Before/after the endpoints it returns the endpoint Y; an empty curve returns 0 and a single point its constant Y. Tangents can exceed MinValue/MaxValue.

Parameters
NameTypeDefault
offsetfloat—
offset

A finite X coordinate in domain units.

Returns float

Evaluates the cubic curve at a finite domain coordinate, not necessarily 0…1. Before/after the endpoints it returns the endpoint Y; an empty curve returns 0 and a single point its constant Y. Tangents can exceed MinValue/MaxValue.

SampleBakedfloat
# SampleBaked
C#
public float SampleBaked(float offset);

Bakes a dirty cache on demand and linearly interpolates cached samples in domain coordinates. This approximates Sample. With BakeResolution=1 the entire cache equals the last Y; use at least 2 for a varying curve.

Parameters
NameTypeDefault
offsetfloat—
offset

A finite X coordinate in domain units.

Returns float

Bakes a dirty cache on demand and linearly interpolates cached samples in domain coordinates. This approximates Sample. With BakeResolution=1 the entire cache equals the last Y; use at least 2 for a varying curve.

SetBakeResolutionvoid
# SetBakeResolution
C#
public void SetBakeResolution(int resolution);

Baked cache sample count, 1…1000, initially 100. Use at least 2 for a varying value. The setter invalidates the cache but does not emit Changed: call EmitChanged() to refresh a connected CurveTexture after this edit.

Parameters
NameTypeDefault
resolutionint—
resolution

Sample count 1…1000; at least 2 for a varying curve.

SetMaxDomainvoid
# SetMaxDomain
C#
public void SetMaxDomain(float max);

Upper X bound, initially 1. The setter preserves the last point and at least a 0.01 gap to MinDomain; it does not scale points. Invalidates the cache and emits Changed and DomainChanged.

Parameters
NameTypeDefault
maxfloat—
max

Requested finite upper bound; the setter preserves existing points and the minimum gap.

SetMaxValuevoid
# SetMaxValue
C#
public void SetMaxValue(float max);

Upper bound for newly added Y values, initially 1. The setter preserves existing point maxima and at least a 0.01 gap to MinValue. Tangents can produce samples above this bound; emits RangeChanged without Changed.

Parameters
NameTypeDefault
maxfloat—
max

Requested finite upper bound; the setter preserves existing points and the minimum gap.

SetMinDomainvoid
# SetMinDomain
C#
public void SetMinDomain(float min);

Lower X bound, initially 0. The setter preserves the first point and at least a 0.01 gap to MaxDomain; it does not move points. Invalidates the cache and emits Changed and DomainChanged.

Parameters
NameTypeDefault
minfloat—
min

Requested finite lower bound; the setter preserves existing points and the minimum gap.

SetMinValuevoid
# SetMinValue
C#
public void SetMinValue(float min);

Lower bound for newly added Y values, initially 0. The setter preserves existing point minima and at least a 0.01 gap to MaxValue. It does not clamp cubic interpolation output; emits RangeChanged without Changed.

Parameters
NameTypeDefault
minfloat—
min

Requested finite lower bound; the setter preserves existing points and the minimum gap.

SetPointCountvoid
# SetPointCount
C#
public void SetPointCount(int count);

Point count, initially 0. Shrinking discards trailing points. Growing does not space X evenly: new X values are domain-clamped zero for an empty curve, otherwise MaxDomain. Use AddPoint for deliberate point placement.

Parameters
NameTypeDefault
countint—
count

New nonnegative point count; growing does not space X evenly.

SetPointLeftModevoid
# SetPointLeftMode
C#
public void SetPointLeftMode(int index, Curve.TangentMode mode);

Changes the left tangent: Free uses the assigned slope, Linear computes a slope from the neighboring point. ModeCount is a sentinel, not a mode.

Parameters
NameTypeDefault
indexint—
modeCurve.TangentMode—
index

An existing point index: 0 ≤ index < PointCount.

mode

Free or Linear; not ModeCount.

SetPointLeftTangentvoid
# SetPointLeftTangent
C#
public void SetPointLeftTangent(int index, float tangent);

Sets the left tangent as dy/dx and switches it to Free. A steep slope can produce Y outside the value range.

Parameters
NameTypeDefault
indexint—
tangentfloat—
index

An existing point index: 0 ≤ index < PointCount.

tangent

A finite slope dy/dx, not an angle.

SetPointOffsetint
# SetPointOffset
C#
public int SetPointOffset(int index, float offset);

Reinserts a point with a new X, clamps X to the domain and also re-clamps its Y to the value range. Returns the new index; the old index is not a stable identifier.

Parameters
NameTypeDefault
indexint—
offsetfloat—
index

An existing point index: 0 ≤ index < PointCount.

offset

A finite X coordinate in domain units.

Returns int

The point’s new insertion index; other indices can change.

SetPointRightModevoid
# SetPointRightMode
C#
public void SetPointRightMode(int index, Curve.TangentMode mode);

Changes the right tangent: Free uses the assigned slope, Linear computes a slope from the neighboring point. ModeCount is a sentinel, not a mode.

Parameters
NameTypeDefault
indexint—
modeCurve.TangentMode—
index

An existing point index: 0 ≤ index < PointCount.

mode

Free or Linear; not ModeCount.

SetPointRightTangentvoid
# SetPointRightTangent
C#
public void SetPointRightTangent(int index, float tangent);

Sets the right tangent as dy/dx and switches it to Free. A steep slope can produce Y outside the value range.

Parameters
NameTypeDefault
indexint—
tangentfloat—
index

An existing point index: 0 ≤ index < PointCount.

tangent

A finite slope dy/dx, not an angle.

SetPointValuevoid
# SetPointValue
C#
public void SetPointValue(int index, float y);

Replaces an existing point’s Y without clamping to MinValue/MaxValue and updates automatic tangents. Later reinsertion through SetPointOffset clamps Y again.

Parameters
NameTypeDefault
indexint—
yfloat—
index

An existing point index: 0 ≤ index < PointCount.

y

A finite Y value; this setter does not clamp it to the value range.

Signals and events2

DomainChangedEvent
# DomainChanged
C#
public event Action DomainChanged;

Notification from domain-bound setters; accompanied by Changed and cache rebuilding on subsequent sampling. It does not mean points were moved.

RangeChangedEvent
# RangeChanged
C#
public event Action RangeChanged;

Notification from value-bound setters. By itself it does not emit Changed or refresh connected textures.

Curve.TangentMode

ValueDescription
Free = 0

The tangent on this side of the point is user-defined.

Linear = 1

The curve calculates the tangent on this side of the point as the slope halfway towards the adjacent point.

ModeCount = 2

The total number of available tangent modes.

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.