Class Rect

A Rect describes a rectangular two-dimensional area as a top-left point (x and y values) and a size (width and height values).

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): Rect

The default constructor (no argument) results in a Rect(0,0,0,0).

Returns

Rect

constructor(tl: Point, br: Point): Rect

The constructor taking two Points produces a Rect that spans both points.

Parameters

  • tl: Point

    Top-left Point

  • br: Point

    Bottom-right Point

Returns

Rect

constructor(tl: Point, sz: Size): Rect

The constructor taking a Point and a Size produces a Rect at that point with that size.

Parameters

Returns

Rect

constructor(x: number, y: number, w: number, h: number): Rect

The four-argument constructor takes four numbers for the x, y, width, height.

Parameters

  • x: number

    Top-left x value.

  • y: number

    Top-left y value.

  • w: number

    Width to be used; must be non-negative.

  • h: number

    Height to be used; must be non-negative.

Returns

Rect

Properties

public bottom: number

Gets or sets the y-axis value of the bottom of the Rect.

public center: Point

Gets or sets the Point at the center of this Rect.

public centerX: number

Gets or sets the horizontal center X coordinate of the Rect.

public centerY: number

Gets or sets the vertical center Y coordinate of the Rect.

public height: number

Gets or sets the height of the Rect.

public left: number

Gets or sets the leftmost value of the Rect.

public position: Point

Gets or sets the x- and y-axis position of the Rect as a Point.

public right: number

Gets or sets the x-axis value of the right of the Rect.

public size: Size

Gets or sets the width and height of the Rect as a Size.

public top: number

Gets or sets the topmost value of the Rect.

public width: number

Gets or sets the width of the Rect.

public x: number

Gets or sets the top-left x coordinate of the Rect.

public y: number

Gets or sets the top-left y coordinate of the Rect.

Methods

public addMargin(m: Margin): Rect

Modify this Rect by adding the given Margin to each side of the Rect.

Parameters

  • m: Margin

    The Margin to add to the Rect.

Returns

Rect

public contains(x: number, y: number, w?: number, h?: number): boolean

Indicates whether this Rect contains the given Point/Rect.

Parameters

  • x: number

    The X coordinate of the Point or Rect to include in the new bounds.

  • y: number

    The Y coordinate of the Point or Rect to include in the new bounds.

  • w?: number optional

    The Width of the Rect to include in the new bounds, defaults to zero.

  • h?: number optional

    The Height of the Rect to include in the new bounds, defaults to zero. false otherwise.

Returns

boolean

public static contains(rx: number, ry: number, rw: number, rh: number, x: number, y: number, w?: number, h?: number): boolean

This static method indicates whether a Rect contains the given Point/Rect.

Parameters

  • rx: number

    The X coordinate of a Rect.

  • ry: number

    The Y coordinate of a Rect.

  • rw: number

    The Width of a Rect.

  • rh: number

    The Height of a Rect.

  • x: number

    The X coordinate of the Point or Rect that might be in the bounds (RX, RY, RW, RH).

  • y: number

    The Y coordinate of the Point or Rect that might be in the bounds (RX, RY, RW, RH).

  • w?: number optional

    The Width of the Rect to include in the new bounds, defaults to zero.

  • h?: number optional

    The Height of the Rect to include in the new bounds, defaults to zero. false otherwise.

Returns

boolean

public containsPoint(p: Point): boolean

Indicates whether this Rect contains the given Point.

Parameters

  • p: Point

    The Point to check. false otherwise.

Returns

boolean

public containsRect(r: Rect): boolean

Indicates whether this Rect contains the given Rect.

Parameters

  • r: Rect

    The Rect to check. false otherwise.

Returns

boolean

public copy(): Rect

Create a copy of this Rect, with the same values.

Returns

Rect

public equalTo(x: number, y: number, w: number, h: number): boolean

Indicates whether the given Rect is equal to the current Rect.

Parameters

  • x: number
  • y: number
  • w: number

    the width.

  • h: number

    the height.

Returns

boolean

public equals(r: Rect): boolean

Indicates whether the given Rect is equal to the current Rect.

Parameters

  • r: Rect

    The rectangle to compare to the current rectangle. and height.

Returns

boolean

public grow(t: number, r: number, b: number, l: number): Rect

Modifies this Rect by adding some distance to each side of the Rect.

Parameters

  • t: number

    the amount to move the top side upwards; may be negative.

  • r: number

    the amount to move the right side rightwards; may be negative.

  • b: number

    the amount to move the bottom side downwards; may be negative.

  • l: number

    the amount to move the left side leftwards; may be negative.

Returns

Rect

public inflate(w: number, h: number): Rect

Modify this Rect so that its width and height are changed on all four sides, equally on the left and right sides, and equally on the top and bottom sides. When the arguments are negative, this operation deflates this Rect, but not beyond zero.

