Function
Static Public Summary | ||
public |
calcStepSize(value: number, stepAmount: number): number Finds the best fitting scale for a given range. |
|
public |
Constrain a value within a range of values. |
|
public |
Cosine function that can accept angles in radians or degrees. |
|
public |
Given a set of two points the squared distance is calculated. |
|
public |
Makes sure that a HTML id allways has a # at the beginning. |
|
public |
Format a number to have a certain number of decimal places and/or fixed places and add a unit label. |
|
public |
Generate a random number following a gaussian distribuition. |
|
public |
Obtains the pixel ratio of the device. |
|
public |
Determines if a point is inside of a box. |
|
public |
isFunction(f: object): boolean Test if an object is a function. |
|
public |
Test if an object is an object. |
|
public |
Test if an object is a string. |
|
public |
loadOptions(obj: object, args: object) Assign the matching properties from the args object to the obj object. |
|
public |
Given an angle makes sure that it is in radians. |
|
public |
Adds an alpha channel to an rgb color. |
|
public |
Round a number to a given amount of decimal places. |
|
public |
Sine function that can accept angles in radians or degrees. |
Static Public
public calcStepSize(value: number, stepAmount: number): number source
import {calcStepSize} from 'newton-lib/src/utils/Utils.js'
Finds the best fitting scale for a given range. Used for simulations where the scale of the data changes dramatically.
public clamp(val: number, min: number, max: number): number source
import {clamp} from 'newton-lib/src/utils/Utils.js'
Constrain a value within a range of values. If value > max then value = max; If value < min then value = min;
public cos(val: number, type: number): number source
import {cos} from 'newton-lib/src/utils/Utils.js'
Cosine function that can accept angles in radians or degrees.
Params:
Name | Type | Attribute | Description |
val | number | Angle for calculating the cosine. |
|
type | number | Determines if the angle provided is in radians or in degrees. See ANGLE_STYLE. |
public distSquared(x0: number, y0: number, x1: number, y1: number): number source
import {distSquared} from 'newton-lib/src/utils/Utils.js'
Given a set of two points the squared distance is calculated. This is faster than calculating the Euclidean distance between them, since no square root is calculated.
public fixId(id: string): string source
import {fixId} from 'newton-lib/src/utils/Utils.js'
Makes sure that a HTML id allways has a # at the beginning. If the provided id already has a # then it returns the same id, otherwise it is added.
Params:
Name | Type | Attribute | Description |
id | string | Id of an HTML object. |
public formatValue(val: number | string, units: string, decPlaces: number, fixPlaces: boolean): string source
import {formatValue} from 'newton-lib/src/utils/Utils.js'
Format a number to have a certain number of decimal places and/or fixed places and add a unit label. Used to format the strings of labels and sliders. If the input value is a SYMBOL then return the same symbol.
Params:
Name | Type | Attribute | Description |
val | number | string | Input number. Can also be a string or a symbol such as in SYMBOL. |
|
units | string | Units of the input number. |
|
decPlaces | number | Amount of decimal places to round. |
|
fixPlaces | boolean | Fix the amount of decimal places. If the number doesn't have enough, zeros will be added. |
public gaussian(n: number): number source
import {gaussian} from 'newton-lib/src/utils/Utils.js'
Generate a random number following a gaussian distribuition.
Params:
Name | Type | Attribute | Description |
n | number | Amount of iterations. |
public getPixelRatio(): number source
import {getPixelRatio} from 'newton-lib/src/utils/Utils.js'
Obtains the pixel ratio of the device. Used to scale properly the canvas for high resolution devices.
public isCoordInside(x: number, y: number, bx: number, by: number, bw: number, bh: number): boolean source
import {isCoordInside} from 'newton-lib/src/utils/Utils.js'
Determines if a point is inside of a box. Often used to test is the mouse is over an element.
public isFunction(f: object): boolean source
import {isFunction} from 'newton-lib/src/utils/Utils.js'
Test if an object is a function.
Params:
Name | Type | Attribute | Description |
f | object | Object to test. |
public isObject(o: object): boolean source
import {isObject} from 'newton-lib/src/utils/Utils.js'
Test if an object is an object.
Params:
Name | Type | Attribute | Description |
o | object | Object to test. |
public isString(s: object): boolean source
import {isString} from 'newton-lib/src/utils/Utils.js'
Test if an object is a string.
Params:
Name | Type | Attribute | Description |
s | object | Object to test. |
public loadOptions(obj: object, args: object) source
import {loadOptions} from 'newton-lib/src/utils/Utils.js'
Assign the matching properties from the args object to the obj object. This allows for settings to be passed in single line and set on the receiving object. Almost all World Element objects accept such settings on their constructors.
Example:
loadOptions(font, { face: "Helvetica", size: 12 });
public rad(angle: number, type: number): number source
import {rad} from 'newton-lib/src/utils/Utils.js'
Given an angle makes sure that it is in radians.
Params:
Name | Type | Attribute | Description |
angle | number | Angle to convert to radians. |
|
type | number | Determines if the angle provided is in radians or in degrees. See ANGLE_STYLE. |
public rgbToRgba(color: string, alpha: number): string source
import {rgbToRgba} from 'newton-lib/src/utils/Utils.js'
Adds an alpha channel to an rgb color. Must have the pattern #AABBCC.
public round(value: number, precision: number): number source
import {round} from 'newton-lib/src/utils/Utils.js'
Round a number to a given amount of decimal places.
public sin(val: number, type: number): number source
import {sin} from 'newton-lib/src/utils/Utils.js'
Sine function that can accept angles in radians or degrees.
Params:
Name | Type | Attribute | Description |
val | number | Angle for calculating the sine. |
|
type | number | Determines if the angle provided is in radians or in degrees. See ANGLE_STYLE. |