cpr.geometry.Rectangle

Position and size object consisting of left, top, width, and height.

Index

Properties
Name Type Description
EMPTY Rectangle Returns an empty Rectangle.
bottom Number Get the y-coordinate of the bottom edge of the box area.
bottomCenter Point x center y bottom
bottomLeft Point x left y bottom
bottomRight Point x right y bottom
bottonLeft Point
center Point x center y center
centerLeft Point x left y center
centerRight Point x right y center
height Number Height default 0
left Number Left default 0
location Point Return the location.
right Number Get the x coordinate of the right edge of the box area.
size Dimension Returns the size.
top Number Above default 0
topCenter Point x middle y top
topLeft Point x left y top
topRight Point x right y top
width Number Width default 0
x Number Get the X coordinate.
y Number Get the y coordinate.
Methods
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

Rectangle(left, top, width, height)
Creates a new rectangle object.
Parameters
name type description
leftoptional Number default0 x coordinate
topoptional Number default0 y coordinate
widthoptional Number default0 width
heightoptional Number default0 Height

Properties

EMPTY
type Rectangle
readonly
Returns an empty Rectangle.
bottom
type Number
readonly
Get the y-coordinate of the bottom edge of the box area.
bottomCenter
type Point
readonly
x center y bottom
bottomLeft
type Point
readonly
x left y bottom
bottomRight
type Point
readonly
x right y bottom
bottonLeft
deprecatedDeprecated due to typo.
type Point
center
type Point
readonly
x center y center
centerLeft
type Point
readonly
x left y center
centerRight
type Point
readonly
x right y center
height
type Number
Height default 0
left
type Number
Left default 0
location
type Point
readonly
Return the location.
right
type Number
readonly
Get the x coordinate of the right edge of the box area.
size
type Dimension
readonly
Returns the size.
top
type Number
Above default 0
topCenter
type Point
readonly
x middle y top
topLeft
type Point
readonly
x left y top
topRight
type Point
readonly
x right y top
width
type Number
Width default 0
x
type Number
get
Get the X coordinate. Same value as left.
set
Set the X coordinate.
y
type Number
get
Get the y coordinate. This is the same value as top.
set
Set the y coordinate.

Methods

