Rectangle
Encapsulates rectangular areas for comparison, intersection etc.
Note that the right and bottom properties are exclusive.
Properties
9
Properties
9Get/sets the bottom edge of the Rectangle. Note that the requested height will change.
The bottom edge value is exclusive of the calculated rectangle height. So y=0 and bottom=10 means a height of 10.
Alias for x. To match DOMRect.
Get/sets the right edge of the Rectangle. Note that the requested width will change.
The right edge value is exclusive of the calculated rectangle width. So x=0 and right=10 means a width of 10.
Alias for y. To match DOMRect.
Functions
17
Functions
17Modifies the bounds of this Rectangle by the specified deltas.
| Parameter | Type | Description |
|---|---|---|
x | Number | How much to add to the x position. |
y | Number | How much to add to the y position. |
width | Number | How much to add to the width. |
height | Number | How much to add to the height. |
This Rectangle
Returns a cloned version of this Rectangle aligned to a target Rectangle, or element or Widget.
| Parameter | Type | Description |
|---|---|---|
spec | Object | Alignment specification. |
spec.target | HTMLElement | Widget | Rectangle | The Widget or element or Rectangle to align to. |
spec.inflate | Number | Number[] | Arguments to inflate. Specify as a number to inflate the target rectangle by that many pixels, or as an array of inflate values for each edge. |
spec.anchorSize | Number[] | The |
spec.anchorPosition | Object | an |
spec.overlap | Boolean | True to allow this to overlap the target. |
spec.align | String | The edge alignment specification string, specifying two points to bring together. Each point is described by an edge initial ( So the form would be For example |
spec.constrainTo | HTMLElement | Widget | Rectangle | The Widget or Element or Rectangle to constrain to.
If the requested alignment cannot be constrained (it will first shrink the resulting Rectangle according
to the |
spec.axisLock | Boolean | Specify as a truthy value to fall back to aligning against the opposite
edge first if the requested alignment cannot be constrained into the |
spec.matchSize | Boolean | min | When aligning edge-to-edge, match the length of the aligned-to edge of the target. Setting this value to This is only honored when |
spec.offset | Number | Number[] | The 'x' and 'y' offset values to create an extra margin round the target to offset the aligned widget further from the target. May be configured as -ve to move the aligned widget towards the target - for example producing the effect of the anchor pointer piercing the target. |
spec.constrainPadding | Number | Number[] | The amount of pixels to pad from the |
spec.rtl | Boolean | Pass as true if this is being used in an RTL environment, and aligning 0% to 100% along a horizontal edge must proceed from right to left. |
A new Rectangle aligned as requested if possible, but if the requested position violates
the constrainTo Rectangle, the shortest translation from the requested position which obeys constraints will be
used.
Returns the client Rectangle (within border and padding and scrollbars) in document based coordinates of the passed element.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The element to calculate the Rectangle for. |
relativeTo | HTMLElement | Optionally, a parent element in whose space to calculate the Rectangle. |
ignorePageScroll | Boolean | Use browser viewport based coordinates. |
clipStickies | Boolean | Return the Rectangle within any sticky elements docked at the element edges. |
The Rectangle in document based (or, optionally viewport based) coordinates. Relative to the relativeTo parameter if passed.
Creates a copy of this Rectangle.
Attempts to constrain this Rectangle into the passed Rectangle. If the strict parameter is true
then this method will return false if constraint could not be achieved.
If this Rectangle has a minHeight or minWidth property, size will be adjusted while attempting to constrain.
Right and bottom are adjusted first leaving the top and bottom sides to "win" in the case that this Rectangle overflows the constrainTo Rectangle.
| Parameter | Type | Description |
|---|---|---|
constrainTo | Rectangle | The Rectangle to constrain this Rectangle into if possible. |
strict | Boolean | Pass |
This Rectangle. If strict is true, and constraining was not successful, false.
Returns true if this Rectangle wholly contains the passed rectangle.
Note that a Point may be passed.
| Parameter | Type | Description |
|---|---|---|
other | Rectangle | The Rectangle to test for containment within this Rectangle |
true if the other Rectangle is wholly contained within this Rectangle
Returns the content Rectangle (within border and padding) in document based coordinates of the passed element.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The element to calculate the Rectangle for. |
relativeTo | HTMLElement | Optionally, a parent element in whose space to calculate the Rectangle. |
ignorePageScroll | Boolean | Use browser viewport based coordinates. |
The Rectangle in document based (or, optionally viewport based) coordinates. Relative to the relativeTo parameter if passed.
Clips off the area of the "other" Rectangle(s) from this Rectangle if any of the the other rectangles occlude a whole edge of this Rectangle.
In the example below, the other Rectangle obscures the whole of the left edge of this Rectangle.
The result from this call would be a Rectangle with the left edge moved to the right edge of the other Rectangle.
This is useful for clipping off sticky elements which are docked to the edges of an element.
other this
┌───────┐─────────────────────────────────────────┐
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
└───────┘─────────────────────────────────────────┘
| Parameter | Type | Description |
|---|---|---|
other | Rectangle | The potentially occluding Rectangle(s). |
A new rectangle with the area of the other Rectangle clipped off.
Returns the Rectangle in document based coordinates of the passed element.
Note: If the element passed is the document or window the window's
rectangle is returned which is always at [0, 0] and encompasses the
browser's entire document viewport.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | Widget | Mask | String | The element (or selector) to calculate the Rectangle for. |
relativeTo | HTMLElement | String | Optionally, a parent element (or selector) in whose space to calculate the Rectangle. |
ignorePageScroll | Boolean | Use browser viewport based coordinates. |
The Rectangle in document based (or, optionally viewport based) coordinates. Relative to the relativeTo parameter if passed.
Returns the Rectangle in viewport coordinates of the passed element.
Note: If the element passed is the document or window the window's rectangle is returned which is always
at [0, 0] and encompasses the browser's entire document viewport.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The element to calculate the Rectangle for. |
relativeTo | HTMLElement | Optionally, a parent element in whose space to calculate the Rectangle. |
The Rectangle in viewport based coordinates. Relative to the relativeTo parameter if provided.
Highlights this Rectangle using the highlighting effect of DomHelper on a transient element which encapsulates the region's area.
Returns the inner Rectangle (within border) in document based coordinates of the passed element.
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The element to calculate the Rectangle for. |
relativeTo | HTMLElement | Optionally, a parent element in whose space to calculate the Rectangle. |
ignorePageScroll | Boolean | Use browser viewport based coordinates. |
The Rectangle in document based (or, optionally viewport based) coordinates. Relative to the relativeTo parameter if passed.
Checks if this Rectangle intersects the passed Rectangle
| Parameter | Type | Description |
|---|---|---|
other | Rectangle | The Rectangle to intersect with this. |
useBoolean | Boolean | Specify |
allowZeroDimensions | Boolean |
|
Returns the intersection Rectangle or false if there is no intersection.
Moves this Rectangle to the passed x, y position. Size is maintained.
| Parameter | Type | Description |
|---|---|---|
x | Number | The new X position. |
y | Number | The new Y position. |
This Rectangle;
Rounds this Rectangle to the pixel resolution of the current display or to the nearest
passed unit which defaults to the current display's devicePixelRatio.
| Parameter | Type | Description |
|---|---|---|
devicePixelRatio | Number | device pixel ratio which defaults to |
Translates this Rectangle by the passed vector. Size is maintained.
| Parameter | Type | Description |
|---|---|---|
x | Number | The X translation vector. |
y | Number | The Y translation vector. |
This Rectangle;
Typedefs
1
Typedefs
1| Parameter | Type | Description |
|---|---|---|
anchor | Object | If an anchor point was specified, this is the point on the aligned Rectangle at the alignment position. |
anchor.x | Number | The X coordinate of the anchor point. |
anchor.y | Number | The Y coordinate of the anchor point. |
anchor.edge | top | right | bottom | left | The edge on which the anchor point lies. |
align | String | The final alignment string used after constraint was applied. |
zone | Number | The zone number the result was aligned into (0, 1, 2, 3 for top right bottom, left). |
constraint | Rectangle | The Rectangle the result was constrained into. |