Parameters

  • w: number

    The additional width on each side, left and right; may be negative.

  • h: number

    The additional height on each side, top and bottom; may be negative.

Returns

Rect

public intersect(x: number, y: number, w: number, h: number): Rect

Modify this Rect so that it is the intersection of this Rect and the rectangle defined by x, y, w, h.

Parameters

  • x: number
  • y: number
  • w: number
  • h: number

Returns

Rect

public intersectRect(r: Rect): Rect

Modify this Rect so that it is the intersection of this Rect and the given Rect.

Parameters

  • r: Rect

    Rect to intersect with.

Returns

Rect

public static intersects(rx: number, ry: number, rw: number, rh: number, x: number, y: number, w: number, h: number): boolean

This static method indicates whether a Rect partly or wholly overlaps the given Rect.

Parameters

  • rx: number

    The X coordinate of a Rect.

  • ry: number

    The Y coordinate of a Rect.

  • rw: number

    The Width of a Rect.

  • rh: number

    The Height of a Rect.

  • x: number

    The X coordinate of the Point or Rect that might overlap the bounds (RX, RY, RW, RH).

  • y: number

    The Y coordinate of the Point or Rect that might overlap the bounds (RX, RY, RW, RH).

  • w: number
  • h: number

Returns

boolean

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

Determine if this Rect partly or wholly overlaps the rectangle defined by x, y, w, h.

Parameters

  • x: number
  • y: number
  • w: number
  • h: number

Returns

boolean

public intersectsRect(r: Rect): boolean

Determine if a given Rect is partly or wholly inside of this Rect.

Parameters

  • r: Rect

    Rect to test intersection with.

Returns

boolean

public isEmpty(): boolean

True if this Rect has a Width and Height of zero.

Returns

boolean

public isReal(): boolean

True if this Rect has X, Y, Width, and Height values that are real numbers and not infinity.

Returns

boolean

public offset(dx: number, dy: number): Rect

Modify this Rect by shifting its values with the given DX and DY offsets.

Parameters

  • dx: number
  • dy: number

Returns

Rect

public static parse(str: string): Rect

This static method can be used to read in a Rect from a string that was produced by Rect.stringify.

Parameters

  • str: string

Returns

Rect

public set(r: Rect): Rect

Modify this Rect so that its X, Y, Width, and Height values are the same as the given Rect.

Parameters

  • r: Rect

    the given Rect.

Returns

Rect

public setPoint(p: Point): Rect

Modify this Rect so that its X and Y values are the same as the given Point.

Parameters

  • p: Point

    the given Point.

Returns

Rect

public setSize(s: Size): Rect

Modify this Rect so that its Width and Height values are the same as the given Size.

Parameters

  • s: Size

    the given Size.

Returns

Rect

public setSpot(x: number, y: number, spot: Spot): Rect

Modify this Rect so that a given Spot is at a given (x,y) point using this Rect's size. Return this rectangle for which the spot is at that point, without modifying the size. The result is meaningless if Spot#isNoSpot is true.

Parameters

  • x: number

    the point where the spot should be.

  • y: number

    the point where the spot should be.

  • spot: Spot

    a Spot; Spot#isSpot must be true.

Returns

Rect

public setTo(x: number, y: number, w: number, h: number): Rect

Modify this Rect with new X, Y, Width, and Height values.

Parameters

  • x: number
  • y: number
  • w: number

    the width.

  • h: number

    the height.

Returns

Rect

public static stringify(val: Rect): string

This static method can be used to write out a Rect as a string that can be read by Rect.parse.

Parameters

Returns

string

public subtractMargin(m: Margin): Rect

Modify this Rect by subtracting the given Margin from each side of the Rect.

Parameters

  • m: Margin

    The Margin to subtract from the Rect.

Returns

Rect

public union(x: number, y: number, w?: number, h?: number): Rect

Modify this Rect to be exactly big enough to contain both the original Rect and the given rectangular area.

Parameters

  • x: number

    The X coordinate of the Point or Rect to include in the new bounds.

  • y: number

    The Y coordinate of the Point or Rect to include in the new bounds.

  • w?: number optional

    The Width of the Rect to include in the new bounds, defaults to zero.

  • h?: number optional

    The Height of the Rect to include in the new bounds, defaults to zero.

Returns

Rect

public unionPoint(p: Point): Rect

Modify this Rect to be exactly big enough to contain both the original Rect and the given Point.

Parameters

  • p: Point

    The Point to include in the new bounds.

Returns

Rect

public unionRect(r: Rect): Rect

Modify this Rect to be exactly big enough to contain this Rect and the given Rect.

Parameters

  • r: Rect

    The Rect to include in the new bounds.

Returns

Rect