fromDOMRect(rect)
Returns a new Rectangle from the DOM.
Parameters
name type description
rect DOMRect
return Rectangle
clientBoundsOf(element)
Creates a rectangle pointing to the bounding client bounds from the HTML node's position and size.
Parameters
name type description
element HTMLElement HTML node.
return Rectangle A rectangle indicating the location and size of the HTML node.
offsetBoundsOf(element)
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.
Parameters
name type description
element HTMLElement HTML node.
return Rectangle A rectangle indicating the location and size of the HTML node.
fromElementBoundsOf(element, coordinate)
Creates a rectangle from the position and size of an HTML node.
Parameters
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.
contains(location)
Returns whether the rectangle contains a given point.
Parameters
name type description
location Point Where to check for inclusion.
return Boolean
contains(rect)
Returns whether the rectangle contains the given rectangle.
Parameters
name type description
rect Rectangle The rectangle to check for inclusion.
return Boolean
contains(x, y)
Returns whether the rectangle contains a given point.
Parameters
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.
return Boolean
containsPoint(other)
deprecatedPlease use contains.
Returns whether the specified coordinates are within the bounds of the Rectangle.
Parameters
name type description
other Point
return Boolean
containsRect(other)
deprecatedPlease use contains.
Returns whether the specified coordinates are within the bounds of the Rectangle.
Parameters
name type description
other Rectangle
return Boolean
equals(other, tolerance)
Compares with another Rectangle and returns whether they are equal.
Parameters
name type description
other Rectangle Another Rectangle to compare.
toleranceoptional Number default0 tolerance.
return Boolean
expand(amount)
Expands the rectangle in all 4 directions by the given value.
Parameters
name type description
amount Number Amount to expand.
return Rectangle
expand(insets)
Expand the rectangle.
Parameters
name type description
insets Insets Inset information containing the amount to be expanded.
return Rectangle
expand(h, v)
Expand the rectangle.
Parameters
name type description
h Number horizontal extension
v Number vertical extension
return Rectangle
expandByInsets(insets)
deprecatedPlease use expand.
Extends the horizontal and vertical sides of the Rectangle by the width and height of the specified Inset and returns it for convenience.
Parameters
name type description
insets Insets
return Rectangle
getCopy()
Get a copy of the Rectangle object.
return Rectangle
getDistance(point)
Gets the distance from this square to a given point.
Parameters
name type description
point Point Point to find distance.
return Number
getDistance(x, y)
Gets the distance from this square to a given point.
Parameters
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.
return Number
getExpanded(amount)
Gets a copy of the rectangular object extending in 4 directions.
Parameters
name type description
amount Number Amount to expand.
return Rectangle
getExpanded(insets)
Get a copy of the expanded rectangle object.
Parameters
name type description
insets Insets
return Rectangle
getExpanded(h, v)
Get a copy of the expanded rectangle object.
Parameters
name type description
h Number
v Number
return Rectangle
getExpandedByInsets(insets)
deprecatedPlease use getExpanded.
Creates and returns a new Rectangle bounded by this Rectangle extended by the specified Inset.
Parameters
name type description
insets Insets
return Rectangle
getIntersection(other)
Obtain the intersection square with another rectangle.
Parameters
name type description
other Rectangle Another rectangle to check for collisions.
return Rectangle
getScaled(xFactor, yFactor)
Reposition and resize this Rectangle at the given scale and return a new Rectangle.
Parameters
name type description
xFactor Number
yFactoroptional Number defaultundefined
return Rectangle
getShrinked(amount)
Get a copy of the rectangular object with all 4 directions reduced.
Parameters
name type description
amount Number Amount to shrink
return Rectangle
getShrinked(insets)
Get a reduced copy of the rectangle object.
Parameters
name type description
insets Insets An inset object containing information about the amount to be reduced.
return Rectangle
getShrinked(h, v)
Get a reduced copy of the rectangle object.
Parameters
name type description
h Number horizontal reduction.
v Number vertical reduction.
return Rectangle
getShrinkedByInsets(insets)
deprecatedPlease use getShrinked.
Returns a new Rectangle reduced by the specified Insets.
Parameters
name type description
insets Insets
return Rectangle
getTranslated(dx, dy)
Gets a copy of the square object with the axis shifted.
Parameters
name type description
dx Number x-axis travel amount.
dy Number y-axis travel amount.
return Rectangle
getTranslated(p)
Gets a copy of the square object with the axis shifted.
Parameters
name type description
p Point A Point object containing information on the amount of movement along the x and y axes.
return Rectangle
getTranslated(dimension)
Gets a copy of the square object with the axis shifted.
Parameters
name type description
dimension Dimension A Dimension object containing axis movement information.
return Rectangle
getTranslatedByDimension(d)
deprecatedPlease use getTranslated.
Returns a new Rectangle moved by the specified Dimension's location.
Parameters
name type description
d Dimension
return Rectangle
getTranslatedByPoint(d)
deprecatedPlease use getTranslated.
Returns a new Rectangle moved by the specified Point's location.
Parameters
name type description
d Point
return Rectangle
getTransposed()
Returns a new rectangle with changed width and height and x and y values.
return Rectangle
getUnion(location)
Expand this square to include the given point.
Parameters
name type description
location Point Points to include.
return Rectangle
getUnion(x, y)
Expand this square to include the given point.
Parameters
name type description
x Number The x-coordinate of the point to include.
y Number The y-coordinate of the point to include.
return Rectangle
getUnion(r)
Expands this rectangle to a size that contains the given rectangle.
Parameters
name type description
r Rectangle squares to include.
return Rectangle
getUnion(x, y, width, height)
Expands this rectangle to a size that contains the given rectangle.
Parameters
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.
return Rectangle
getUnionWithBounds(x, y, width, height)
deprecatedPlease use getUnion.
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.
Parameters
name type description
x Number
y Number
width Number
height Number
return Rectangle
getUnionWithLocation(x, y)
deprecatedPlease use getUnion.
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.
Parameters
name type description
x Number
y Number
return Rectangle
getUnionWithPoint(p)
deprecatedPlease use getUnion.
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.
Parameters
name type description
p Point
return Rectangle
getUnionWithRect(r)
deprecatedPlease use getUnion.
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.
Parameters
name type description
r Rectangle
return Rectangle
intersect(other)
Makes the current Rectangle the Rectangle of the area that intersects another Rectangle.
Parameters
name type description
other Rectangle Another Rectangle object to intersect.
return Rectangle
intersects(other)
Returns whether it collides with another box.
Parameters
name type description
other Rectangle Rectangle to check for collisions.
return Boolean
isEmpty()
Returns whether the width of the Rectangle object is negative or zero.
return Boolean
isZeroBounds()
return Boolean
resize(sizeDelta)
Increases or decreases the size of the rectangle by the given size.
Parameters
name type description
sizeDelta Point Size to increase or decrease.
return Rectangle
resize(sizeDelta)
Increases or decreases the size of the rectangle by the given size.
Parameters
name type description
sizeDelta Dimension Size to increase or decrease.
return Rectangle
resize(widthDelta, heightDelta)
Increases or decreases the size of the rectangle by the given size.
Parameters
name type description
widthDelta Number width change.
heightDelta Number height change.
return Rectangle
resizeByDimension(d)
deprecatedPlease use resize.
Resize this Rectangle with the value provided as input and return it for convenience.
Parameters
name type description
d Dimension
return Rectangle
scale(xFactor, yFactor)
Reposition and resize this Rectangle with the given scale and return this for convenience.
Parameters
name type description
xFactor Number
yFactoroptional Number defaultundefined
return Rectangle
setBounds(x, y, width, height)
Override the bounds of the rectangle.
Parameters
name type description
x Number x coordinate.
y Number y coordinate.
width Number width.
height Number Height.
return Rectangle
shrink(amount)
Reduces the rectangle in all 4 directions by a given amount.
Parameters
name type description
amount Number Amount to shrink.
return Rectangle
shrink(insets)
Reduce the rectangle.
Parameters
name type description
insets Insets An inset containing the information to be reduced.
return Rectangle
shrink(h, v)
Reduce the rectangle.
Parameters
name type description
h Number horizontal reduction
v Number vertical reduction
return Rectangle
shrinkByInsets(insets)
deprecatedPlease use shrink.
Collapse the rectangle via Insets and return this Rectangle for convenience.
Parameters
name type description
insets Insets
return Rectangle
translate(dx, dy)
Apply translation to the rectangular coordinate system.
Parameters
name type description
dx Number x-axis travel amount.
dy Number y-axis travel amount.
return Rectangle
translate(p)
Apply translation to the rectangular coordinate system.
Parameters
name type description
p Point A Point object containing information on the amount of movement along the x and y axes.
return Rectangle
translate(dimension)
Apply translation to the rectangular coordinate system.
Parameters
name type description
dimension Dimension A Dimension object containing axis movement information.
return Rectangle
translateByDimension(d)
deprecatedPlease use translate.
Move this Rectangle by x,y by the width and height of the Dimension, then return this Rectangle for convenience.
Parameters
name type description
d Dimension
return Rectangle
translateByPoint(d)
deprecatedPlease use translate.
Moves this Rectangle by x,y of Point and returns this Rectangle for convenience.
Parameters
name type description
d Point
return Rectangle
transpose()
Switches the width and height of this Rectangle as well as the x and y values.
return Rectangle
union(location)
Expand this square to include the given point.
Parameters
name type description
location Point Points to include.
return Rectangle
union(x, y)
Expand this square to include the given point.
Parameters
name type description
x Number The x-coordinate of the point to include.
y Number The y-coordinate of the point to include.
return Rectangle
union(r)
Expands this rectangle to a size that contains the given rectangle.
Parameters
name type description
r Rectangle squares to include.
return Rectangle
union(x, y, width, height)
Expands this rectangle to a size that contains the given rectangle.
Parameters
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.
return Rectangle
unionWithBounds(x, y, width, height)
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).
Parameters
name type description
x Number
y Number
width Number
height Number
return Rectangle
unionWithLocation(x, y)
deprecatedPlease use union.
Updates the bounds of this Rectangle to the smallest size that can contain both this Rectangle and its coordinates (x, y).
Parameters
name type description
x Number
y Number
return Rectangle
unionWithPoint(p)
deprecatedPlease use union.
Updates the bounds of this Rectangle to the smallest size that can hold both this Rectangle and the specified Point.
Parameters
name type description
p Point
return Rectangle
unionWithRect(r)
deprecatedPlease use union.
Updates the size of this Rectangle to the smallest size that can contain both this Rectangle and the specified Rectangle.
Parameters
name type description
r Rectangle
return Rectangle