Class BiasedEasing

java.lang.Object
com.hypixel.hytale.server.npc.util.BiasedEasing

public final class BiasedEasing extends Object
Strictly monotonic C² function on [0, 1] with f(0) = 0, f(1) = 1, f'(0) = k, f'(1) = e, f(0.5) = t Seam at x = 0.5 with slope s = f'(0.5) and zero second derivative there. Raw parameter bounds (monotonicity): 0 invalid input: '<'= s invalid input: '<'= maxSeamSlope(t) = 4 * min(t, 1 - t) 0 invalid input: '<'= k invalid input: '<'= maxInitialSlope(t) = 4 * t 0 invalid input: '<'= e invalid input: '<'= maxFinalSlope(t) = 4 * (1 - t) fromNormalized(t, sNorm, kNorm, eNorm) maps the unit cube onto the full valid box, so every normalized input tuple is legal. Read as a velocity profile, f is the relative speed and the endpoint slopes are accelerations. Read as a position profile, f is the fraction of the distance covered and the endpoint slopes are the speeds there, which is why e has to be settable: a ramp that ends at full speed cannot have f'(1) = 0. Also provides the closed-form antiderivative F(x) = ∫₀ˣ f, and a version rescaled so that it reaches exactly 1 at x = 1.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    How close to the true root inverse(double) narrows before returning.
  • Constructor Summary

    Constructors
    Constructor
    Description
    BiasedEasing(double t)
    Recommended: s = 4t(1-t), k = 0, e = 0.
    BiasedEasing(double t, double s)
    Explicit seam slope, zero endpoint slopes.
    BiasedEasing(double t, double s, double k)
    Explicit seam and initial slope, zero final slope.
    BiasedEasing(double t, double s, double k, double e)
    Fully explicit (raw units).
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    Returns the legal upper bound for the normalized final slope.
    static double
    Normalized seam slope that reproduces the harmonic-mean default.
    static double
    defaultSeamSlope(double t)
    The recommended default seam slope: harmonic mean of the chord slopes.
    double
    derivative(double x)
    Evaluates f'(x).
    forSlowEndSpeedRatio(double t, double sNorm, double eNorm, double slowEndSpeedRatio)
    Builds a position profile whose initial speed is slowEndSpeedRatio of its peak speed.
    fromNormalized(double t, double sNorm, double kNorm)
    Maps normalized seam and initial slopes linearly onto their valid bounds.
    fromNormalized(double t, double sNorm, double kNorm, double eNorm)
    As fromNormalized(double, double, double), with eNorm mapped onto [0, eMax(t)].
    double
    integral(double x)
    Antiderivative F(x) = ∫₀ˣ f(ξ) dξ, consistent with the clamped value(): constant 0 below x = 0, growing with slope 1 above x = 1.
    double
    inverse(double y)
    Solves f(x) = y to within DEFAULT_INVERSE_TOLERANCE.
    double
    inverse(double y, double tolerance)
    Solves f(x) = y on [0, 1] by bisection.
    static double
    maxFinalSlope(double t)
    Largest final slope keeping the curve monotone for this t.
    static double
    maxInitialSlope(double t)
    Largest initial slope keeping the curve monotone for this t.
    static double
    maxSeamSlope(double t)
    Largest seam slope keeping the curve monotone for this t.
    double
    meanValueFrom(double offset)
    Returns the mean of f over [offset, 1].
    double
    Returns the integral normalized to 1 at x = 1.
    double
    normalizedIntegralFrom(double offset, double progress)
    Returns the fraction accumulated over a valueFrom(double, double) sweep.
    double
    Steepest slope anywhere on [0, 1].
    double
    f'(0) as a fraction of peakDerivative(), so 0 when the curve starts flat.
    double
    Total integral ∫₀¹ f(ξ) dξ = F(1).
    double
    value(double x)
    Evaluates f(x), clamped outside [0, 1].
    double
    valueFrom(double offset, double progress)
    Evaluates the curve over [offset, 1].

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_INVERSE_TOLERANCE

      public static final double DEFAULT_INVERSE_TOLERANCE
      How close to the true root inverse(double) narrows before returning.
      See Also:
  • Constructor Details

    • BiasedEasing

      public BiasedEasing(double t)
      Recommended: s = 4t(1-t), k = 0, e = 0. Valid for every t in (0, 1).
    • BiasedEasing

      public BiasedEasing(double t, double s)
      Explicit seam slope, zero endpoint slopes.
    • BiasedEasing

      public BiasedEasing(double t, double s, double k)
      Explicit seam and initial slope, zero final slope.
    • BiasedEasing

      public BiasedEasing(double t, double s, double k, double e)
      Fully explicit (raw units). Clamps t into (0, 1) and each slope against its t-dependent bound.
  • Method Details

    • fromNormalized

      @Nonnull public static BiasedEasing fromNormalized(double t, double sNorm, double kNorm)
      Maps normalized seam and initial slopes linearly onto their valid bounds.
    • fromNormalized

      @Nonnull public static BiasedEasing fromNormalized(double t, double sNorm, double kNorm, double eNorm)
      As fromNormalized(double, double, double), with eNorm mapped onto [0, eMax(t)].
    • forSlowEndSpeedRatio

      @Nonnull public static BiasedEasing forSlowEndSpeedRatio(double t, double sNorm, double eNorm, double slowEndSpeedRatio)
      Builds a position profile whose initial speed is slowEndSpeedRatio of its peak speed. Uses bisection because the peak depends on the initial slope. An unreachable ratio uses the steepest legal initial slope.
    • maxSeamSlope

      public static double maxSeamSlope(double t)
      Largest seam slope keeping the curve monotone for this t.
    • maxInitialSlope

      public static double maxInitialSlope(double t)
      Largest initial slope keeping the curve monotone for this t.
    • maxFinalSlope

      public static double maxFinalSlope(double t)
      Largest final slope keeping the curve monotone for this t.
    • defaultSeamSlope

      public static double defaultSeamSlope(double t)
      The recommended default seam slope: harmonic mean of the chord slopes.
    • defaultNormalizedSeamSlope

      public static double defaultNormalizedSeamSlope(double t)
      Normalized seam slope that reproduces the harmonic-mean default.
    • defaultNormalizedFinalSlope

      public static double defaultNormalizedFinalSlope()
      Returns the legal upper bound for the normalized final slope. Position-profile ramps use it for a full-speed handover at the fast end.
    • value

      public double value(double x)
      Evaluates f(x), clamped outside [0, 1].
    • valueFrom

      public double valueFrom(double offset, double progress)
      Evaluates the curve over [offset, 1]. Maps progress from [0, 1] onto that range.
    • derivative

      public double derivative(double x)
      Evaluates f'(x). Returns k at 0 and e at 1. Constant outside [0, 1].
    • inverse

      public double inverse(double y)
      Solves f(x) = y to within DEFAULT_INVERSE_TOLERANCE.
    • inverse

      public double inverse(double y, double tolerance)
      Solves f(x) = y on [0, 1] by bisection. Strict monotonicity makes the root unique and bounds its value error by 4 * tolerance.
    • integral

      public double integral(double x)
      Antiderivative F(x) = ∫₀ˣ f(ξ) dξ, consistent with the clamped value(): constant 0 below x = 0, growing with slope 1 above x = 1. F is C³ across the seam. F(1) = totalIntegral().
    • normalizedIntegral

      public double normalizedIntegral(double x)
      Returns the integral normalized to 1 at x = 1. For a velocity profile, this is normalized displacement. Its endpoint slopes are f(x) / F(1).
    • normalizedIntegralFrom

      public double normalizedIntegralFrom(double offset, double progress)
      Returns the fraction accumulated over a valueFrom(double, double) sweep. For a velocity profile, this is its position profile. A degenerate span returns progress.
    • peakDerivative

      public double peakDerivative()
      Steepest slope anywhere on [0, 1].
    • slowEndSpeedRatio

      public double slowEndSpeedRatio()
      f'(0) as a fraction of peakDerivative(), so 0 when the curve starts flat.
    • totalIntegral

      public double totalIntegral()
      Total integral ∫₀¹ f(ξ) dξ = F(1).
    • meanValueFrom

      public double meanValueFrom(double offset)
      Returns the mean of f over [offset, 1]. For a velocity profile, distance divided by this mean gives duration. A degenerate span returns f(1) = 1.