Class: CoordUtils

Kekule. CoordUtils

new CoordUtils()

Utility methods about coordinates (2D or 3D).
Source:

Methods

(static) absValue(coord) → {Hash}

Returns the absolute value of each coord axises.
Parameters:
Name Type Description
coord Hash
Source:
Returns:
Type
Hash

(static) add(coord1, coord2) → {Hash}

Add value of two coordinates.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Hash

(static) calcCoordGroup2DTransformParams(targetCoord1, targetCoord2, destCoord1, destCoord2) → {Hash}

Returns suitable 2D transform params that can transform a line between targetCoord1/targetCoord2 to destCoord1, destCoord2.
Parameters:
Name Type Description
targetCoord1 Hash
targetCoord2 Hash
destCoord1 Hash
destCoord2 Hash
Source:
Returns:
Type
Hash

(static) calcInverseTransform2DMatrix(options) → {Array}

Calculate inversed transform matrix of options.
Parameters:
Name Type Description
options Hash
Source:
Returns:
Type
Array

(static) calcInverseTransform3DMatrix(options) → {Array}

Calculate inversed transform matrix of options.
Parameters:
Name Type Description
options Hash
Source:
Returns:
Type
Array

(static) calcRotate3DMatrix(options) → {Array}

Calculate 3D rotation matrix from options.
Parameters:
Name Type Description
options Object Rotation options, can has the following fields: rotateX, rotateY, rotateZ, // if Y is set, Z will be ignored; if X is set, Y/Z will be ignored rotateAngle, rotateAxisVector // rotate around a vector start from center or zero point, if this value is set, rotateX-Z will be ignored rotateMatrix // use matrix to rotate directly center: {x, y, z} (center of rotate).
Source:
Returns:
A 4X4 matrix.
Type
Array

(static) calcTransform2DMatrix(options) → {Array}

Calculate the 2D transfrom matrix. The tranform will be performed in the following order: rotate, scale, translate.
Parameters:
Name Type Description
options Hash Transform options, can has the following fields: scale, scaleX, scaleY translateX, translateY, rotateAngle, center: {x, y} (center of rotate and scale).
Source:
Returns:
A 4X4 matrix.
Type
Array

(static) calcTransform3DMatrix(options) → {Array}

Calculate the 3D transfrom matrix. The tranform will be performed in the following order: rotate, scale, translate.
Parameters:
Name Type Description
options Object Transform options, can has the following fields: scale, scaleX, scaleY, scaleZ, // all scale from center or zero point translateX, translateY, translateZ, rotateX, rotateY, rotateZ, // if Y is set, Z will be ignored; if X is set, Y/Z will be ignored rotateAngle, rotateAxisVector // rotate around a vector start from center or zero point, if this value is set, rotateX-Z will be ignored rotateMatrix // use matrix to rotate directly center: {x, y, z} (center of rotate and scale).
Source:
Returns:
A 4X4 matrix.
Type
Array

(static) clone(coord) → {Hash}

Clone a coord.
Parameters:
Name Type Description
coord Hash
Source:
Returns:
Type
Hash

(static) create() → {Hash}

Create a coordinate object by params. If two params provided, a 2D (x/y) coordinate will be created, else 3D (x/y/z) one will be created.
Source:
Returns:
Type
Hash

(static) divide(coord, value) → {Hash}

Coord / value.
Parameters:
Name Type Description
coord Hash
value Num
Source:
Returns:
Type
Hash

(static) getCenter(coords) → {Hash}

Calculate center coord of a set of coords.
Parameters:
Name Type Description
coords Array
Source:
Returns:
Type
Hash

(static) getContainerBox(coords) → {Hash}

Returns a minial box that contains all coords.
Parameters:
Name Type Description
coords Array Array of coords.
Source:
Returns:
Type
Hash

(static) getDistance(coord1, coord2) → {Float}

Get distance between two coords. If coord2 is not set, this function will calc distance between coord1 and zero point.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Float

(static) insideRect(coord, rectCoord1, rectCoord2) → {Bool}

Check if coord inside 2D rect.
Parameters:
Name Type Description
coord Object
rectCoord1 Object
rectCoord2 Object
Deprecated:
  • Yes
Source:
Returns:
Type
Bool

(static) inverseTransform2D(coord, options) → {Hash}

Do a reversed 2d transform to a coord.
Parameters:
Name Type Description
coord Hash 2D coordinate.
options Hash Transform options, can has the following fields: scale, scaleX, scaleY translateX, translateY, rotateAngle, center: {x, y} (center of rotate and scale).
Source:
Returns:
2D coord after reversed transform.
Type
Hash

(static) is3D(coord) → {Bool}

Check if the coord is a 3D one (has z value)
Parameters:
Name Type Description
coord Object
Source:
Returns:
Type
Bool

(static) isEqual(coord1, coord2) → {Bool}

Check if two coords are same.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Bool

(static) isInsideBox(coord, box) → {Bool}

Check if coord is inside a box.
Parameters:
Name Type Description
coord Hash
box Hash
Source:
Returns:
Type
Bool

(static) isZero(coord, allowedError) → {Bool}

Check if a coord is a zero one (x/y/z all equals to 0).
Parameters:
Name Type Description
coord Hash
allowedError Float
Source:
Returns:
Type
Bool

(static) multiply(coord, value) → {Hash}

Coord * value.
Parameters:
Name Type Description
coord Hash
value Num
Source:
Returns:
Type
Hash

(static) standardize(coord) → {Hash}

Standardize coord to a length 1 vector.
Parameters:
Name Type Description
coord Hash
Source:
Returns:
Type
Hash

(static) substract(coord1, coord2) → {Hash}

Substract values of two coordinates, coord1 - coord2.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Hash

(static) toArray(coord) → {Array}

Convert coord to a 2D or 3D array of values
Parameters:
Name Type Description
coord Hash
Source:
Returns:
Type
Array

(static) transform2D(coord, options) → {Hash}

Do a 2d transform to a coord. The tranform will be performed in the following order: rotate, scale, translate.
Parameters:
Name Type Description
coord Hash 2D coordinate.
options Hash Transform options, can has the following fields: scale, scaleX, scaleY translateX, translateY, rotateAngle, center: {x, y} (center of rotate and scale).
Source:
Returns:
2D coord after transform.
Type
Hash

(static) transform2DByMatrix(coord, transformMatrix)

Do a 2D transform to a coord by a transformer matrix.
Parameters:
Name Type Description
coord Hash
transformMatrix Array A 3X3 matrix.
Source:

(static) transform3D(coord, options) → {Hash}

Do a 3d transform to a coord. The tranform will be performed in the following order: rotate, scale, translate.
Parameters:
Name Type Description
coord Hash 3D coordinate.
options Hash Transform options, can has the following fields: scale, scaleX, scaleY, scaleZ, // all scale from center or zero point translateX, translateY, translateZ, rotateX, rotateY, rotateZ, rotateAngle, rotateAxisVector // rotate around a vector start from center or zero point rotateMatrix // use matrix to rotate directly center: {x, y, z} (center of rotate and scale).
Source:
Returns:
3D coord after transform.
Type
Hash

(static) transform3DByMatrix(coord, transformMatrix)

Do a 3d transform to a coord by a transformer matrix.
Parameters:
Name Type Description
coord Hash
transformMatrix Array A 4X4 matrix.
Source: