Class SizeFloat

java.lang.Object
com.helger.base.dimension.SizeFloat
All Implemented Interfaces:
IHasDimensionFloat, IHasHeightFloat, IHasWidthFloat

@Immutable public class SizeFloat extends Object implements IHasDimensionFloat
This class represents an object having width and height.
Author:
Philip Helger
  • Constructor Details

    • SizeFloat

      public SizeFloat(@NonNull IHasDimensionInt aObj)
      Constructor copying from an existing int dimension object.
      Parameters:
      aObj - The dimension object to copy from. May not be null.
    • SizeFloat

      public SizeFloat(@NonNull IHasDimensionLong aObj)
      Constructor copying from an existing long dimension object.
      Parameters:
      aObj - The dimension object to copy from. May not be null.
    • SizeFloat

      public SizeFloat(@NonNull IHasDimensionFloat aObj)
      Constructor copying from an existing float dimension object.
      Parameters:
      aObj - The dimension object to copy from. May not be null.
    • SizeFloat

      public SizeFloat(@Nonnegative float dWidth, @Nonnegative float dHeight)
      Constructor with width and height.
      Parameters:
      dWidth - The width. Must be ≥ 0.
      dHeight - The height. Must be ≥ 0.
  • Method Details

    • getWidth

      @Nonnegative public float getWidth()
      Specified by:
      getWidth in interface IHasWidthFloat
      Returns:
      The width of an object
    • getHeight

      @Nonnegative public float getHeight()
      Specified by:
      getHeight in interface IHasHeightFloat
      Returns:
      The height of an object
    • getBestMatchingSize

      @CheckReturnValue public @NonNull SizeFloat getBestMatchingSize(@Nonnegative float dMaxWidth, @Nonnegative float dMaxHeight)
      Return the scaled width and height relative to a maximum size.
      Parameters:
      dMaxWidth - Maximum width. Must be > 0.
      dMaxHeight - 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

      @CheckReturnValue public @NonNull SizeFloat getScaledToWidth(@Nonnegative float dNewWidth)
      Get a new size that is scaled to the specified width, keeping the aspect ratio.
      Parameters:
      dNewWidth - The new width. Must be > 0.
      Returns:
      A new SizeFloat with the scaled dimensions. Never null.
    • getScaledToHeight

      @CheckReturnValue public @NonNull SizeFloat getScaledToHeight(@Nonnegative float dNewHeight)
      Get a new size that is scaled to the specified height, keeping the aspect ratio.
      Parameters:
      dNewHeight - The new height. Must be > 0.
      Returns:
      A new SizeFloat with the scaled dimensions. Never null.
    • getAdded

      @CheckReturnValue public @NonNull SizeFloat getAdded(@NonNull IHasDimensionInt aToAdd)
      Get a new size with the dimensions of the provided int dimension added.
      Parameters:
      aToAdd - The dimension to add. May not be null.
      Returns:
      A new SizeFloat. Never null.
    • getAdded

      @CheckReturnValue public @NonNull SizeFloat getAdded(@NonNull IHasDimensionFloat aToAdd)
      Get a new size with the dimensions of the provided float dimension added.
      Parameters:
      aToAdd - The dimension to add. May not be null.
      Returns:
      A new SizeFloat. Never null.
    • getSubtracted

      @CheckReturnValue public @NonNull SizeFloat getSubtracted(@NonNull IHasDimensionInt aToSubtract)
      Get a new size with the dimensions of the provided int dimension subtracted.
      Parameters:
      aToSubtract - The dimension to subtract. May not be null.
      Returns:
      A new SizeFloat. Never null.
    • getSubtracted

      @CheckReturnValue public @NonNull SizeFloat getSubtracted(@NonNull IHasDimensionFloat aToSubtract)
      Get a new size with the dimensions of the provided float dimension subtracted.
      Parameters:
      aToSubtract - The dimension to subtract. May not be null.
      Returns:
      A new SizeFloat. Never null.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object