Rectangle

Extends: module:AWT.Shape

Source: AWT.js:1038

The rectangular module:AWT.Shape accepts five different sets of parameters:

Example

CODE
<p>// Calling Rectangle() with different sets of parameters<br>
// A Point and a Dimension:<br>
new Rectangle(pos, dim)<br>
// Another Rectangle, to be cloned:<br>
new Rectangle(rect)<br>
// Two Point objects containing the coordinates of upper-left and lower-right vertexs:<br>
new Rectangle(p0, p1)<br>
// An array of four numbers with the coordinates of the same vertexs:<br>
new Rectangle([x0, y0, x1, y1])<br>
// Four single numbers, meaning the same coordinates as above:<br>
new Rectangle(x0, y0, x1, y1)</p>

Constructor

new Rectangle( pos: Point | Rectangle | number | Array.<number>, dim?: Dimension | number, w?: number, h?: number, ): Rectangle

Rectangle constructor

Parameters

  • pos (Point | Rectangle | number | Array.<number>)
  • dim (Dimension | number, optional)
  • w (number, optional)
  • h (number, optional)

Instance Methods

getBounds(): module:AWT.Rectangle

Overrides: module:AWT.Shape#getBounds

Gets the enclosing Rectangle of this Shape.

Returns

setBounds(rect: module:AWT.Rectangle): module:AWT.Rectangle

Sets this Rectangle the position and dimension of another one

Parameters

Returns

equals(r: module:AWT.Shape): boolean

Overrides: module:AWT.Shape#equals

Checks if two shapes are equivalent.

Parameters

Returns

  • boolean

clone(): module:AWT.Rectangle

Clones this Rectangle

Returns

scaleBy(delta: Point | Dimension): module:AWT.Rectangle

Overrides: module:AWT.Shape#scaleBy

Multiplies the dimension of the Shape by the specified delta amount.

Parameters

  • delta (Point | Dimension) — Object containing the X and Y ratio to be scaled.

Returns

grow(dx: number, dy: number): module:AWT.Rectangle

Expands the boundaries of this shape. This affects the current position and dimension.

Parameters

  • dx (number) — The amount to grow (or decrease) in horizontal direction
  • dy (number) — The amount to grow (or decrease) in vertical direction

Returns

getOppositeVertex(): module:AWT.Point

Gets the module:AWT.Point corresponding to the lower-right vertex of the Rectangle.

Returns

add(shape: module:AWT.Shape): module:AWT.Rectangle

Adds the boundaries of another shape to the current one

Parameters

Returns

getCoords(): string

Gets a string with the co-ordinates of the upper-left and lower-right vertexs of this rectangle,
(with values rounded to int)

Returns

  • string

getAttributes(): object

Gets a object with the basic attributes needed to rebuild this instance excluding functions,
parent references, constants and also attributes retaining the default value.
The resulting object is commonly usued to serialize elements in JSON format.

Returns

  • object

setAttributes(data: object): module:AWT.Rectangle

Overrides: module:AWT.Shape#setAttributes

Reads the properties of this Rectangle from a data object

Parameters

  • data (object) — The data object to be parsed

Returns

moveBy(delta: Point | Dimension): module:AWT.Shape

Inherited from module:AWT.Shape#moveBy

Overrides: module:AWT.Shape#moveBy

Shifts the shape a specified amount in horizontal and vertical directions

Parameters

Returns

moveTo(newPos: module:AWT.Point): module:AWT.Shape

Inherited from module:AWT.Shape#moveTo

Overrides: module:AWT.Shape#moveTo

Moves this shape to a new position

Parameters

Returns

getShape(rect: module:AWT.Rectangle): module:AWT.Shape

Inherited from module:AWT.Shape#getShape

Overrides: module:AWT.Shape#getShape

Gets a clone of this shape moved to the pos component of the rectangle and scaled
by its dim value.

Parameters

  • rect (module:AWT.Rectangle) — The rectangle to be taken as a base for moving and scaling
    this shape.

Returns

contains(_p: module:AWT.Point): boolean

Inherited from module:AWT.Shape#contains

Overrides: module:AWT.Shape#contains

Checks if the provided module:AWT.Point is inside this shape.

Parameters

Returns

  • boolean

intersects(_r: module:AWT.Rectangle): boolean

Inherited from module:AWT.Shape#intersects

Overrides: module:AWT.Shape#intersects

Checks if the provided Rectangle r intersects with this shape.

Parameters

Returns

  • boolean

fill( ctx: external:CanvasRenderingContext2D, dirtyRegion?: module:AWT.Rectangle, ): external:CanvasRenderingContext2D

Inherited from module:AWT.Shape#fill

Overrides: module:AWT.Shape#fill

Fills the Shape with the current style in the provided HTML canvas context

Parameters

Returns

stroke( ctx: external:CanvasRenderingContext2D, ): external:CanvasRenderingContext2D

Inherited from module:AWT.Shape#stroke

Overrides: module:AWT.Shape#stroke

Draws this shape in the provided HTML canvas 2D rendering context.

Parameters

Returns

preparePath( ctx: external:CanvasRenderingContext2D, ): external:CanvasRenderingContext2D

Inherited from module:AWT.Shape#preparePath

Overrides: module:AWT.Shape#preparePath

Prepares an HTML canvas 2D rendering context with a path that can be used to stroke a line,
to fill a surface or to define a clipping region.

Parameters

Returns

clip( ctx: external:CanvasRenderingContext2D, fillRule?: string, ): external:CanvasRenderingContext2D

Inherited from module:AWT.Shape#clip

Overrides: module:AWT.Shape#clip

Creates a clipping region on the specified HTML canvas 2D rendering context

Parameters

  • ctx (external:CanvasRenderingContext2D) — The rendering context
  • fillRule (string, optional, default: "'nonzero'") — Can be 'nonzero' (default when not set) or 'evenodd'

Returns

isRect(): boolean

Inherited from module:AWT.Shape#isRect

Overrides: module:AWT.Shape#isRect

Shorthand method for determining if a Shape is an Rectangle

Returns

  • boolean

toString(): string

Inherited from module:AWT.Shape#toString

Overrides: module:AWT.Shape#toString

Overwrites the original 'Object.toString' method with a more descriptive text

Returns

  • string

Static Methods

buildShape(data: object): module:AWT.Shape

Inherited from module:AWT.Shape

Builds a shape based on the provided data object.
Data should contain a 'type' member, specifying the type of shape requested ('rect', 'ellipse', 'rectangle' or 'path')

Parameters

  • data (object) — Specific data for this shape

Returns

Instance Fields

type: string

Overrides: module:AWT.Shape#type

Shape type id

dim: module:AWT.Dimension

The Dimension of the Rectangle

pos: module:AWT.Point

Inherited from module:AWT.Shape#pos

Overrides: module:AWT.Shape#pos

The current position of the shape