Package com.helger.base.dimension
Class SizeInt
java.lang.Object
com.helger.base.dimension.SizeInt
- All Implemented Interfaces:
IHasDimensionInt,IHasHeightInt,IHasWidthInt
This class represents an object having width and height.
- Author:
- Philip Helger
-
Constructor Summary
ConstructorsConstructorDescriptionSizeInt(int nWidth, int nHeight) Constructor with width and height.SizeInt(@NonNull IHasDimensionInt aObj) Constructor copying from an existing dimension object. -
Method Summary
Modifier and TypeMethodDescriptionboolean@NonNull SizeIntgetAdded(@NonNull IHasDimensionInt aToAdd) Get a new size with the dimensions of the provided object added.@NonNull SizeIntgetBestMatchingSize(int nMaxWidth, int nMaxHeight) Return the scaled width and height relative to a maximum size.int@NonNull SizeIntgetScaledToHeight(int nNewHeight) Get a new size that is scaled to the specified height, keeping the aspect ratio.@NonNull SizeIntgetScaledToWidth(int nNewWidth) Get a new size that is scaled to the specified width, keeping the aspect ratio.@NonNull SizeIntgetSubtracted(@NonNull IHasDimensionInt aToSubtract) Get a new size with the dimensions of the provided object subtracted.intgetWidth()inthashCode()toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.base.dimension.IHasDimensionInt
isLandscape, isPortrait, isQuadratic
-
Constructor Details
-
SizeInt
Constructor copying from an existing dimension object.- Parameters:
aObj- The dimension object to copy from. May not benull.
-
SizeInt
public SizeInt(@Nonnegative int nWidth, @Nonnegative int nHeight) Constructor with width and height.- Parameters:
nWidth- The width. Must be ≥ 0.nHeight- The height. Must be ≥ 0.
-
-
Method Details
-
getWidth
@Nonnegative public int getWidth()- Specified by:
getWidthin interfaceIHasWidthInt- Returns:
- The width of an object
-
getHeight
@Nonnegative public int getHeight()- Specified by:
getHeightin interfaceIHasHeightInt- Returns:
- The height of an object
-
getBestMatchingSize
@CheckReturnValue public @NonNull SizeInt getBestMatchingSize(@Nonnegative int nMaxWidth, @Nonnegative int nMaxHeight) Return the scaled width and height relative to a maximum size.- Parameters:
nMaxWidth- Maximum width. Must be > 0.nMaxHeight- Maximum height. Must be > 0.- Returns:
- An array with 2 elements, where the first element is the width, and the second is the height.
-
getScaledToWidth
Get a new size that is scaled to the specified width, keeping the aspect ratio.- Parameters:
nNewWidth- The new width. Must be > 0.- Returns:
- A new
SizeIntwith the scaled dimensions. Nevernull.
-
getScaledToHeight
Get a new size that is scaled to the specified height, keeping the aspect ratio.- Parameters:
nNewHeight- The new height. Must be > 0.- Returns:
- A new
SizeIntwith the scaled dimensions. Nevernull.
-
getAdded
Get a new size with the dimensions of the provided object added.- Parameters:
aToAdd- The dimension to add. May not benull.- Returns:
- A new
SizeInt. Nevernull.
-
getSubtracted
Get a new size with the dimensions of the provided object subtracted.- Parameters:
aToSubtract- The dimension to subtract. May not benull.- Returns:
- A new
SizeInt. Nevernull.
-
equals
-
hashCode
public int hashCode() -
toString
-