Class Size2

The Size2 implements a 2D size with a width and height. The class follows the 'copy-on-write' pattern, which means that every operation such as Size2.add or Size2.subtract returns a copy of the size2 with updates values. It also implies that the values of the size2 cannot be directly modified.

The concept of immutability improves sharing of objects as all types in TypeScript are assigned by identity, instead of by-value (e.g. a copy) as in other programming languages like C.

Constructors

  • Parameters

    • Optionalwidth: number
    • Optionalheight: number

    Returns Size2

Properties

_height: number
_width: number
zero: Size2

A Size2 with all components set to zero.

Accessors

  • get height(): number
  • The height.

    Returns number

  • set height(value): void
  • Parameters

    • value: number

    Returns void

  • get isZero(): boolean
  • Determines if width and height are zero.

    Returns boolean

  • get width(): number
  • The width.

    Returns number

  • set width(value): void
  • Parameters

    • value: number

    Returns void

Methods

  • Copies all properties defined by the prototype of Size2 from other to this instance.

    Parameters

    Returns Size2

  • Clones this instance and returns a new Size2 with identical values.

    Returns Size2

  • Returns a copy of the current Size2 divided by another Size2.

    Parameters

    Returns Size2

  • Returns a copy of the current Size2 divided by a factor.

    Parameters

    • factor: number

    Returns Size2

  • Sets width and height to zero.

    Returns Size2

  • Divides this Size2 by a factor.

    Parameters

    • factor: number

    Returns Size2

  • Performs component-wise multiplication with another Size2.

    Parameters

    Returns Size2

  • Multiplies the width and height with the given factor.

    Parameters

    • factor: number

    Returns Size2

  • Sets the values.

    Parameters

    • width: number
    • height: number

    Returns Size2

  • Subtracts another Size2 from this one and returns it.

    Parameters

    Returns Size2

  • Returns whether the provided Size2, given a error margin, has the same width and height values as this one.

    Parameters

    • rhs: Immutable<Size2>

      The other Size2 to compare with.

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Returns whether the given Size2 contains the same width and height as this one.

    Parameters

    Returns boolean

  • Returns a copy of the current Size2 multiplied by the given Size2.

    Parameters

    Returns Size2

  • Returns a copy of this Size2 multiplied by the factor.

    Parameters

    • factor: number

    Returns Size2

  • Returns a copy of the current width and height subtracted by the given Size2.

    Parameters

    Returns Size2

  • Returns a string representation of an object.

    Returns string

  • Divides the given Size2 by a factor.

    Parameters

    Returns Size2

  • Compares two Size2 with an error margin.

    Parameters

    • lhs: Immutable<Size2>

      First size2 to compare.

    • rhs: Immutable<Size2>

      Second size2 to compare.

    • Optionalepsilon: number

      Optional. Error margin within which the numbers should be considered equal.

    Returns boolean

    True if equal, false otherwise.

  • Returns whether width and height from both sizes contains the same values.

    Parameters

    Returns boolean

  • Returns a new Size2 with the maximum width and maximum height from both Size2.

    Parameters

    Returns Size2

    Size2 with the maximum width and maximum height from both Size2.

  • Returns a new Size2 with the minimum width and minimum height from both Size2.

    Parameters

    Returns Size2

    Size2 with the minimum width and minimum height from both Size2.

  • Multiply the Size2 by the scalar.

    Parameters

    Returns Size2