ixfx
    Preparing search index...

    Class PointTracker

    A tracked point. Mutable. Useful for monitoring how it changes over time. Eg. when a pointerdown event happens, to record the start position and then track the pointer as it moves until pointerup.

    See also

    // Create a tracker on a pointerdown
    const t = new PointTracker();

    // ...and later, tell it when a point is seen (eg. pointermove)
    const nfo = t.seen({x: evt.x, y:evt.y});
    // nfo gives us some details on the relation between the seen point, the start, and points inbetween
    // nfo.angle, nfo.centroid, nfo.speed etc.

    Compute based on last seen point

    t.angleFromStart();
    t.distanceFromStart();
    t.x / t.y
    t.length; // Total length of accumulated points
    t.elapsed; // Total duration since start
    t.lastResult; // The PointSeenInfo for last seen point

    Housekeeping

    t.reset(); // Reset tracker
    

    By default, the tracker only keeps track of the initial point and does not store intermediate 'seen' points. To use the tracker as a buffer, set storeIntermediate option to true.

    // Keep only the last 10 points
    const t = new PointTracker({
    sampleLimit: 10
    });

    // Store all 'seen' points
    const t = new PointTracker({
    storeIntermediate: true
    });

    // In this case, the whole tracker is automatically
    // reset after 10 samples
    const t = new PointTracker({
    resetAfterSamples: 10
    })

    When using a buffer limited by sampleLimit, the 'initial' point will be the oldest in the buffer, not actually the very first point seen.

    Hierarchy (View Summary)

    Index

    Accessors

    • get elapsed(): number

      Returns the elapsed time, in milliseconds since the initial value

      Returns number

    • get size(): number

      Returns number of recorded values (includes the initial value in the count)

      Returns number

    Constructors

    Methods

    • Returns angle (in radians) from latest point to the initial point If there are less than two points, undefined is return.

      Returns undefined | number

      Angle in radians

    • Returns distance from latest point to initial point. If there are less than two points, zero is returned.

      This is the direct distance from initial to last, not the accumulated length.

      Returns number

      Distance

    • Adds a value, returning computed result.

      At this point, we check if the buffer is larger than resetAfterSamples. If so, reset() is called. If not, we check sampleLimit. If the buffer is twice as large as sample limit, trimStore() is called to take it down to sample limit, and onTrimmed() is called.

      Parameters

      Returns SeenResultType

    Properties

    debug: boolean
    id: string
    initialRelation: undefined | PointRelation
    lastResult:
        | undefined
        | Readonly<
            {
                fromInitial: PointRelationResult;
                fromLast: PointRelationResult;
                fromMark: undefined
                | PointRelationResult;
                values: readonly Point[];
            },
        >
    markRelation: undefined | PointRelation