API / geotoolkit / 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↳
Rect↳↳
BubbleRect↳↳
ReadOnlyRect
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 |
|---|---|---|
height | number | Height |
readonly | boolean | Readonly |
width | number | Width |
x | number | Left |
y | number | Top |
Constructors
• new Rect()
Area.constructor
• new Rect(properties)
| Name | Type | Description |
|---|---|---|
properties | Options | object to copy |
Area.constructor
• new Rect(rect)
| Name | Type | Description |
|---|---|---|
rect | Rect | Rect instance to copy |
Area.constructor
• new Rect(x1, y1, x2, y2)
| Name | Type | Description |
|---|---|---|
x1 | number | left |
y1 | number | top |
x2 | number | right |
y2 | number | bottom |
Area.constructor
Methods
▸ 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.
| Name | Type | Description |
|---|---|---|
a1 | Point | the first input point |
a2 | Point | the second input point |
result1 | Point | the first output point |
result2 | Point | the second output point |
number
how many times line intersects rectangle
▸ clone(): Rect
Return clone object.
clone a copy of this object
▸ contains(x, y?): boolean
Check if the area contains point
Throws
if illegal argument count
| Name | Type | Description |
|---|---|---|
x | number | Point | x position of the point |
Optional y | number | y position of the point |
boolean
▸ containsPolygon(polygon): boolean
Check if rectangle contains polygon
| Name | Type | Description |
|---|---|---|
polygon | Polygon | polygon |
boolean
true if contains, else false
▸ containsRect(x, y, w, h): boolean
Check if rectangle contains rectangle
Throws
if illegal argument count
| Name | Type | Description |
|---|---|---|
x | number | x position |
y | number | y position |
w | number | width |
h | number | height |
boolean
▸ containsRect(rect): boolean
Check if rectangle contains rectangle
Throws
if illegal argument count
| Name | Type | Description |
|---|---|---|
rect | Rect | rect |
boolean
▸ equalsRect(rect, epsilon?): boolean
Returns true if rectangles are identical
boolean
equals this and rect have same x, y, width, height
▸ getBottom(): number
Return bottom coordinate (always top < bottom)
number
y
▸ getBottomCenter(): Point
Return Bottom center position
a new point to specify right bottom position
▸ getBounds(): Rect
Return bounds
bounds
▸ getCenter(): Point
Gets coordinates of the rectangle's center
coordinates of the center
▸ getCenterX(): number
Gets X coordinate of the rectangle's center
number
X coordinate of the center
▸ getCenterY(): number
Gets Y coordinate of the rectangle's center
number
Y coordinate of the center
▸ getClassName(): string
string
▸ getDiagonalLength(): number
Get diagonal length of rectangle
number
diagonal length
▸ getHeight(): number
Return height
number
▸ getLeft(): number
Return coordinate of left corner
number
x
▸ getLeftBottom(): Point
Return left bottom position
a new point to specify right bottom position
▸ getLeftCenter(): Point
Return Left center position
a new point to specify right bottom position
▸ getLeftTop(): Point
Return left top position
a new point to specify left top position
▸ getProperties(): Options
Gets all the properties pertaining to this object
▸ getRight(): number
Return coordinate of right corner
number
x
▸ getRightBottom(): Point
Return right bottom position
a new point to specify right bottom position
▸ getRightCenter(): Point
Return Right center position
a new point to specify right bottom position
▸ getRightTop(): Point
Return left top position
a new point to specify left top position
▸ getTop(): number
Return top coordinate
number
y
▸ getTopCenter(): Point
Return Top center position
a new point to specify right bottom position
▸ getWidth(): number
Return width
number
▸ getX(): number
Return left position
number
▸ getY(): number
Return top position
number
y
▸ inflate(width, height?): Rect
Inflate rectangle from each side by width and height
| Name | Type | Description |
|---|---|---|
width | number | extend in horizontal direction |
Optional height | number | extend in vertical direction |
▸ intersect(x, y, width, height): Rect
Intersects this rectangle with the specified one
Throws
if the rect is null or if illegal arguments
| Name | Type | Description |
|---|---|---|
x | number | The x coordinate |
y | number | The y coordinate |
width | number | The width |
height | number | The height |
this
▸ intersect(rect): Rect
Intersects this rectangle with the specified one
Throws
if the rect is null or if illegal arguments
| Name | Type | Description |
|---|---|---|
rect | Rect | rectangle to intersect with |
this
▸ 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.
| Name | Type | Description |
|---|---|---|
rect | Rect | The x coordinate or another rectangle |
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.
| Name | Type | Description |
|---|---|---|
x | number | The x coordinate |
y | number | The y coordinate |
w | number | The width |
h | number | The height |
boolean
▸ isEmpty(): boolean
returns Rect state
boolean
true if width or height == 0
▸ isReadOnly(): boolean
return Rect state. If true, rect cannot be modified.
boolean
readOnly
▸ lock(): Rect
protect Rect instance from modification.
this
▸ merge(newRect, operation?): Rect
Merges with provided rectangular area according to the operation applied.
Throws
if the rects provided is null
| Name | Type | Description |
|---|---|---|
newRect | Rect | rect to be merged with the current |
Optional operation | GeometryOperation | operation to apply |
this
▸ 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.
this
▸ setCenter(x, y): Rect
Sets rectangle center
| Name | Type | Description |
|---|---|---|
x | number | X coordinate of the rectangle's center |
y | number | Y coordinate of the rectangle's center |
the actual instance
▸ setHeight(h): Rect
Sets height
| Name | Type | Description |
|---|---|---|
h | number | height |
▸ setProperties(properties?): Rect
Sets all the properties pertaining to this object
| Name | Type | Description |
|---|---|---|
Optional properties | Options | object containing the properties to set |
this
▸ setRect(rect): Rect
Sets rectangle
Throws
if illegal argument count
this
▸ setRect(x1, y1, x2, y2): Rect
Sets rectangle
Throws
if illegal argument count
| Name | Type | Description |
|---|---|---|
x1 | number | the x-coordinate of one corner |
y1 | number | the y-coordinate of one corner |
x2 | number | the x-coordinate of the opposite corner |
y2 | number | the y coordinate of the opposite corner |
this
▸ setWidth(w): Rect
Sets width
| Name | Type | Description |
|---|---|---|
w | number | width |
▸ setX(x): Rect
Set left position
| Name | Type | Description |
|---|---|---|
x | number | left position |
this
▸ setY(y): Rect
Set top position
| Name | Type | Description |
|---|---|---|
y | number | top position |
this
▸ toString(): string
Returns string like: "Rect: x1,y1:x2,y2" With x1 left With y1 top With x2 right With y2 bottom
string
string value
▸ translate(tx, ty): Rect
Translates rectangle a specified distance
| Name | Type | Description |
|---|---|---|
tx | number | x translation |
ty | number | y translation |
this
▸ union(rect): Rect
Union this Rect with the specified
| Name | Type | Description |
|---|---|---|
rect | Rect | The rect to union with current one |
this
▸ unionPoint(x, y): Rect
Unions this Rect with the specified x,y-point
| Name | Type | Description |
|---|---|---|
x | number | The x coordinate |
y | number | The y coordinate |
this
▸ Static containsRect(rect1, rect2): boolean
Check if rectangle1 contains rectangle2
boolean
true if contains, else false
▸ Static fromObject(object?): Rect
Create or get rect from object
rect
▸ Static getClassName(): string
string
▸ Static inflateRect(source, w, h): Rect
Inflate rectangle
| Name | Type | Description |
|---|---|---|
source | Rect | rect to be inflated |
w | number | The width to inflate |
h | number | The height to inflate |
a new inflated rectangle
▸ 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.
boolean
true if intersects, else false
▸ 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
| Name | Type | Description |
|---|---|---|
oldRect | Rect | 1st rect to merge |
newRect | Rect | 2nd rect to merge |
Optional operation | GeometryOperation | operation to be performed on the new rect |
Optional dstRect | Rect | destination rectangular geometry |
merged rectangular geometry