Module: mutils

Maths utility methods.
Source:

Methods

(static) angleDegsBetweenPoints(originPoint, destinationPoint) → {number}

Returns the angle in degrees between 2 points.
Parameters:
Name Type Description
originPoint vector An object with `x` and `y` properties.
destinationPoint vector An object with `x` and `y` properties.
Source:
Returns:
angleDegrees - The angle in degrees.
Type
number

(static) angleRadsBetweenPoints(originPoint, destinationPoint) → {number}

Returns the angle in radians between 2 points.
Parameters:
Name Type Description
originPoint vector An object with `x` and `y` properties.
destinationPoint vector An object with `x` and `y` properties.
Source:
Returns:
angleRadians - The angle in radians.
Type
number

(static) angularDeltaFromAnglesDeg(sourceAngleDegrees, targetAngleDegrees) → {number}

Return the shortest angular offset (in degrees) from a source angle (in degrees) to a target angle (in degrees).
The result may be negative.
Parameters:
Name Type Description
sourceAngleDegrees number The source angle in degrees.
targetAngleDegrees number The target angle in degrees.
Source:
Returns:
offsetAngleDegrees - The offset in degrees.
Type
number

(static) angularDeltaFromAnglesForceDirDeg(sourceAngleDegrees, targetAngleDegrees, direction) → {number}

Return the shortest angular offset (in degrees) in the given direction of travel from a source angle (in degrees) to a target angle (in degrees).
The result may be negative.
Parameters:
Name Type Description
sourceAngleDegrees number The source angle in degrees.
targetAngleDegrees number The target angle in degrees.
direction number The direction (under 0 for CCW, over 0 for CW)
Source:
Returns:
offsetAngleDegrees - The offset in degrees.
Type
number

(static) angularDeltaFromAnglesRad(sourceAngleRadians, targetAngleRadians) → {number}

Return the shortest angular offset (in radians) from a source angle (in radians) to a target angle (in radians).
The result may be negative.
Parameters:
Name Type Description
sourceAngleRadians number The source angle in radians.
targetAngleRadians number The target angle in radians.
Source:
Returns:
offsetAngleRadians - The offset in radians.
Type
number

(static) clamp01(value) → {number}

Restricts a given value between 0 and 1 (inclusive).
Parameters:
Name Type Description
value number
Source:
Returns:
restrictedValue
Type
number

(static) clampNeg1Pos1(value) → {number}

Restricts a given value between -1 and 1 (inclusive).
Parameters:
Name Type Description
value number
Source:
Returns:
restrictedValue
Type
number

(static) containScale(sourceWidth, sourceHeight, boundsWidth, boundsHeight) → {number}

Returns the scale needed to contain the source dimensions exactly within the given bounds while maintaining aspect ratio.
Parameters:
Name Type Description
sourceWidth number The source width.
sourceHeight number The source height.
boundsWidth number The bounds width.
boundsHeight number The bounds height.
Source:
Returns:
scale - The resulting scale.
Type
number

(static) coverScale(sourceWidth, sourceHeight, boundsWidth, boundsHeight) → {number}

Given source dimensions, returns the scale needed to completely cover the given bounds while maintaining aspect ratio.
Parameters:
Name Type Description
sourceWidth number The source width.
sourceHeight number The source height.
boundsWidth number The bounds width.
boundsHeight number The bounds height.
Source:
Returns:
scale - The resulting scale.
Type
number

(static) degToRad(angleDegrees) → {number}

Converts angle from degrees to radians.
Parameters:
Name Type Description
angleDegrees number Angle in degrees.
Source:
Returns:
angleRadians - Angle in radians.
Type
number

(static) distanceBetweenPoints(pointA, pointB) → {number}

Returns the distance between 2 vector points.
Parameters:
Name Type Description
pointA vector An object with `x` and `y` properties.
pointB vector An object with `x` and `y` properties.
Source:
Returns:
distance
Type
number

(static) ellipsePerimeter(radiusX, radiusY) → {number}

Calculates the perimter (circumference) of an ellipse.
Parameters:
Name Type Description
radiusX number The ellipse radius in the x axis.
radiusY number The ellipse radius in the y axis.
Source:
Returns:
perimeter - Will return the perimeter length of the ellipse.
Type
number

(static) indexOffsetInDirection(indexFrom, indexTo, dir, totalCount) → {int}

Given indexes that repeat from 0 to `totalCount`-1, return the offset from one to another in a set direction, negative or positive.
Parameters:
Name Type Description
indexFrom number The starting index. Must be positive integer under `totalCount`.
indexTo number The target index. Must be positive integer under `totalCount`.
dir number A number over or under zero. If dir is over 0 the resulting offset will be over zero and visa-versa.
totalCount count The total number of indexes. Eg. The array length.
Source:
Returns:
indexOffset - The offset between indexes.
Type
int

(static) intersectionPtsBetweenCircleAndLineSeg(segmentPoint0, segmentPoint1, circleCenter, circleRadius) → {Array.<Vector>}

Returns an array of intersection points (with length between 0 and 2) between a circle and line segment.
Parameters:
Name Type Description
segmentPoint0 vector An object with `x` and `y` properties.
segmentPoint1 vector An object with `x` and `y` properties.
circleCenter vector An object with `x` and `y` properties.
circleRadius number
Source:
Returns:
intersectionPoints - Will return a list of intersection points, between 0 and 2.
Type
Array.<Vector>

(static) intersectionPtsBetweenCircles(circleCenter0, circleRadius0, circleCenter1, circleRadius1) → {Array.<Vector>}

