Dimensions
Inheritance: java.lang.Object
public class Dimensions
Represents the linear dimensions (width and height) of one raster rectangular image in arbitrary unit. Immutable struct.
Constructors
Constructor | Description |
---|---|
Dimensions(int width, int height) | Creates a new instance from specified width and height |
Methods
Method | Description |
---|---|
getWidth() | Returns width of the image |
getHeight() | Returns height of the image |
isSquare() | Determines whether specified ‘Dimensions’ represents square, i.e. |
getArea() | Returns an area (Width x Height) |
isEmpty() | Determines whether this “Dimensions” instance is empty and default, i.e. |
getAspectRatio() | Aspect ratio of this dimensions as width/height |
proportionallyResizeForNewWidth(int targetWidth) | Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified width |
proportionallyResizeForNewHeight(int targetHeight) | Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified height |
equals(Dimensions other) | Determines whether this instance is equal with specified “Dimensions” instance |
equals(Object obj) | Determines whether this instance is equal with specified uncasted object, which presumably is another “Dimensions” instance |
hashCode() | Returns a hashcode for this instance, which cannot be changed during its lifetime |
op_Equality(Dimensions first, Dimensions second) | Checks whether two “Dimensions” values are equal, i.e. |
op_Inequality(Dimensions first, Dimensions second) | Checks whether two “Dimensions” values are not equal, i.e. |
toString() | Returns a string representation of this “Dimensions” |
deepClone() | Returns a full copy of this instance |
getEmpty() | Returns an empty Dimensions instance |
Dimensions(int width, int height)
public Dimensions(int width, int height)
Creates a new instance from specified width and height
Parameters:
Parameter | Type | Description |
---|---|---|
width | int | Width of image |
height | int | Height of image |
getWidth()
public final int getWidth()
Returns width of the image
Returns: int
getHeight()
public final int getHeight()
Returns height of the image
Returns: int
isSquare()
public final boolean isSquare()
Determines whether specified ‘Dimensions’ represents square, i.e. if width is equal to height
Returns: boolean
getArea()
public final long getArea()
Returns an area (Width x Height)
Returns: long
isEmpty()
public final boolean isEmpty()
Determines whether this “Dimensions” instance is empty and default, i.e. it doesn’t store correct width and height
Returns: boolean
getAspectRatio()
public final Ratio getAspectRatio()
Aspect ratio of this dimensions as width/height
Returns: Ratio
proportionallyResizeForNewWidth(int targetWidth)
public final Dimensions proportionallyResizeForNewWidth(int targetWidth)
Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified width
Parameters:
Parameter | Type | Description |
---|---|---|
targetWidth | int | New target width, that will be present in resultant Dimension |
Returns: Dimensions - New “Dimensions” instance with specified target width and proportionally resized height
proportionallyResizeForNewHeight(int targetHeight)
public final Dimensions proportionallyResizeForNewHeight(int targetHeight)
Creates and returns new “Dimensions” instance, which is proportionally resized from current, based on specified height
Parameters:
Parameter | Type | Description |
---|---|---|
targetHeight | int | New target height, that will be present in resultant Dimension |
Returns: Dimensions - New “Dimensions” instance with specified target height and proportionally resized width
equals(Dimensions other)
public final boolean equals(Dimensions other)
Determines whether this instance is equal with specified “Dimensions” instance
Parameters:
Parameter | Type | Description |
---|---|---|
other | Dimensions | Other “Dimensions” instance to check on equality |
Returns: boolean - True if are equal, false if are not equal
equals(Object obj)
public boolean equals(Object obj)
Determines whether this instance is equal with specified uncasted object, which presumably is another “Dimensions” instance
Parameters:
Parameter | Type | Description |
---|---|---|
obj | java.lang.Object | Other object, that is presumably of “Dimensions” type, that should be checked on equality with this |
Returns: boolean - True if are equal, false if are not equal
hashCode()
public int hashCode()
Returns a hashcode for this instance, which cannot be changed during its lifetime
Returns: int - Immutable (for this instance) hash-code as signed 4-byte integer
op_Equality(Dimensions first, Dimensions second)
public static boolean op_Equality(Dimensions first, Dimensions second)
Checks whether two “Dimensions” values are equal, i.e. they have equal width and height, or both are empty
Parameters:
Parameter | Type | Description |
---|---|---|
first | Dimensions | First instance to check |
second | Dimensions | Second instance to check |
Returns: boolean - True if are equal, false if are not equal
op_Inequality(Dimensions first, Dimensions second)
public static boolean op_Inequality(Dimensions first, Dimensions second)
Checks whether two “Dimensions” values are not equal, i.e. their corresponding width and/or height are different
Parameters:
Parameter | Type | Description |
---|---|---|
first | Dimensions | First instance to check |
second | Dimensions | Second instance to check |
Returns: boolean - True if are unequal, false if are equal
toString()
public String toString()
Returns a string representation of this “Dimensions”
W640×H480
Returns: java.lang.String - String instance, that contains a width and height in W:(width)×H:(height) format
deepClone()
public final Dimensions deepClone()
Returns a full copy of this instance
Returns: Dimensions - New instance, that is a full and deep copy of this one
getEmpty()
public static Dimensions getEmpty()
Returns an empty Dimensions instance
Returns: Dimensions