Represents the size of a rectangular object with a given width and height.
ImplementsInheritance Hierarchy

Remarks

This is a convertible type that can be used with the following notation(s) in parameter lists, parameter objects or setters.

It is possible to specify an Array or plain Object to define the Size:

[20, 20] // width, height
{ width: 20, height: 20 }

Examples

The following example shows a few ways to use Size:
// Create a new size
const size = new Size(10, 15)

console.log(
  `The size has width ${size.width} and height ${size.height} representing an area of ${size.area}`,
)

// Create another size
const size2 = new Size(5, 17)

// Enlarge it by multiplying with a factor
const larger = size2.multiply(1.5)

// Make the first size only half as large
const half = size.multiply(0.5)

Members

Show:

Constructors

Creates a new instance with the provided width and height.

Parameters

width: number
The new width.
height: number
The new height.

Properties

Gets the area of this instance which is the product of width and height.
The area of an empty size is 0 (even though the product would yield another value since both width and height are negative).
readonlyfinal

Property Value

The area.
Gets the height.
Negative values for the height indicate an empty size.
readonlyfinal

Property Value

The height.

Implements

ISize.height
Determines whether the specified size is empty.
ISize instances are considered empty if their width or height is less than 0.0d.
readonly

Defined in

ISize.isEmpty
Gets a value indicating whether this instance is finite.
This means that the instance is not empty and both width and height are finite.
readonlyfinal
Gets the width.
Negative values for the width indicate an empty size.
readonlyfinal

Property Value

The width.

Implements

ISize.width

Methods

Determines whether the specified object is of type Size and has the same width and height as this instance.
final

Parameters

other: any
An object to compare with the current Size instance.

Return Value

boolean
true if the specified object is of type Size and has the same width and height as this instance; otherwise, false.
Returns a hash code for this object.

The hash code is a numeric value that can be used to treat this object as a key in a hash table or similar data structure.

Two objects that are considered equal must have the same hash code. However, the reverse does not hold and two objects having the same hash code don't have to be equal. Ideally, the hash code should be roughly uniformly-distributed to prevent hash tables from performing poorly. Calculating the hash code is also a potentially frequent operation and should therefore be fast.

final

Return Value

number
the hash code for this object
Multiplies the width and height by the given factor and returns the result.
final

Parameters

factor: number
The factor to multiply the width and height by.

Return Value

Size
A new size that has the width and height multiplied by the factor.
Creates a MutableSize instance with the current values of this instance.
final

Return Value

MutableSize
A new MutableSize instance whose properties have been initialized with the values of this instance.
Creates a new Size instance with the current values of this size.

Return Value

Size
A new Size instance that has been initialized with the current values of size.

Defined in

ISize.toSize
Returns a that describes this instance.
final

Return Value

string
A that describes this instance.

Constants

The "empty" size that has width and height set to -1.0d.
The "infinite" size that has width and height set to Number.POSITIVE_INFINITY.
The "zero" size that has width and height set to 0.0d.
This size is not treated as empty.
static

Static Methods

Creates a Size instance from the given size-like object by performing automatic type conversion.
static

Parameters

sizeLike: Size
The object to convert to a Size.

Return Value

Size
The given sizeLike if it is already a Size, or a new instance initialized to the values found in sizeLike.
Returns a size whose width and height are the respective maximum of the two provided Size instances.
static

Parameters

size1: Size
The first size.
size2: Size
The second size.

Return Value

Size
A size whose width and height are the Math.max of the respective properties of the two parameters.
Returns a size whose width and height are the respective minimum of the two provided Size instances.
static

Parameters

size1: Size
The first size.
size2: Size
The second size.

Return Value

Size
A size whose width and height are the Math.min of the respective properties of the two parameters.