Module: decks/utils/rect

decks/utils/rect

Utility module for dealing with rectangles.
Source:

Methods

<static> distance(point1, point2) → {number}

Calculates the distance between two points. Points can be expressed with top and left values, or x and y values.
Parameters:
Name Type Description
point1 Object first point
point2 Object second point
Source:
Returns:
- the distance between the points
Type
number

<static> getElementRect(element) → {Object}

Gets a bounding client rect for an element, with respect to the document coordinate system (not the window coordinate system).
Parameters:
Name Type Description
element HTMLElement the element for which to find the rect
Source:
Returns:
- the calculated rect, with respect to the document coordinate system
Type
Object

<static> intersects(r1, r2) → {boolean}

Indicates whether rectangle r1 intersects rectangle r2
Parameters:
Name Type Description
r1 * first rectangle
r2 * second rectangle
Source:
Returns:
true if r1 intersects r2, otherwise false
Type
boolean

<static> isEmpty(r) → {undefined}

Indicates if the rect is empty (null, undefined, or or has all values equal to 0)
Parameters:
Name Type Description
r
Source:
Returns:
Type
undefined

<static> isEqual(r1, r2) → {undefined}

Indicates if two rects are equal in all dimensions/values.
Parameters:
Name Type Description
r1
r2
Source:
Returns:
Type
undefined

<static> move(r, x, y) → {Object}

Moves a rect by adding the specified x and y values to left and top. The width and height are not changed, but the right and bottom values are changed based on the new left/top and current width/height. This does not change width and height;
Parameters:
Name Type Argument Default Description
r Object rectangle-like object
x number <optional>
<nullable>
0 delta value for left
y number <optional>
<nullable>
0 delta value for top
Source:
Returns:
- resulting normalized rectangle object
Type
Object

<static> moveTo(r, x, y) → {undefined}

Moves a rect to an absolute x and y location.
Parameters:
Name Type Description
r
x
y
Source:
Returns:
Type
undefined

<static> moveToX(r, x) → {undefined}

Moves a rect to an absolute x location.
Parameters:
Name Type Description
r
x
Source:
Returns:
Type
undefined

<static> moveToY(r, y) → {undefined}

Moves a rect to an absolute y location.
Parameters:
Name Type Description
r
y
Source:
Returns:
Type
undefined

<static> moveX(r, deltaX) → {undefined}

Moves a rect by a delta x value.
Parameters:
Name Type Description
r
deltaX
Source:
Returns:
Type
undefined

<static> moveY(r, deltaY) → {undefined}

Moves a rect by a delta y value.
Parameters:
Name Type Description
r
deltaY
Source:
Returns:
Type
undefined

<static> normalize(r) → {undefined}

Normalizes an object that has top, bottom, left, and right properties, to a plain object with top, bottom, left, right, width, and height properties.
Parameters:
Name Type Description
r * object that has top, bottom, left, right properties. If r is an Element, r will be the result of r.getBoundingClientRect()
Source:
Returns:
Type
undefined

<static> resize(r, width, height) → {Object}

Resizes a rect by adding the specified width and height values, and adjusting the right and bottom dimensions, based on the current top/left and new width/height. Use negative width and height to shrink the rect. This does not change top and left.
Parameters:
Name Type Argument Default Description
r Object rectangle-like object
width number <optional>
<nullable>
0 delta value for width
height number <optional>
<nullable>
0 delta value for height
Source:
Returns:
resulting normalized rectangle object
Type
Object

<static> resizeHeight(r, deltaHeight) → {undefined}

Resizes a rect with a delta height (changes height and bottom)
Parameters:
Name Type Description
r
deltaHeight
Source:
Returns:
Type
undefined

<static> resizeTo(r, width, height) → {undefined}

Resizes a rect to an absolute width and height (not delta values)
Parameters:
Name Type Description
r
width
height
Source:
Returns:
Type
undefined

<static> resizeToHeight(r, height) → {undefined}

Resizes to rect to an absolute height (not delta value)
Parameters:
Name Type Description
r
height
Source:
Returns:
Type
undefined

<static> resizeToWidth(r, width) → {undefined}

Resizes a rect to an absolute width (not delta value)
Parameters:
Name Type Description
r
width
Source:
Returns:
Type
undefined

<static> resizeWidth(r, deltaWidth) → {undefined}

Resizes a rect with a delta width (changes width and right)
Parameters:
Name Type Description
r
deltaWidth
Source:
Returns:
Type
undefined

<static> union(r1, r2) → {*}

Returns a new rectangle which is the union of rectangles r1 and r2
Parameters:
Name Type Description
r1 * rectangle 1
r2 * rectangle 2
Source:
Returns:
New rectangle that is the union of r1 and r2
Type
*

<static> unionAll(rects) → {*}

Returns a new rectangle which is the union of all the given rectangles
Parameters:
Name Type Description
rects Array
Source:
Returns:
New rectangle
Type
*