跳到主要内容

Rect

declare class Rect {}

Rect holds four integer coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right bottom). These fields can be accessed directly. Use width() and height() to retrieve the rectangle's width and height. Note: most methods do not check to see that the coordinates are sorted correctly (i.e. left <= right and top <= bottom).

Note that the right and bottom coordinates are exclusive. This means a Rect being drawn untransformed onto a Canvas will draw into the column and row described by its left and top coordinates, but not those of its bottom and right.

Instance Method

isEmpty

declare class Rect {
isEmpty() : boolean
}
  • Description

    Returns true if the rectangle is empty (left >= right or top >= bottom).

equals

declare class Rect {
equals(rect: Rect): boolean
}
  • Description

    Indicates whether some other object is "equal to" this one.

height

declare class Rect {
height(): number
}
  • Description

    Returns Rect height

width

declare class Rect {
width(): number
}
  • Description

    Returns rect width

centerX

declare class Rect {
centerX(): number
}
  • Description

    the horizontal center of the rectangle. If the computed value is fractional, this method returns the largest integer that is less than the computed value.

centerY

declare class Rect {
centerY(): number
}
  • Description

    the vertical center of the rectangle. If the computed value is fractional, this method returns the largest integer that is less than the computed value.

exactCenterX

declare class Rect {
exactCenterX(): number
}
  • Description

    the exact horizontal center of the rectangle as a float.

exactCenterY

declare class Rect {
exactCenterY(): number
}
  • Description

    the exact vertical center of the rectangle as a float.

offset

declare class Rect {
offset(dx: number, dy: number): void
}
  • Description

    Offset the rectangle by adding dx to its left and right coordinates, and adding dy to its top and bottom coordinates.

offsetTo

declare class Rect {
offsetTo(newLeft: number, newTop: number): void
}
  • Description

    Offset the rectangle to a specific (left, top) position, keeping its width and height the same.

setEmpty

declare class Rect {
setEmpty(): void
}
  • Description

    Set the rectangle to (0,0,0,0)

inset

declare class Rect {
inset(dx: number, dy: number): void
}
  • Description

    Insets the rectangle on all sides specified by the insets.

contains

declare class Rect {
contains(rect: Rect): boolean
}
  • Description

    Returns true iff the specified rectangle r is inside or equal to this rectangle.

contains

declare class Rect {
contains(x: number, y: number): boolean
}
  • Description

    Returns true if (x,y) is inside the rectangle.

contains

declare class Rect {
contains(left: number, top: number, right: number, bottom: number)
}
  • Description

    Returns true iff the 4 specified sides of a rectangle are inside or equal to this rectangle.