Record Class Size

java.lang.Object
java.lang.Record
is.galia.image.Size
Record Components:
width - Width in pixels.
height - Height in pixels.

public record Size(double width, double height) extends Record

Two-dimensional area, typically an image area. Values are stored as doubles.

Zero-dimensions are allowed, but not negative ones.

  • Constructor Details

    • Size

      public Size(double width, double height)
      Floating-point constructor.
    • Size

      public Size(long width, long height)
      Integer constructor. The arguments will be converted to doubles for storage.
    • Size

      public Size(Size size)
      Copy constructor.
  • Method Details

    • isPyramid

      public static boolean isPyramid(List<Size> levels)
      Parameters:
      levels - Resolution levels in order from largest to smallest.
      Returns:
      Whether the given dimensions appear to comprise a pyramid of successively half-scaled dimensions.
    • ofScaledArea

      public static Size ofScaledArea(Size size, long scaledArea)
      Parameters:
      size - Pre-scaled size.
      scaledArea - Area to fill.
      Returns:
      Resulting dimensions when size is scaled to fill scaledArea.
    • area

      public double area()
    • width

      public double width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public double height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component
    • intArea

      public int intArea()
    • intWidth

      public int intWidth()
      Returns:
      Rounded width.
    • intHeight

      public int intHeight()
      Returns:
      Rounded height.
    • inverted

      public Size inverted()
      Returns:
      New instance with swapped width and height.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if either dimension is < 0.5.
    • longArea

      public long longArea()
    • longWidth

      public long longWidth()
      Returns:
      Rounded width.
    • longHeight

      public long longHeight()
      Returns:
      Rounded height.
    • scaled

      public Size scaled(double amount)
      Rescales both dimensions by the given amount.
      Parameters:
      amount - Positive number with 1 indicating no scale.
      Returns:
      New instance.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.