Smoothable

westures-core. Smoothable

A Smoothable datatype is one that is capable of smoothing out a series of values as they come in, one at a time, providing a more consistent series. It does this by creating some inertia in the values using a cascading average. (For those who are interested in such things, this effectively means that it provides a practical application of Zeno's Dichotomy).

Constructor

new Smoothable(optionsopt)

Source:
Example
const x = new Smoothable({ identity: 1 });
const a = x.next(1);   // 1.0
const b = x.next(1.2); // 1.1
const c = x.next(0.9); // 1.0
const d = x.next(0.6); // 0.8
const e = x.next(1.2); // 1.0
const f = x.next(1.6); // 1.3
x.restart();
const g = x.next(0);   // 0.5
Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Default Description
applySmoothing boolean <optional>
true Whether to apply smoothing to the data.
identity * <optional>
0 The identity value of this smoothable data.

Members

[@@cascade] :object

Description:
  • The cascading average of outgoing values.
Source:
The cascading average of outgoing values.
Type:
  • object

identity :*

Description:
  • The "identity" value of the data that will be smoothed.
Source:
Default Value:
  • 0
The "identity" value of the data that will be smoothed.
Type:
  • *

Methods

[@@smooth](data) → (nullable) {object}

Description:
  • Smooth out the outgoing data.
Source:
Parameters:
Name Type Description
data object The next batch of data to emit.
Returns:
Type
object

average(a, b) → {number}

Description:
  • Average out two values, as part of the smoothing algorithm. Override this method if the data being smoothed is not a Number.
Source:
Parameters:
Name Type Description
a number
b number
Returns:
The average of 'a' and 'b'
Type
number

next(data) → {*}

Description:
  • The function through which smoothed emits are passed.
Source:
Parameters:
Name Type Description
data * The data to emit.
Returns:
The smoothed out data.
Type
*

restart()

Description:
  • Restart the Smoothable gesture.
Source:

(inner) smoothingIsApplicable(isRequested) → {boolean}

Description:
  • Determines whether to apply smoothing. Smoothing is on by default but turned off if either:
    1. The user explicitly requests that it be turned off.
    2. The active pointer is not "coarse".
Source:
See:
Parameters:
Name Type Description
isRequested boolean Whether smoothing was requested by the user.
Returns:
Whether to apply smoothing.
Type
boolean