Returns an array of intersection points (with length between 0 and 2) between 2 circles.
Parameters:
Name Type Description
circleCenter0 vector An object with `x` and `y` properties.
circleRadius0 number
circleCenter1 vector An object with `x` and `y` properties.
circleRadius1 number
Source:
Returns:
intersectionPoints - Will return a list of intersection points, between 0 and 2.
Type
Array.<Vector>

(static) intersectLineLine(lineApoint0, lineApoint1, lineBpoint0, lineBpoint1) → {PIXI.Point|null}

Returns the intersection point between two infinite length lines.
Parameters:
Name Type Description
lineApoint0 vector An object with `x` and `y` properties.
lineApoint1 vector An object with `x` and `y` properties.
lineBpoint0 vector An object with `x` and `y` properties.
lineBpoint1 vector An object with `x` and `y` properties.
Source:
Returns:
intersectionPoint - Will return null if lines don't intersect.
Type
PIXI.Point | null

(static) intersectRayRay(lineAorigin, lineAtarget, lineBorigin, lineBtarget) → {PIXI.Point|null}

Returns the intersection point between two rays.
A ray is an infinite line from origin point through the target point.
Parameters:
Name Type Description
lineAorigin vector An object with `x` and `y` properties.
lineAtarget vector An object with `x` and `y` properties.
lineBorigin vector An object with `x` and `y` properties.
lineBtarget vector An object with `x` and `y` properties.
Source:
Returns:
intersectionPoint - Will return null if the rays don't intersect.
Type
PIXI.Point | null

(static) intersectSegmentSegment(lineApoint0, lineApoint1, lineBpoint0, lineBpoint1) → {PIXI.Point|null}

Returns the intersection point between two closed lines.
Parameters:
Name Type Description
lineApoint0 vector An object with `x` and `y` properties.
lineApoint1 vector An object with `x` and `y` properties.
lineBpoint0 vector An object with `x` and `y` properties.
lineBpoint1 vector An object with `x` and `y` properties.
Source:
Returns:
intersectionPoint - Will return null if segments don't intersect.
Type
PIXI.Point | null

(static) projectDistance(originPoint, targetPoint, distance) → {PIXI.Point}

Returns the point projecting from one point to another at a set distance.
Parameters:
Name Type Description
originPoint vector An object with `x` and `y` properties.
targetPoint vector An object with `x` and `y` properties.
distance number The distance to project.
Source:
Returns:
projectedPoint - A new point object.
Type
PIXI.Point

(static) projectFromPointDeg(originPoint, angleDegrees, distance) → {PIXI.Point}

Projects from a point at a given degree angle and distance.
Parameters:
Name Type Description
originPoint vector An object with `x` and `y` properties.
angleDegrees number The rotation angle, in degrees.
distance number The distance to project.
Source:
Returns:
projectedPoint - A new point object.
Type
PIXI.Point

(static) projectFromPointRad(originPoint, angleRadians, distance) → {PIXI.Point}

Projects from a point at a given radian angle and distance.
Parameters:
Name Type Description
originPoint vector An object with `x` and `y` properties.
angleRadians number The rotation angle, in radians.
distance number The distance to project.
Source:
Returns:
projectedPoint - A new point object.
Type
PIXI.Point

(static) radToDeg(angleRadians) → {number}

Converts angle from radians to degrees.
Parameters:
Name Type Description
angleRadians number Angle in radians.
Source:
Returns:
angleDegrees - Angle in degrees.
Type
number

(static) randFloatNegOneToOne() → {number}

Return a random number between -1.0 and 1.0.
Source:
Returns:
randomNumber
Type
number

(static) random1PlusMinus() → {number}

Return either 1.0 or -1.0 at random.
Source:
Returns:
randomNumber
Type
number

(static) rotatePtAroundPtDeg(centerPoint, subjectPoint, angleDegrees, overwrite) → {PIXI.Point|null}

Rotates one point around another a given angle (in degrees)
Parameters:
Name Type Description
centerPoint vector An object with `x` and `y` properties.
subjectPoint vector An object with `x` and `y` properties.
angleDegrees number The rotation angle, in degrees.
overwrite boolean If true: `subjectPoint` will be updated with the result. If false: a new PIXI.Point object will be returned.
Source:
Returns:
result - The resulting coordinate.
Type
PIXI.Point | null

(static) rotatePtAroundPtRad(centerPoint, subjectPoint, angleRadians, overwrite) → {PIXI.Point|null}

Rotates one point around another a given angle (in radians)
Parameters:
Name Type Description
centerPoint vector An object with `x` and `y` properties.
subjectPoint vector An object with `x` and `y` properties.
angleRadians number The rotation angle, in radians.
overwrite boolean If true: `subjectPoint` will be updated with the result. If false: a new PIXI.Point object will be returned.
Source:
Returns:
result - The resulting coordinate.
Type
PIXI.Point | null

(static) roundToNearest(number, step, offsetopt) → {number}

Rounds a number to nearest step, supporting optional starting offset.
Parameters:
Name Type Attributes Default Description
number number The target number.
step number The step to round to.
offset number <optional>
0 Optional starting offset.
Source:
Returns:
roundedResult
Type
number

(static) shortestIndexOffset(indexFrom, indexTo, totalCount) → {int}

Given indexes that repeat from 0 to `totalCount`-1, return the shortest offset from one to another in any direction.
Parameters:
Name Type Description
indexFrom number The starting index. Must be positive integer under `totalCount`.
indexTo number The target index. Must be positive integer under `totalCount`.
totalCount count The total number of indexes. Eg. The array length.
Source:
Returns:
indexOffset - The offset between indexes. Result may be negative.
Type
int