cpr.geometry.Rectangle
Position and size object consisting of left, top, width, and height.
Index
Name |
Return Type |
Description |
fromDOMRect |
Rectangle |
Returns a new Rectangle from the DOM. |
clientBoundsOf |
Rectangle |
Creates a rectangle pointing to the bounding client bounds from the HTML node's position and size. |
offsetBoundsOf |
Rectangle |
Creates a rectangle that points from the position and size of the HTML node to the state position and size from the parent layout node. |
fromElementBoundsOf |
Rectangle |
Creates a rectangle from the position and size of an HTML node. |
contains |
Boolean |
Returns whether the rectangle contains a given point. |
containsPoint |
Boolean |
Returns whether the specified coordinates are within the bounds of the Rectangle. |
containsRect |
Boolean |
Returns whether the specified coordinates are within the bounds of the Rectangle. |
equals |
Boolean |
Compares with another Rectangle and returns whether they are equal. |
expand |
Rectangle |
Expands the rectangle in all 4 directions by the given value. |
expandByInsets |
Rectangle |
Extends the horizontal and vertical sides of the Rectangle by the width and height of the specified Inset and returns it for convenience. |
getCopy |
Rectangle |
Get a copy of the Rectangle object. |
getDistance |
Number |
Gets the distance from this square to a given point. |
getExpanded |
Rectangle |
Gets a copy of the rectangular object extending in 4 directions. |
getExpandedByInsets |
Rectangle |
Creates and returns a new Rectangle bounded by this Rectangle extended by the specified Inset. |
getIntersection |
Rectangle |
Obtain the intersection square with another rectangle. |
getScaled |
Rectangle |
Reposition and resize this Rectangle at the given scale and return a new Rectangle. |
getShrinked |
Rectangle |
Get a copy of the rectangular object with all 4 directions reduced. |
getShrinkedByInsets |
Rectangle |
Returns a new Rectangle reduced by the specified Insets. |
getTranslated |
Rectangle |
Gets a copy of the square object with the axis shifted. |
getTranslatedByDimension |
Rectangle |
Returns a new Rectangle moved by the specified Dimension's location. |
getTranslatedByPoint |
Rectangle |
Returns a new Rectangle moved by the specified Point's location. |
getTransposed |
Rectangle |
Returns a new rectangle with changed width and height and x and y values. |
getUnion |
Rectangle |
Expand this square to include the given point. |
getUnionWithBounds |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle. |
getUnionWithLocation |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle. |
getUnionWithPoint |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle. |
getUnionWithRect |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle. |
intersect |
Rectangle |
Makes the current Rectangle the Rectangle of the area that intersects another Rectangle. |
intersects |
Boolean |
Returns whether it collides with another box. |
isEmpty |
Boolean |
Returns whether the width of the Rectangle object is negative or zero. |
isZeroBounds |
Boolean |
|
resize |
Rectangle |
Increases or decreases the size of the rectangle by the given size. |
resizeByDimension |
Rectangle |
Resize this Rectangle with the value provided as input and return it for convenience. |
scale |
Rectangle |
Reposition and resize this Rectangle with the given scale and return this for convenience. |
setBounds |
Rectangle |
Override the bounds of the rectangle. |
shrink |
Rectangle |
Reduces the rectangle in all 4 directions by a given amount. |
shrinkByInsets |
Rectangle |
Collapse the rectangle via Insets and return this Rectangle for convenience. |
translate |
Rectangle |
Apply translation to the rectangular coordinate system. |
translateByDimension |
Rectangle |
Move this Rectangle by x,y by the width and height of the Dimension, then return this Rectangle for convenience. |
translateByPoint |
Rectangle |
Moves this Rectangle by x,y of Point and returns this Rectangle for convenience. |
transpose |
Rectangle |
Switches the width and height of this Rectangle as well as the x and y values. |
union |
Rectangle |
Expand this square to include the given point. |
unionWithBounds |
Rectangle |
Update the size of this Rectangle to the smallest size that can contain both this Rectangle and the rectangle (x, y, w, h). |
unionWithLocation |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can contain both this Rectangle and its coordinates (x, y). |
unionWithPoint |
Rectangle |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point. |
unionWithRect |
Rectangle |
Updates the size of this Rectangle to the smallest size that can contain both this Rectangle and the specified Rectangle. |
Constructor
Creates a new rectangle object.
name |
type |
description |
leftoptional
|
Number |
default0
|
x coordinate |
topoptional
|
Number |
default0
|
y coordinate |
widthoptional
|
Number |
default0
|
width |
heightoptional
|
Number |
default0
|
Height |
Properties
type
|
Rectangle |
readonly
|
Returns an empty Rectangle.
|
type
|
Number |
readonly
|
Get the y-coordinate of the bottom edge of the box area.
|
type
|
Point |
readonly
|
x center y bottom
|
type
|
Point |
readonly
|
x left y bottom
|
type
|
Point |
readonly
|
x right y bottom
|
deprecatedDeprecated due to typo.
type
|
Point |
readonly
|
x center y center
|
type
|
Point |
readonly
|
x left y center
|
type
|
Point |
readonly
|
x right y center
|
type
|
Number |
|
Height default 0
|
type
|
Number |
|
Left default 0
|
type
|
Point |
readonly
|
Return the location.
|
type
|
Number |
readonly
|
Get the x coordinate of the right edge of the box area.
|
type
|
Number |
|
Above default 0
|
type
|
Point |
readonly
|
x middle y top
|
type
|
Point |
readonly
|
x left y top
|
type
|
Point |
readonly
|
x right y top
|
type
|
Number |
|
Width default 0
|
type
|
Number |
get
|
Get the X coordinate. Same value as left.
|
set
|
Set the X coordinate.
|
type
|
Number |
get
|
Get the y coordinate. This is the same value as top.
|
set
|
Set the y coordinate.
|
Methods
Returns a new Rectangle from the DOM.
name |
type |
description |
rect
|
DOMRect |
|
Creates a rectangle pointing to the bounding client bounds from the HTML node's position and size.
name |
type |
description |
element
|
HTMLElement |
HTML node. |
return
|
Rectangle |
A rectangle indicating the location and size of the HTML node. |
Creates a rectangle that points from the position and size of the HTML node to the state position and size from the parent layout node.
name |
type |
description |
element
|
HTMLElement |
HTML node. |
return
|
Rectangle |
A rectangle indicating the location and size of the HTML node. |
Creates a rectangle from the position and size of an HTML node.
name |
type |
description |
element
|
HTMLElement |
HTML node. |
coordinateoptional
|
LocationCooridnate |
default"client"
|
The coordinate system to use. Only client and offset are supported. |
return
|
Rectangle |
A rectangle indicating the location and size of the HTML node. |
Returns whether the rectangle contains a given point.
name |
type |
description |
location
|
Point |
Where to check for inclusion. |
Returns whether the rectangle contains the given rectangle.
name |
type |
description |
rect
|
Rectangle |
The rectangle to check for inclusion. |
Returns whether the rectangle contains a given point.
name |
type |
description |
x
|
Number |
The X-coordinate of the location to check for inclusion. |
y
|
Number |
The Y-coordinate of the location to check for inclusion. |
Returns whether the specified coordinates are within the bounds of the Rectangle.
name |
type |
description |
other
|
Point |
|
Returns whether the specified coordinates are within the bounds of the Rectangle.
Compares with another Rectangle and returns whether they are equal.
name |
type |
description |
other
|
Rectangle |
Another Rectangle to compare. |
toleranceoptional
|
Number |
default0
|
tolerance. |
Expands the rectangle in all 4 directions by the given value.
name |
type |
description |
amount
|
Number |
Amount to expand. |
Expand the rectangle.
name |
type |
description |
insets
|
Insets |
Inset information containing the amount to be expanded. |
Expand the rectangle.
name |
type |
description |
h
|
Number |
horizontal extension |
v
|
Number |
vertical extension |
Extends the horizontal and vertical sides of the Rectangle by the width and height of the specified Inset and returns it for convenience.
name |
type |
description |
insets
|
Insets |
|
Get a copy of the Rectangle object.
Gets the distance from this square to a given point.
name |
type |
description |
point
|
Point |
Point to find distance. |
Gets the distance from this square to a given point.
name |
type |
description |
x
|
Number |
The X-coordinate of the point from which to find the distance. |
y
|
Number |
The y-coordinate of the point from which to find the distance. |
Gets a copy of the rectangular object extending in 4 directions.
name |
type |
description |
amount
|
Number |
Amount to expand. |
Get a copy of the expanded rectangle object.
name |
type |
description |
insets
|
Insets |
|
Get a copy of the expanded rectangle object.
name |
type |
description |
h
|
Number |
|
v
|
Number |
|
Creates and returns a new Rectangle bounded by this Rectangle extended by the specified Inset.
name |
type |
description |
insets
|
Insets |
|
Obtain the intersection square with another rectangle.
name |
type |
description |
other
|
Rectangle |
Another rectangle to check for collisions. |
Reposition and resize this Rectangle at the given scale and return a new Rectangle.
name |
type |
description |
xFactor
|
Number |
|
yFactoroptional
|
Number |
defaultundefined
|
|
Get a copy of the rectangular object with all 4 directions reduced.
name |
type |
description |
amount
|
Number |
Amount to shrink |
Get a reduced copy of the rectangle object.
name |
type |
description |
insets
|
Insets |
An inset object containing information about the amount to be reduced. |
Get a reduced copy of the rectangle object.
name |
type |
description |
h
|
Number |
horizontal reduction. |
v
|
Number |
vertical reduction. |
Returns a new Rectangle reduced by the specified Insets.
name |
type |
description |
insets
|
Insets |
|
Gets a copy of the square object with the axis shifted.
name |
type |
description |
dx
|
Number |
x-axis travel amount. |
dy
|
Number |
y-axis travel amount. |
Gets a copy of the square object with the axis shifted.
name |
type |
description |
p
|
Point |
A Point object containing information on the amount of movement along the x and y axes. |
Gets a copy of the square object with the axis shifted.
name |
type |
description |
dimension
|
Dimension |
A Dimension object containing axis movement information. |
Returns a new Rectangle moved by the specified Dimension's location.
Returns a new Rectangle moved by the specified Point's location.
name |
type |
description |
d
|
Point |
|
Returns a new rectangle with changed width and height and x and y values.
Expand this square to include the given point.
name |
type |
description |
location
|
Point |
Points to include. |
Expand this square to include the given point.
name |
type |
description |
x
|
Number |
The x-coordinate of the point to include. |
y
|
Number |
The y-coordinate of the point to include. |
Expands this rectangle to a size that contains the given rectangle.
name |
type |
description |
r
|
Rectangle |
squares to include. |
Expands this rectangle to a size that contains the given rectangle.
name |
type |
description |
x
|
Number |
The x-coordinate of the rectangle to include. |
y
|
Number |
The y-coordinate of the rectangle to include. |
width
|
Number |
The width of the rectangle to include. |
height
|
Number |
The height of the rectangle to include. |
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle.
name |
type |
description |
x
|
Number |
|
y
|
Number |
|
width
|
Number |
|
height
|
Number |
|
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle.
name |
type |
description |
x
|
Number |
|
y
|
Number |
|
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle.
name |
type |
description |
p
|
Point |
|
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point and return a new Reactangle.
Makes the current Rectangle the Rectangle of the area that intersects another Rectangle.
name |
type |
description |
other
|
Rectangle |
Another Rectangle object to intersect. |
Returns whether it collides with another box.
name |
type |
description |
other
|
Rectangle |
Rectangle to check for collisions. |
Returns whether the width of the Rectangle object is negative or zero.
Increases or decreases the size of the rectangle by the given size.
name |
type |
description |
sizeDelta
|
Point |
Size to increase or decrease. |
Increases or decreases the size of the rectangle by the given size.
name |
type |
description |
sizeDelta
|
Dimension |
Size to increase or decrease. |
Increases or decreases the size of the rectangle by the given size.
name |
type |
description |
widthDelta
|
Number |
width change. |
heightDelta
|
Number |
height change. |
Resize this Rectangle with the value provided as input and return it for convenience.
Reposition and resize this Rectangle with the given scale and return this for convenience.
name |
type |
description |
xFactor
|
Number |
|
yFactoroptional
|
Number |
defaultundefined
|
|
Override the bounds of the rectangle.
name |
type |
description |
x
|
Number |
x coordinate. |
y
|
Number |
y coordinate. |
width
|
Number |
width. |
height
|
Number |
Height. |
Reduces the rectangle in all 4 directions by a given amount.
name |
type |
description |
amount
|
Number |
Amount to shrink. |
Reduce the rectangle.
name |
type |
description |
insets
|
Insets |
An inset containing the information to be reduced. |
Reduce the rectangle.
name |
type |
description |
h
|
Number |
horizontal reduction |
v
|
Number |
vertical reduction |
Collapse the rectangle via Insets and return this Rectangle for convenience.
name |
type |
description |
insets
|
Insets |
|
Apply translation to the rectangular coordinate system.
name |
type |
description |
dx
|
Number |
x-axis travel amount. |
dy
|
Number |
y-axis travel amount. |
Apply translation to the rectangular coordinate system.
name |
type |
description |
p
|
Point |
A Point object containing information on the amount of movement along the x and y axes. |
Apply translation to the rectangular coordinate system.
name |
type |
description |
dimension
|
Dimension |
A Dimension object containing axis movement information. |
Move this Rectangle by x,y by the width and height of the Dimension, then return this Rectangle for convenience.
Moves this Rectangle by x,y of Point and returns this Rectangle for convenience.
name |
type |
description |
d
|
Point |
|
Switches the width and height of this Rectangle as well as the x and y values.
Expand this square to include the given point.
name |
type |
description |
location
|
Point |
Points to include. |
Expand this square to include the given point.
name |
type |
description |
x
|
Number |
The x-coordinate of the point to include. |
y
|
Number |
The y-coordinate of the point to include. |
Expands this rectangle to a size that contains the given rectangle.
name |
type |
description |
r
|
Rectangle |
squares to include. |
Expands this rectangle to a size that contains the given rectangle.
name |
type |
description |
x
|
Number |
The x-coordinate of the rectangle to include. |
y
|
Number |
The y-coordinate of the rectangle to include. |
width
|
Number |
The width of the rectangle to include. |
height
|
Number |
The height of the rectangle to include. |
deprecatedPlease use union.
Update the size of this Rectangle to the smallest size that can contain both this Rectangle and the rectangle (x, y, w, h).
name |
type |
description |
x
|
Number |
|
y
|
Number |
|
width
|
Number |
|
height
|
Number |
|
deprecatedPlease use union.
Updates the bounds of this Rectangle to the smallest size that can contain both this Rectangle and its coordinates (x, y).
name |
type |
description |
x
|
Number |
|
y
|
Number |
|
deprecatedPlease use union.
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point.
name |
type |
description |
p
|
Point |
|
deprecatedPlease use union.
Updates the size of this Rectangle to the smallest size that can contain both this Rectangle and the specified Rectangle.