Last updated

API / geotoolkit / util / Rect / Rect

Class: Rect

util.Rect.Rect

Represents a rectangle with sides parallel to the axes. This rectangle has methods that allow the geometry to be queried and modified. The geometry that makes up a rectangle consists of two coordinate points that define the diagonal between the left bottom corner and the right top corner. Note that the bottom vertical coordinate is guaranteed to be less than the top vertical coordinate, and that the left horizontal coordinate is less than the right horizontal coordinate.

Example

const r1 = new Rect({'x': 4,
'y': 3,
'width': 2,
'height': 1
});

const r2 = new Rect(r1);
const r3 = new Rect(4, 3, 6, 4);  // x1, y1, x2, y2
// r1, r2, and r3 are now equal

Hierarchy

Table of contents

Constructors
[new Rect()](/solutions/geotoolkit/apis/classes/geotoolkit.util.rect.rect.md#new rect())[new Rect(properties)](/solutions/geotoolkit/apis/classes/geotoolkit.util.rect.rect.md#new rect(properties))[new Rect(rect)](/solutions/geotoolkit/apis/classes/geotoolkit.util.rect.rect.md#new rect(rect))
[new Rect(x1, y1, x2, y2)](/solutions/geotoolkit/apis/classes/geotoolkit.util.rect.rect.md#new rect(x1, y1, x2, y2))
Methods
Css Properties
Name Type Description
heightnumberHeight
readonlybooleanReadonly
widthnumberWidth
xnumberLeft
ynumberTop

Contents

Constructors

new Rect()

new Rect()

Overrides

Area.constructor


new Rect(properties)

new Rect(properties)

Parameters

Name Type Description
propertiesOptionsobject to copy

Overrides

Area.constructor


new Rect(rect)

new Rect(rect)

Parameters

Name Type Description
rectRectRect instance to copy

Overrides

Area.constructor


new Rect(x1, y1, x2, y2)

new Rect(x1, y1, x2, y2)

Parameters

Name Type Description
x1numberleft
y1numbertop
x2numberright
y2numberbottom

Overrides

Area.constructor

Methods

clipLine

clipLine(a1, a2, result1, result2): number

Clips a line by rectangle.

a1 [IN] the start position of the line. a2 [IN] the end position of the line. result1 [OUT] the first point of the clipped line. result2 [OUT] the end point of the clipped line. return true if clipped rectangle intersects line or line is inside of the rectangle.

Parameters

Name Type Description
a1Pointthe first input point
a2Pointthe second input point
result1Pointthe first output point
result2Pointthe second output point

Returns

number

how many times line intersects rectangle


clone

clone(): Rect

Return clone object.

Returns

Rect

clone a copy of this object


contains

contains(x, y?): boolean

Check if the area contains point

Throws

if illegal argument count

Parameters

Name Type Description
xnumber | Pointx position of the point
Optional ynumbery position of the point

Returns

boolean

Overrides

Area.contains


containsPolygon

containsPolygon(polygon): boolean

Check if rectangle contains polygon

Parameters

Name Type Description
polygonPolygonpolygon

Returns

boolean

true if contains, else false


containsRect

containsRect(x, y, w, h): boolean

Check if rectangle contains rectangle

Throws

if illegal argument count

Parameters

Name Type Description
xnumberx position
ynumbery position
wnumberwidth
hnumberheight

Returns

boolean

containsRect(rect): boolean

Check if rectangle contains rectangle

Throws

if illegal argument count

Parameters

Name Type Description
rectRectrect

Returns

boolean


equalsRect

equalsRect(rect, epsilon?): boolean

Returns true if rectangles are identical

Parameters

Name Type Description
rectRect | Optionsrect to compare to
Optional epsilonnumberacceptance criteria

Returns

boolean

equals this and rect have same x, y, width, height


getBottom

getBottom(): number

Return bottom coordinate (always top < bottom)

Returns

number

y


getBottomCenter

getBottomCenter(): Point

Return Bottom center position

Returns

Point

a new point to specify right bottom position


getBounds

getBounds(): Rect

Return bounds

Returns

Rect

bounds

Overrides

Area.getBounds


getCenter

getCenter(): Point

Gets coordinates of the rectangle's center

Returns

Point

coordinates of the center


getCenterX

getCenterX(): number

Gets X coordinate of the rectangle's center

Returns

number

X coordinate of the center


getCenterY

getCenterY(): number

Gets Y coordinate of the rectangle's center

Returns

number

Y coordinate of the center


getClassName

getClassName(): string

Returns

string

Inherited from

Area.getClassName


getDiagonalLength

getDiagonalLength(): number

Get diagonal length of rectangle

Returns

number

diagonal length


getHeight

getHeight(): number

Return height

Returns

number


getLeft

getLeft(): number

Return coordinate of left corner

Returns

number

x


getLeftBottom

getLeftBottom(): Point

Return left bottom position

Returns

Point

a new point to specify right bottom position


getLeftCenter

getLeftCenter(): Point

Return Left center position

Returns

Point

a new point to specify right bottom position


getLeftTop

getLeftTop(): Point

Return left top position

Returns

Point

a new point to specify left top position


getProperties

getProperties(): Options

Gets all the properties pertaining to this object

Returns

Options

Overrides

Area.getProperties


getRight

getRight(): number

Return coordinate of right corner

Returns

number

x


getRightBottom

getRightBottom(): Point

Return right bottom position

Returns

Point

a new point to specify right bottom position


getRightCenter

getRightCenter(): Point

Return Right center position

Returns

Point

a new point to specify right bottom position


getRightTop

getRightTop(): Point

Return left top position

Returns

Point

a new point to specify left top position


getTop

getTop(): number

Return top coordinate

Returns

number

y


getTopCenter

getTopCenter(): Point

Return Top center position

Returns

Point

a new point to specify right bottom position


getWidth

getWidth(): number

Return width

Returns

number


getX

getX(): number

Return left position

Returns

number


getY

getY(): number

Return top position

Returns

number

y


inflate

inflate(width, height?): Rect

Inflate rectangle from each side by width and height

Parameters

Name Type Description
widthnumberextend in horizontal direction
Optional heightnumberextend in vertical direction

Returns

Rect


intersect

intersect(x, y, width, height): Rect

Intersects this rectangle with the specified one

Throws

if the rect is null or if illegal arguments

Parameters

Name Type Description
xnumberThe x coordinate
ynumberThe y coordinate
widthnumberThe width
heightnumberThe height

Returns

Rect

this

intersect(rect): Rect

Intersects this rectangle with the specified one

Throws

if the rect is null or if illegal arguments

Parameters

Name Type Description
rectRectrectangle to intersect with

Returns

Rect

this


intersects

intersects(rect): boolean

Determines whether or not this Rectangle and the specified Rectangle intersection. Two rectangles intersect if their intersection is non-empty or if they touch on either side.

Parameters

Name Type Description
rectRectThe x coordinate or another rectangle

Returns

boolean

intersects(x, y, w, h): boolean

Determines whether or not this Rectangle and the specified Rectangle intersection. Two rectangles intersect if their intersection is non-empty or if they touch on either side.

Parameters

Name Type Description
xnumberThe x coordinate
ynumberThe y coordinate
wnumberThe width
hnumberThe height

Returns

boolean


isEmpty

isEmpty(): boolean

returns Rect state

Returns

boolean

true if width or height == 0


isReadOnly

isReadOnly(): boolean

return Rect state. If true, rect cannot be modified.

Returns

boolean

readOnly


lock

lock(): Rect

protect Rect instance from modification.

Returns

Rect

this


merge

merge(newRect, operation?): Rect

Merges with provided rectangular area according to the operation applied.

Throws

if the rects provided is null

Parameters

Name Type Description
newRectRectrect to be merged with the current
Optional operationGeometryOperationoperation to apply

Returns

Rect

this


round

round(): Rect

Round this rectangle to integer values for coordinates. This method sets the largest whole numbers less than or equal to the current values of left-top corner and sets the smallest whole numbers greater than or equal to the current values of right-bottom corner of the rectangle.

Returns

Rect

this


setCenter

setCenter(x, y): Rect

Sets rectangle center

Parameters

Name Type Description
xnumberX coordinate of the rectangle's center
ynumberY coordinate of the rectangle's center

Returns

Rect

the actual instance


setHeight

setHeight(h): Rect

Sets height

Parameters

Name Type Description
hnumberheight

Returns

Rect


setProperties

setProperties(properties?): Rect

Sets all the properties pertaining to this object

Parameters

Name Type Description
Optional propertiesOptionsobject containing the properties to set

Returns

Rect

this

Overrides

Area.setProperties


setRect

setRect(rect): Rect

Sets rectangle

Throws

if illegal argument count

Parameters

Name Type Description
rectRect | Optionsrect or params

Returns

Rect

this

setRect(x1, y1, x2, y2): Rect

Sets rectangle

Throws

if illegal argument count

Parameters

Name Type Description
x1numberthe x-coordinate of one corner
y1numberthe y-coordinate of one corner
x2numberthe x-coordinate of the opposite corner
y2numberthe y coordinate of the opposite corner

Returns

Rect

this


setWidth

setWidth(w): Rect

Sets width

Parameters

Name Type Description
wnumberwidth

Returns

Rect


setX

setX(x): Rect

Set left position

Parameters

Name Type Description
xnumberleft position

Returns

Rect

this


setY

setY(y): Rect

Set top position

Parameters

Name Type Description
ynumbertop position

Returns

Rect

this


toString

toString(): string

Returns string like: "Rect: x1,y1:x2,y2" With x1 left With y1 top With x2 right With y2 bottom

Returns

string

string value


translate

translate(tx, ty): Rect

Translates rectangle a specified distance

Parameters

Name Type Description
txnumberx translation
tynumbery translation

Returns

Rect

this


union

union(rect): Rect

Union this Rect with the specified

Parameters

Name Type Description
rectRectThe rect to union with current one

Returns

Rect

this


unionPoint

unionPoint(x, y): Rect

Unions this Rect with the specified x,y-point

Parameters

Name Type Description
xnumberThe x coordinate
ynumberThe y coordinate

Returns

Rect

this


containsRect

Static containsRect(rect1, rect2): boolean

Check if rectangle1 contains rectangle2

Parameters

Name Type Description
rect1Rectrectangle 1
rect2Rectrectangle 2

Returns

boolean

true if contains, else false


fromObject

Static fromObject(object?): Rect

Create or get rect from object

Parameters

Name Type Description
Optional objectTypeobject can be in format of constructor of Rect

Returns

Rect

rect


getClassName

Static getClassName(): string

Returns

string

Inherited from

Area.getClassName


inflateRect

Static inflateRect(source, w, h): Rect

Inflate rectangle

Parameters

Name Type Description
sourceRectrect to be inflated
wnumberThe width to inflate
hnumberThe height to inflate

Returns

Rect

a new inflated rectangle


intersectsRect

Static intersectsRect(rect1, rect2): boolean

Check if rectangle1 intersects rectangle2. Two rectangles intersect if their intersection is non-empty or if they touch on either side.

Parameters

Name Type Description
rect1Rectrectangle 1
rect2Rectrectangle 2

Returns

boolean

true if intersects, else false


merge

Static merge(oldRect, newRect, operation?, dstRect?): Rect

Merges provided rectangular areas according to the operation applied.

Throws

if either of the rects provided is null

Parameters

Name Type Description
oldRectRect1st rect to merge
newRectRect2nd rect to merge
Optional operationGeometryOperationoperation to be performed on the new rect
Optional dstRectRectdestination rectangular geometry

Returns

Rect

merged rectangular geometry