Options
All
  • Public
  • Public/Protected
  • All
Menu

Class RectangleUtil

A utility class containing methods related to the Rectangle class.

Hierarchy

  • RectangleUtil

Index

Methods

Static compare

  • compare(r1: Rectangle, r2: Rectangle, e?: number): boolean
  • Compares all properties of the given rectangle, returning true only if they are equal (with the given accuracy 'e').

    Parameters

    • r1: Rectangle
    • r2: Rectangle
    • Optional e: number

    Returns boolean

Static extend

  • extend(rect: Rectangle, left?: number, right?: number, top?: number, bottom?: number): void
  • Extends the rectangle in all four directions.

    Parameters

    • rect: Rectangle
    • Optional left: number
    • Optional right: number
    • Optional top: number
    • Optional bottom: number

    Returns void

Static extendToWholePixels

  • extendToWholePixels(rect: Rectangle, scaleFactor?: number): void
  • Extends the rectangle in all four directions so that it is exactly on pixel bounds.

    Parameters

    • rect: Rectangle
    • Optional scaleFactor: number

    Returns void

Static fit

  • fit(rectangle: Rectangle, into: Rectangle, scaleMode?: string, pixelPerfect?: boolean, out?: Rectangle): Rectangle
  • Calculates a rectangle with the same aspect ratio as the given 'rectangle', centered within 'into'.

    This method is useful for calculating the optimal viewPort for a certain display size. You can use different scale modes to specify how the result should be calculated; furthermore, you can avoid pixel alignment errors by only allowing whole-number multipliers/divisors (e.g. 3, 2, 1, 1/2, 1/3).

    @see starling.utils.ScaleMode

    Parameters

    • rectangle: Rectangle
    • into: Rectangle
    • Optional scaleMode: string
    • Optional pixelPerfect: boolean
    • Optional out: Rectangle

    Returns Rectangle

Static getBounds

  • getBounds(rectangle: Rectangle, matrix: Matrix, out?: Rectangle): Rectangle
  • Calculates the bounds of a rectangle after transforming it by a matrix. If you pass an out-rectangle, the result will be stored in this rectangle instead of creating a new object.

    Parameters

    • rectangle: Rectangle
    • matrix: Matrix
    • Optional out: Rectangle

    Returns Rectangle

Static getBoundsProjected

  • getBoundsProjected(rectangle: Rectangle, matrix: Matrix3D, camPos: Vector3D, out?: Rectangle): Rectangle
  • Calculates the bounds of a rectangle projected into the XY-plane of a certain 3D space as they appear from the given camera position. Note that 'camPos' is expected in the target coordinate system (the same that the XY-plane lies in).

    If you pass an 'out' Rectangle, the result will be stored in this rectangle instead of creating a new object.

    Parameters

    • rectangle: Rectangle
    • matrix: Matrix3D
    • camPos: Vector3D
    • Optional out: Rectangle

    Returns Rectangle

Static getPositions

  • getPositions(rectangle: Rectangle, out?: Vector<Point>): Vector<Point>
  • Returns a vector containing the positions of the four edges of the given rectangle.

    Parameters

    • rectangle: Rectangle
    • Optional out: Vector<Point>

    Returns Vector<Point>

Static intersect

  • intersect(rect1: Rectangle, rect2: Rectangle, out?: Rectangle): Rectangle
  • Calculates the intersection between two Rectangles. If the rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0.

    Parameters

    • rect1: Rectangle
    • rect2: Rectangle
    • Optional out: Rectangle

    Returns Rectangle

Static normalize

  • normalize(rect: Rectangle): void
  • If the rectangle contains negative values for width or height, all coordinates are adjusted so that the rectangle describes the same region with positive values.

    Parameters

    • rect: Rectangle

    Returns void

Generated using TypeDoc