Size
The Size object is used to describe the size or dimensions of something, through its width
and height
properties.
Example: Create a size that is 10pt wide and 5pt high, and use it to define a rectangle:
Constructors
Size(width, height)
Creates a Size object with the given width and height values.
Parameters:
width:
Number
— the widthheight:
Number
— the heightReturns:
Size
Example:Create a size that is 10pt wide and 5pt high
Size(array)
Creates a Size object using the numbers in the given array as dimensions.
Parameters:
array:
Array
Returns:
Size
Example:Creating a size of width: 320, height: 240 using an array of numbers:
Size(object)
Creates a Size object using the properties in the given object.
Parameters:
object:
Object
Returns:
Size
Example:Creating a size of width: 10, height: 20 using an object literal:
Size(size)
Creates a Size object using the coordinates of the given Size object.
Parameters:
size:
Size
Returns:
Size
Size(point)
Creates a Size object using the
point.x
andpoint.y
values of the given Point object.Parameters:
point:
Point
Returns:
Size
Example:
Operators
+number
,+size
Returns the addition of the supplied value to the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to addReturns:
Size
— the addition of the size and the value as a new size
Example:
Returns the addition of the width and height of the supplied size to the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to addReturns:
Size
— the addition of the two sizes as a new size
Example:
-number
,-size
Returns the subtraction of the supplied value from the width and height of the size as a new size. The object itself is not modified! The object itself is not modified!
Parameters:
number:
Number
— the number to subtractReturns:
Size
— the subtraction of the size and the value as a new size
Example:
Returns the subtraction of the width and height of the supplied size from the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to subtractReturns:
Size
— the subtraction of the two sizes as a new size
Example:
*number
,*size
Returns the multiplication of the supplied value with the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to multiply byReturns:
Size
— the multiplication of the size and the value as a new size
Example:
Returns the multiplication of the width and height of the supplied size with the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to multiply byReturns:
Size
— the multiplication of the two sizes as a new size
Example:
/number
,/size
Returns the division of the supplied value by the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to divide byReturns:
Size
— the division of the size and the value as a new size
Example:
Returns the division of the width and height of the supplied size by the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to divide byReturns:
Size
— the division of the two sizes as a new size
Example:
%number
,%size
The modulo operator returns the integer remainders of dividing the size by the supplied value as a new size.
Parameters:
value:
Number
Returns:
Size
— the integer remainders of dividing the size by the value as a new size
Example:
The modulo operator returns the integer remainders of dividing the size by the supplied size as a new size.
Parameters:
size:
Size
Returns:
Size
— the integer remainders of dividing the sizes by each other as a new size
Example:
Properties
width
The width of the size
Type:
Number
height
The height of the size
Type:
Number
Methods
set(...values)
Sets the size to the passed values. Note that any sequence of parameters that is supported by the various
Size
() constructors also work for calls ofset()
.Parameters:
values:
any value
Returns:
Size
equals(size)
Checks whether the width and height of the size are equal to those of the supplied size.
Parameters:
size:
Size
— the size to compare toReturns:
Boolean
Example:
clone()
Returns a copy of the size.
Returns:
Size
toString()
Returns:
String
— a string representation of the size
Tests
isZero()
Checks if this size has both the width and height set to 0.
Returns:
Boolean
—true
if both width and height are 0,false
otherwise
isNaN()
Checks if the width or the height of the size are NaN.
Returns:
Boolean
—true
if the width or height of the size are NaN,false
otherwise
Math Functions
round()
Returns a new size with rounded
width
andheight
values. The object itself is not modified!Returns:
Size
Example:
ceil()
Returns a new size with the nearest greater non-fractional values to the specified
width
andheight
values. The object itself is not modified!Returns:
Size
Example:
floor()
Returns a new size with the nearest smaller non-fractional values to the specified
width
andheight
values. The object itself is not modified!Returns:
Size
Example:
abs()
Returns a new size with the absolute values of the specified
width
andheight
values. The object itself is not modified!Returns:
Size
Example:
Math Operator Functions
add(number)
Returns the addition of the supplied value to the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to addReturns:
Size
— the addition of the size and the value as a new size
Example:
add(size)
Returns the addition of the width and height of the supplied size to the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to addReturns:
Size
— the addition of the two sizes as a new size
Example:
subtract(number)
Returns the subtraction of the supplied value from the width and height of the size as a new size. The object itself is not modified! The object itself is not modified!
Parameters:
number:
Number
— the number to subtractReturns:
Size
— the subtraction of the size and the value as a new size
Example:
subtract(size)
Returns the subtraction of the width and height of the supplied size from the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to subtractReturns:
Size
— the subtraction of the two sizes as a new size
Example:
multiply(number)
Returns the multiplication of the supplied value with the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to multiply byReturns:
Size
— the multiplication of the size and the value as a new size
Example:
multiply(size)
Returns the multiplication of the width and height of the supplied size with the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to multiply byReturns:
Size
— the multiplication of the two sizes as a new size
Example:
divide(number)
Returns the division of the supplied value by the width and height of the size as a new size. The object itself is not modified!
Parameters:
number:
Number
— the number to divide byReturns:
Size
— the division of the size and the value as a new size
Example:
divide(size)
Returns the division of the width and height of the supplied size by the size as a new size. The object itself is not modified!
Parameters:
size:
Size
— the size to divide byReturns:
Size
— the division of the two sizes as a new size
Example:
modulo(value)
The modulo operator returns the integer remainders of dividing the size by the supplied value as a new size.
Parameters:
value:
Number
Returns:
Size
— the integer remainders of dividing the size by the value as a new size
Example:
modulo(size)
The modulo operator returns the integer remainders of dividing the size by the supplied size as a new size.
Parameters:
size:
Size
Returns:
Size
— the integer remainders of dividing the sizes by each other as a new size
Example:
Static Methods
Size.min(size1, size2)
Returns a new size object with the smallest
width
andheight
of the supplied sizes.Parameters:
size1:
Size
size2:
Size
Returns:
Size
— the newly created size object
Example:
Example:Find the minimum of multiple sizes:
Size.max(size1, size2)
Returns a new size object with the largest
width
andheight
of the supplied sizes.Parameters:
size1:
Size
size2:
Size
Returns:
Size
— the newly created size object
Example:
Example:Find the maximum of multiple sizes:
Size.random()
Returns a size object with random
width
andheight
values between0
and1
.Returns:
Size
— the newly created size object
Example: