Class: BoxUtils

Kekule. BoxUtils

new BoxUtils()

Utility methods about geometry box (2D or 3D). Box is a region defined by two coord values.
Source:

Methods

(static) clone(box) → {Hash}

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

(static) convertToRect(box) → {Hash}

Convert a box to a rect defined by left, top, width and height.
Parameters:
Name Type Description
box Hash
Source:
Returns:
Type
Hash

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

Create a box with two coord at top-left and bottom-right.
Parameters:
Name Type Description
coord1 Hash
coord2 Hash
Source:
Returns:
Type
Hash

(static) getCenterCoord(box) → {Hash}

Returns center coord of 2D or 3D box.
Parameters:
Name Type Description
box Hash
Source:
Returns:
Type
Hash

(static) getContainerBox(box1, box2) → {Hash}

Get the smallest big box that contains box1 and box2.
Parameters:
Name Type Description
box1 Hash
box2 Hash
Source:
Returns:
Type
Hash

(static) getCornerCoords(box) → {Array}

To a 2D box, returns four coords of box top-left, top-right, bottom-left and bottom-right. To a 3D box, returns coords of 8 corners.
Parameters:
Name Type Description
box Hash
Source:
Returns:
Array of coords.
Type
Array

(static) getIntersection(box1, box2) → {Hash}

Returns intersection of two boxes.
Parameters:
Name Type Description
box1 Hash
box2 Hash
Source:
Returns:
Type
Hash

(static) getMinMaxCoords(box) → {Hash}

Returns the min and max corner coords of box.
Parameters:
Name Type Description
box Hash
Source:
Returns:
{min: coord, max: coord}
Type
Hash

(static) hasIntersection(box1, box2) → {Bool}

Check if two box has intersection.
Parameters:
Name Type Description
box1 Hash
box2 Hash
Source:
Returns:
Type
Bool

(static) inflateBox(box, inflationX, inflationY) → {Hash}

Inflate the size of box. topleft - inflation and bottomright + inflation. X/Y/Z may have different inflation. If only one inflation value is provided, the box will be use this value on both width and height (and depth).
Parameters:
Name Type Description
box Hash
inflationX Float
inflationY Float
Source:
Returns:
Type
Hash

(static) isEqual(b1, b2) → {Bool}

Check if two boxes are the same.
Parameters:
Name Type Description
b1 Hash
b2 Hash
Source:
Returns:
Type
Bool

(static) isInside(innerBox, outerBox) → {Bool}

Check if innerBox is inside outerBox.
Parameters:
Name Type Description
innerBox Hash
outerBox Hash
Source:
Returns:
Type
Bool

(static) normalize(box) → {Hash}

Normalize the x/y values in box. Some times x1 > x2 or y1 > y2, normalize will ensure x1/y1 is always no larger then x2/y2.
Parameters:
Name Type Description
box Hash
Source:
Returns:
Type
Hash

(static) shiftBox(deltaX, deltaY, deltaZ) → {Hash}

Shift box to a new location.
Parameters:
Name Type Description
deltaX Float
deltaY Float
deltaZ Float
Source:
Returns:
Type
Hash

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

Do a 2d transform to a box. The tranform will be performed in the following order: rotate, scale, translate. Note that there may be rotation in transform, so box may be larger than expected.
Parameters:
Name Type Description
box Hash
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 box after transform.
Type
Hash

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

Do a 3d transform to a box. The tranform will be performed in the following order: rotate, scale, translate.
Parameters:
Name Type Description
box Hash 3D box.
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 center: {x, y, z} (center of rotate and scale).
Source:
Returns:
3D box after transform.
Type
Hash