// Generated API outline. Implementation bodies omitted.
#nullable enable
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using System;
using nfloat = System.Runtime.InteropServices.NFloat;
using static Xui.Core.Math2D.Constants;
namespace Xui.Core.Animation
{
///
/// Represents a 1D motion curve with constant deceleration (e.g., for scroll or fling).
/// Starts at a given position and velocity, then decelerates linearly to a stop.
///
///
/// This model is commonly used in UI frameworks to simulate natural-feeling scroll behavior.
/// The acceleration is constant and opposite to the direction of motion, resulting in
/// a predictable, smooth slowdown.
///
public readonly struct ConstantDecelerationCurve
{
///
/// The time when the motion begins.
///
public readonly TimeSpan StartTime;
///
/// The time when the motion stops (velocity reaches zero).
///
public readonly TimeSpan EndTime;
///
/// The constant acceleration applied during motion, typically negative.
///
public readonly nfloat A;
///
/// The initial velocity at , in pixels per second.
///
public readonly nfloat V0;
///
/// The initial position at , in pixels.
///
public readonly nfloat P0;
///
/// Constructs a motion curve with constant deceleration.
///
/// The time when motion begins.
/// The initial position at .
/// The initial velocity in pixels per second.
/// The magnitude of deceleration (must be positive).
/// Thrown if is not positive.
public ConstantDecelerationCurve(TimeSpan startTime, nfloat position, nfloat velocity, nfloat accelerationMagnitude);
///
/// The total duration of the motion in seconds.
///
public nfloat DurationSeconds { get; }
///
/// Evaluates the position at the specified time.
///
/// The absolute time at which to evaluate the position.
/// The position in pixels.
public nfloat this[TimeSpan time] {[DebuggerStepThrough]
get; }
///
/// Evaluates the velocity at the specified time.
///
/// The absolute time at which to evaluate the velocity.
/// The velocity in pixels per second.
public nfloat VelocityAt(TimeSpan time);
}
///
/// Represents a 1D cubic motion curve over time, interpolating both position and velocity.
/// Time is expressed using , and calculations are performed in seconds.
///
///
/// This curve is defined by a cubic polynomial:
/// f(t) = A·t³ + B·t² + C·t + D, where t is time in seconds since the global epoch.
/// It supports generation from boundary conditions (position and velocity at both ends),
/// as well as curve continuation with seamless velocity transitions.
///
public readonly struct CubicMotionCurve
{
///
/// The time at which the motion curve starts.
///
public readonly TimeSpan StartTime;
///
/// The time at which the motion curve ends.
///
public readonly TimeSpan EndTime;
///
/// The cubic coefficient (multiplied by t³).
///
public readonly nfloat A;
///
/// The quadratic coefficient (multiplied by t²).
///
public readonly nfloat B;
///
/// The linear coefficient (multiplied by t).
///
public readonly nfloat C;
///
/// The constant offset term.
///
public readonly nfloat D;
///
/// Initializes a new cubic motion curve with the given polynomial coefficients and time range.
///
public CubicMotionCurve(TimeSpan startTime, TimeSpan endTime, nfloat a, nfloat b, nfloat c, nfloat d);
///
/// The final position at .
///
public nfloat FinalPosition { get; }
///
/// The duration of the motion curve, in seconds.
///
public nfloat DurationSeconds { get; }
///
/// Continues the current curve by constructing a new cubic motion curve that
/// begins where this one leaves off, matching position and velocity, and
/// interpolating to a new position and velocity over the given time range.
///
public CubicMotionCurve ContinueWithBoundaryConditions(TimeSpan startTime, TimeSpan endTime, nfloat endPosition, nfloat endVelocity);
///
/// Constructs a cubic motion curve that interpolates position and velocity
/// between two points in time using Hermite interpolation.
///
/// The curve's start time.
/// The position at .
/// The velocity at .
/// The curve's end time.
/// The position at .
/// The velocity at .
/// A cubic motion curve satisfying the specified boundary conditions.
public static CubicMotionCurve FromBoundaryConditions(TimeSpan startTime, nfloat startPosition, nfloat startVelocity, TimeSpan endTime, nfloat endPosition, nfloat endVelocity);
///
/// Evaluates the position at the specified time.
///
/// An absolute time value.
/// The position at the given time.
public nfloat this[TimeSpan time] {[DebuggerStepThrough]
get; }
///
/// Evaluates the velocity at the specified time.
///
/// An absolute time value.
/// The velocity at the given time.
public nfloat VelocityAt(TimeSpan time);
}
///
/// Provides a collection of easing functions and smoothing utilities used in animations.
/// All easing methods are normalized to take a parameter t in the range [0, 1].
///
public static partial class Easing
{
///
/// Represents a 3rd- or 4th-degree polynomial easing function for animation timing curves.
///
///
/// This type can be used to approximate Bézier-based easing curves (like )
/// using polynomial coefficients, which are faster to evaluate and easier to store or serialize.
///
public readonly struct PolynomialEasing
{
/// The coefficient for x⁴ (A = 0 for cubic curves).
public readonly nfloat A;
/// The coefficient for x³.
public readonly nfloat B;
/// The coefficient for x².
public readonly nfloat C;
/// The coefficient for x¹.
public readonly nfloat D;
/// The constant term.
public readonly nfloat E;
///
/// Constructs a 3rd-degree polynomial: y = B·x³ + C·x² + D·x + E
///
public PolynomialEasing(nfloat b, nfloat c, nfloat d, nfloat e);
///
/// Constructs a 4th-degree polynomial: y = A·x⁴ + B·x³ + C·x² + D·x + E
///
public PolynomialEasing(nfloat a, nfloat b, nfloat c, nfloat d, nfloat e);
///
/// Approximates a easing curve using a cubic polynomial.
/// The result fits y = B·x³ + C·x² + D·x + E over the domain x ∈ [0, 1].
///
/// The Bézier curve to approximate.
/// Number of sample points to use in least-squares fitting. Default is 16.
public PolynomialEasing(CubicBezier bezier, int samples = 16);
///
/// Evaluates the polynomial at a given value of x ∈ [0, 1].
///
/// The input value (typically time).
/// The eased value at x.
public nfloat this[nfloat x] {[DebuggerStepThrough]
get; }
}
}
///
/// Provides a collection of easing functions and smoothing utilities used in animations.
/// All easing methods are normalized to take a parameter t in the range [0, 1].
///
public static partial class Easing
{
///
/// Normalizes a value between and into a [0,1] range.
/// Returns 0 if ≤ .
///
public static nfloat Normalize(nfloat value, nfloat min, nfloat max);
///
/// Eases in and out with a sine curve. Smoothest at beginning and end.
///
public static nfloat EaseInOutSine(nfloat t);
///
/// Accelerates slowly from 0 to 1 with a quadratic curve.
///
public static nfloat EaseInQuad(nfloat t);
///
/// Decelerates smoothly from 1 to 0 with a quadratic curve.
///
public static nfloat EaseOutQuad(nfloat t);
///
/// Accelerates and decelerates using a quadratic curve.
///
public static nfloat EaseInOutQuad(nfloat t);
///
/// Accelerates slowly with a cubic curve.
///
public static nfloat EaseInCubic(nfloat t);
///
/// Decelerates slowly with a cubic curve.
///
public static nfloat EaseOutCubic(nfloat t);
///
/// Smoothly accelerates and decelerates with a cubic curve.
///
public static nfloat EaseInOutCubic(nfloat t);
///
/// Stronger acceleration from 0 using a quartic curve.
///
public static nfloat EaseInQuart(nfloat t);
///
/// Stronger deceleration to 1 using a quartic curve.
///
public static nfloat EaseOutQuart(nfloat t);
///
/// Strong acceleration and deceleration using a quartic curve.
///
public static nfloat EaseInOutQuart(nfloat t);
///
/// Creates an elastic "bounce-in" effect at the beginning of the transition.
///
public static nfloat EaseInElastic(nfloat t);
///
/// Creates an elastic "bounce-out" effect at the end of the transition.
///
public static nfloat EaseOutElastic(nfloat t);
///
/// Combines EaseInElastic and EaseOutElastic for a spring-like bounce effect at both ends.
///
public static nfloat EaseInOutElastic(nfloat t);
///
/// Eases in with a "backwards" overshoot effect before settling forward.
///
public static nfloat EaseInBack(nfloat t);
///
/// Eases out with a slight overshoot after reaching the target.
///
public static nfloat EaseOutBack(nfloat t);
///
/// Eases in and out with a "backwards" overshoot at both ends.
///
public static nfloat EaseInOutBack(nfloat t);
///
/// Creates a bounce effect as if hitting the ground and bouncing back.
///
public static nfloat EaseOutBounce(nfloat t);
///
/// Reverses EaseOutBounce to ease in with bounce.
///
public static nfloat EaseInBounce(nfloat t);
///
/// Eases in and out with a bounce at both ends.
///
public static nfloat EaseInOutBounce(nfloat t);
///
/// Applies a smoothstep-like easing function that produces smooth transitions with zero first and second derivatives at boundaries.
///
public static nfloat SmootherStep(nfloat t);
///
/// Smoothly interpolates between two values using a critically damped spring-like function.
///
/// The starting value.
/// The target value.
/// Reference to current velocity (will be modified).
/// Time it takes to reach the target value.
/// Maximum speed during interpolation.
/// Elapsed time since the last update.
public static nfloat SmoothDamp(nfloat from, nfloat to, ref nfloat velocity, nfloat smoothTime, nfloat maxSpeed, nfloat deltaTime);
}
/// Bounded rubber-band displacement for dragging beyond a scrollable range.
public static class ElasticMotion
{
/// Maps an unconstrained position to a progressively resisted position outside the bounds.
public static nfloat Resist(nfloat position, nfloat min, nfloat max, nfloat viewport);
/// Maps a position with a platform-specific resistance factor (smaller values feel firmer).
public static nfloat Resist(nfloat position, nfloat min, nfloat max, nfloat viewport, nfloat resistance);
/// Recovers the drag position so a new delta or a grabbed rebound does not jump.
public static nfloat Unresist(nfloat position, nfloat min, nfloat max, nfloat viewport);
/// Inverts resistance using the same factor as the drag that produced the position.
public static nfloat Unresist(nfloat position, nfloat min, nfloat max, nfloat viewport, nfloat resistance);
}
///
/// Represents a motion curve where velocity decays exponentially over time.
/// Commonly used to simulate fling or momentum-based motion with smooth slowdown.
///
public readonly struct ExponentialDecayCurve
{
///
/// The time at which the motion begins.
///
public readonly TimeSpan StartTime;
///
/// The time at which the motion ends, determined by when velocity falls below a defined threshold.
///
public readonly TimeSpan EndTime;
///
/// The decay factor per second. Lower values result in faster deceleration.
///
public readonly nfloat DecayPerSecond;
///
/// The initial velocity at the start of the curve.
///
public readonly nfloat InitialVelocity;
///
/// The starting position of the motion.
///
public readonly nfloat StartPosition;
///
/// A typical decay factor (~0.998 per millisecond). Use for normal fling decay.
///
public static readonly nfloat Normal;
///
/// A faster decay factor (~0.99 per millisecond). Use for snappier motion.
///
public static readonly nfloat Fast;
///
/// Initializes an exponential decay motion curve.
///
/// The time when motion begins.
/// The initial position.
/// The initial velocity (can be negative).
///
/// The decay multiplier per second. A value less than 1, closer to 0 = faster decay.
/// Recommended value is .
///
///
/// The velocity below which motion is considered stopped (defaults to 0.5).
///
[DebuggerStepThrough]
public ExponentialDecayCurve(TimeSpan startTime, nfloat startPosition, nfloat initialVelocity, nfloat decayPerSecond, double velocityThreshold = 0.5);
///
/// Gets the final position of the motion at .
///
public nfloat FinalPosition { get; }
///
/// Evaluates the position of the motion at a given time.
///
/// The time to evaluate.
/// The interpolated position at the specified time.
public nfloat this[TimeSpan time] {[DebuggerStepThrough]
get; }
///
/// Evaluates the velocity of the motion at a given time.
///
/// The time to evaluate.
/// The current velocity at the specified time.
public nfloat VelocityAt(TimeSpan time);
}
///
/// Represents a 1D motion curve under constant acceleration, defined as a quadratic function of time.
///
/// This curve is useful for modeling motion that decelerates smoothly to a stop,
/// such as fling or scroll-stop animations.
///
public readonly struct QuadraticMotionCurve
{
///
/// The time at which the motion starts.
///
public readonly TimeSpan StartTime;
///
/// The time at which the motion ends (i.e., when velocity reaches zero).
///
public readonly TimeSpan EndTime;
///
/// The quadratic coefficient (0.5 * acceleration).
///
public readonly nfloat A;
///
/// The linear coefficient (initial velocity minus adjustment).
///
public readonly nfloat B;
///
/// The constant coefficient (initial position minus offset).
///
public readonly nfloat C;
///
/// Initializes the curve with explicit polynomial coefficients and time range.
///
/// The time when motion starts.
/// The time when motion ends.
/// The quadratic coefficient.
/// The linear coefficient.
/// The constant offset.
[DebuggerStepThrough]
public QuadraticMotionCurve(TimeSpan startTime, TimeSpan endTime, nfloat a, nfloat b, nfloat c);
///
/// Constructs a curve from initial position, velocity, and acceleration magnitude.
/// The acceleration is applied in the opposite direction of velocity to decelerate to zero.
///
/// The time when motion starts.
/// Initial position.
/// Initial velocity (positive or negative).
/// Positive scalar magnitude of deceleration.
public QuadraticMotionCurve(TimeSpan startTime, nfloat startPosition, nfloat startVelocity, nfloat accelerationMagnitude);
///
/// Gets the final position of the motion at .
///
public nfloat FinalPosition { get; }
///
/// Evaluates the position of the motion at the specified .
///
/// The time at which to evaluate the position.
public nfloat this[TimeSpan time] {[DebuggerStepThrough]
get; }
///
/// Evaluates the instantaneous velocity at the specified .
///
/// The time at which to evaluate the velocity.
/// The velocity in units per second.
public nfloat VelocityAt(TimeSpan time);
}
/// A critically damped spring evaluated analytically, independent of display refresh rate.
public readonly struct SpringMotionCurve
{
/// The time at which the rebound starts.
public TimeSpan StartTime { get; }
/// The exact resting position.
public nfloat Target { get; }
/// Creates a spring preserving initial position and velocity.
public SpringMotionCurve(TimeSpan startTime, nfloat position, nfloat velocity, nfloat target);
/// Evaluates the position at an absolute frame time.
public nfloat this[TimeSpan time] { get; }
/// Evaluates the velocity in units per second.
public nfloat VelocityAt(TimeSpan time);
/// Whether the curve is close enough to finish at its exact target.
public bool IsComplete(TimeSpan time);
}
}
namespace Xui.Core.Animation
{
using Xui.Core.Math2D;
///
/// Provides a collection of easing functions and smoothing utilities used in animations.
/// All easing methods are normalized to take a parameter t in the range [0, 1].
///
public static partial class Easing
{
///
/// Represents a CSS-style cubic Bézier easing curve constrained between (0,0) and (1,1).
///
///
/// These curves are used for timing animations and transitions.
/// The curve always starts at (0,0) and ends at (1,1), and the control points and
/// shape the acceleration and deceleration of the animation.
///
public readonly struct CubicBezier
{
/// The first control point (typically near the origin).
public readonly Point P1;
/// The second control point (typically near the destination).
public readonly Point P2;
///
/// Initializes a new CSS-style cubic Bézier easing curve with the given control points.
/// Assumes endpoints at (0,0) and (1,1).
///
public CubicBezier(Point p1, Point p2);
///
/// Returns the interpolated point on the Bézier curve at a given ∈ [0, 1].
///
public Point Lerp(nfloat t);
///
/// Approximates the Y output value for a given input X ∈ [0,1] using a 16-step lookup table.
///
public nfloat Evaluate(nfloat x);
///
/// Approximates the Y output value for a given input X ∈ [0,1] using binary search to the given precision.
///
public nfloat Evaluate(nfloat x, nfloat precision);
///
/// Indexer alias for .
///
public nfloat this[nfloat x] { get; }
///
/// Finds the parameter t ∈ [0, 1] where the curve is closest to the given point.
/// Uses 16-step approximation.
///
public nfloat ClosestT(Point target);
///
/// Returns a new cubic Bézier easing curve with a deformation applied near the closest point to ,
/// shifted by .
///
public CubicBezier Drag(Point origin, Vector delta);
///
/// Returns a new cubic Bézier easing curve with a deformation applied at the given parameter by .
///
public CubicBezier DragAt(nfloat t, Vector delta);
///
/// Converts a full into a CSS-style easing curve.
/// The curve must begin at (0,0) and end at (1,1).
///
public static implicit operator CubicBezier(Curves2D.CubicBezier bezier);
/// Equivalent to CSS `ease`: cubic-bezier(0.25, 0.1, 0.25, 1.0)
public static CubicBezier Ease { get; }
/// Equivalent to CSS `ease-in`: cubic-bezier(0.42, 0, 1.0, 1.0)
public static CubicBezier EaseIn { get; }
/// Equivalent to CSS `ease-out`: cubic-bezier(0, 0, 0.58, 1.0)
public static CubicBezier EaseOut { get; }
/// Equivalent to CSS `ease-in-out`: cubic-bezier(0.42, 0, 0.58, 1.0)
public static CubicBezier EaseInOut { get; }
}
}
}