Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Rect

A 2D rectangle defined by x, y position and width, height.

Hierarchy

Index

Constructors

constructor

  • newRect(other: Rect): Rect
  • newRect(x?: undefined | number, y?: undefined | number, width?: undefined | number, height?: undefined | number): Rect
  • en

    Constructs a Rect from another one.

    zh

    构造与指定矩形相等的矩形。

    Parameters

    • other: Rect

      Specified Rect.

    Returns Rect

  • en

    Constructs a Rect with specified values.

    zh

    构造具有指定的最小值和尺寸的矩形。

    Parameters

    • Optional x: undefined | number

      The minimum X coordinate of the rectangle.

    • Optional y: undefined | number

      The minimum Y coordinate of the rectangle.

    • Optional width: undefined | number

      The width of the rectangle, measured from the X position.

    • Optional height: undefined | number

      The height of the rectangle, measured from the Y position.

    Returns Rect

Properties

T

T: any

Return the information of the current rect in string

returns

The information of the current rect in string

height

height: number

The height of the Rect.

width

width: number

The width of the Rect.

x

x: number

The minimum x value.

y

y: number

The minimum y value.

Accessors

center

  • get center(): Vec2
  • set center(value: Vec2): void

origin

  • get origin(): Vec2
  • set origin(value: Vec2): void

size

  • get size(): Size
  • set size(value: Size): void

w

  • get w(): number
  • set w(val: number): void

xMax

  • get xMax(): number
  • set xMax(value: number): void

xMin

  • get xMin(): number
  • set xMin(value: number): void

yMax

  • get yMax(): number
  • set yMax(value: number): void

yMin

  • get yMin(): number
  • set yMin(value: number): void

z

  • get z(): number
  • set z(val: number): void

Methods

clone

contains

  • contains(point: Vec2): boolean
  • Check whether the current rect contains the given point.

    Parameters

    • point: Vec2

      Specified point.

    Returns boolean

    The specified point is included in the rectangle and returns true', otherwise it returnsfalse'.

containsRect

  • containsRect(other: Rect): boolean
  • Returns true if the other rect entirely inside this rectangle.

    Parameters

    • other: Rect

      Specified rectangles.

    Returns boolean

    Returns true' if all the points of the specified rectangle are included in the current rectangle,false' otherwise.

equals

  • equals(other: Rect): boolean
  • Check whether the current Rect equals another one.

    Parameters

    • other: Rect

      Specified rectangles.

    Returns boolean

    Returns true' when the minimum and maximum values of both rectangles are equal, respectively; otherwise, returnsfalse'.

intersects

  • intersects(other: Rect): boolean
  • Check whether the current rectangle intersects with the given one.

    Parameters

    • other: Rect

      Specified rectangles.

    Returns boolean

    If intersected, return true', otherwise returnfalse'.

lerp

  • lerp(to: Rect, ratio: number): this
  • Calculate the interpolation result between this Rect and another one with given ratio.

    Parameters

    • to: Rect

      Target Rect.

    • ratio: number

      The interpolation coefficient.The range is [0,1].

    Returns this

set

  • set(other: Rect): any
  • set(x?: undefined | number, y?: undefined | number, width?: undefined | number, height?: undefined | number): any
  • Set values with another Rect.

    Parameters

    • other: Rect

      Specified Rect.

    Returns any

    this

  • Set the value of each component of the current Rect.

    Parameters

    • Optional x: undefined | number

      The x parameter of the specified rectangle

    • Optional y: undefined | number

      The y parameter of the specified rectangle

    • Optional width: undefined | number

      The width parameter of the specified rectangle

    • Optional height: undefined | number

      The height parameter of the specified rectangle

    Returns any

    this

toString

  • toString(): string

transformMat4

  • transformMat4(mat: Mat4): this

Static fromMinMax

  • fromMinMax<Out, VecLike>(out: Out, v1: VecLike, v2: VecLike): Out
  • Creates a rectangle from two coordinate values.

    Type parameters

    Parameters

    • out: Out
    • v1: VecLike

      Specified point 1.

    • v2: VecLike

      Specified point 2.

    Returns Out

    Target rectangle.

Static intersection

  • intersection<Out>(out: Out, one: Out, other: Out): Out
  • Returns the overlapping portion of 2 rectangles.

    Type parameters

    Parameters

    • out: Out

      Output Rect.

    • one: Out

      One of the specify Rect.

    • other: Out

      Another of the specify Rect.

    Returns Out

Static lerp

  • lerp<Out>(out: Out, from: Out, to: Out, ratio: number): Out
  • Calculate the interpolation result between this rect and another one with given ratio

    Type parameters

    Parameters

    • out: Out

      Output rect.

    • from: Out

      Original rect.

    • to: Out

      Target rect.

    • ratio: number

      The interpolation coefficient.The range is [0,1].

    Returns Out

Static union

  • union<Out>(out: Out, one: Out, other: Out): Out
  • Returns the smallest rectangle that contains the current rect and the given rect.

    Type parameters

    Parameters

    • out: Out

      Output Rect.

    • one: Out

      One of the specify Rect.

    • other: Out

      Another of the specify Rect.

    Returns Out

Generated using TypeDoc