Package net.paulhertz.pixelaudio.curves

# Class PAGestureParametric

java.lang.Object
net.paulhertz.pixelaudio.curves.PAGestureParametric

public final class PAGestureParametric extends Object
Treats a gesture defined by (time, x, y) samples as a parametric curve. `u ∈ [0,1] → (t(u), x(u), y(u))`

Under the hood:

- timesMs: int[] of time offsets (ms), ascending, timesMs[0] == 0
- points: PVector list (x,y) of same length

You can:

sample with a linear parameter: f(u) = u
- pass a warp function f(u) to speed up/slow down traversal

Exponential warp (speeding up over time)

        DoubleUnaryOperator expWarp = u -> (float_ Math.pow(u, 2.0);   // u^2
        GestureParametric.Sample s = gp.sample(0.5f, expWarp);

Log-like warp (fast at start, slow at end)

        DoubleUnaryOperator sqrtWarp = u -> (float_ Math.sqrt(u);   //
        GestureParametric.Sample s = gp.sample(0.5f, sqrtWarp);

Something like f(u) = (e^{k * u} - 1) / (e^{k} - 1) for more dramatic warps.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `PAGestureParametric.Sample`
  Data storage class for PAGestureParametric.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `private final int`
  `count`
  `private final List<processing.core.PVector>`
  `points`
  `private final int[]`
  `timesMs`
  `private final float`
  `totalDurationMs`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PAGestureParametric(List<processing.core.PVector> points, int[] timesMs)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `private int`
  `findSegment(float tTarget)`
  Find the largest i such that timesMs[i] <= tTarget.
  `float`
  `getTotalDurationMs()`
  Total gesture duration in ms.
  `private static float`
  `lerp(float a, float b, float u)`
  `PAGestureParametric.Sample`
  `sample(float u)`
  Sample with linear parameterization: f(u) = u.
  `PAGestureParametric.Sample`
  `sample(float u, DoubleUnaryOperator warp)`
  Sample with an optional warp function f(u) → [0,1].

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### points

    private final List<processing.core.PVector> points

  - ### timesMs

    private final int[] timesMs

  - ### count

    private final int count

  - ### totalDurationMs

    private final float totalDurationMs

- ## Constructor Details

  - ### PAGestureParametric

    public PAGestureParametric(List<processing.core.PVector> points, int[] timesMs)
    Parameters:
      `points` - gesture points (x,y)
      `timesMs` - time offsets (ms), same length as points, ascending, timesMs[0] == 0

- ## Method Details

  - ### getTotalDurationMs

    public float getTotalDurationMs()
    Total gesture duration in ms.

  - ### sample

    public PAGestureParametric.Sample sample(float u)
    Sample with linear parameterization: f(u) = u. u is clamped to [0,1].

  - ### sample

    public PAGestureParametric.Sample sample(float u, DoubleUnaryOperator warp)
    Sample with an optional warp function f(u) → [0,1]. If warp is null, identity is used.

  - ### findSegment

    private int findSegment(float tTarget)
    Find the largest i such that timesMs[i] <= tTarget. Returns count-1 if tTarget is beyond the last sample.

  - ### lerp

    private static float lerp(float a, float b, float u)