Class Dimensions


  • public class Dimensions
    extends java.lang.Object
    A measurement of an object's width, height, and depth along the X, Y, and Z dimensions, respectively.

    Dimensions of zero dimensions are considered equal regardless of the units involved.

    Author:
    Garret Wilson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Dimensions ZERO_DIMENSIONS
      A convenience dimensions of zero pixel size.
    • Constructor Summary

      Constructors 
      Constructor Description
      Dimensions​(double width, double height, double depth, Unit unit)
      Width, height, and depth unit constructor.
      Dimensions​(double width, double height, Unit unit)
      Width and height unit constructor with a depth of one.
      Dimensions​(double width, Unit widthUnit, double height, Unit heightUnit)
      Width unit and height unit constructor with a depth of one.
      Dimensions​(Extent width, Extent height)
      Width and height extent constructor with a default depth of zero pixels.
      Dimensions​(Extent width, Extent height, Extent depth)
      Width, height, and depth extent constructor.
    • Field Detail

      • ZERO_DIMENSIONS

        public static final Dimensions ZERO_DIMENSIONS
        A convenience dimensions of zero pixel size.
    • Constructor Detail

      • Dimensions

        public Dimensions​(double width,
                          double height,
                          Unit unit)
        Width and height unit constructor with a depth of one.
        Parameters:
        width - The width.
        height - The height.
        unit - The unit with which the extent is measured.
        Throws:
        java.lang.NullPointerException - if the given unit is null.
      • Dimensions

        public Dimensions​(double width,
                          Unit widthUnit,
                          double height,
                          Unit heightUnit)
        Width unit and height unit constructor with a depth of one.
        Parameters:
        width - The width.
        widthUnit - The unit with which the width is measured.
        height - The height.
        heightUnit - The unit with which the height is measured.
        Throws:
        java.lang.NullPointerException - if the given width unit and/or height unit is null.
      • Dimensions

        public Dimensions​(double width,
                          double height,
                          double depth,
                          Unit unit)
        Width, height, and depth unit constructor.
        Parameters:
        width - The width.
        height - The height.
        depth - The depth.
        unit - The unit with which the extent is measured.
        Throws:
        java.lang.NullPointerException - if the given unit is null.
      • Dimensions

        public Dimensions​(Extent width,
                          Extent height)
        Width and height extent constructor with a default depth of zero pixels.
        Parameters:
        width - The width extent.
        height - The height extent.
        Throws:
        java.lang.NullPointerException - if the given width, and/or height is null.
        java.lang.IllegalArgumentException - if the degree of any extent is not 1.
      • Dimensions

        public Dimensions​(Extent width,
                          Extent height,
                          Extent depth)
        Width, height, and depth extent constructor.
        Parameters:
        width - The width extent.
        height - The height extent.
        depth - The depth extent.
        Throws:
        java.lang.NullPointerException - if the given width, height, and/or depth is null.
        java.lang.IllegalArgumentException - if the degree of any extent is not 1.
    • Method Detail

      • getWidth

        public Extent getWidth()
        Returns:
        The width extent.
      • getHeight

        public Extent getHeight()
        Returns:
        The height extent.
      • getDepth

        public Extent getDepth()
        Returns:
        The depth extent.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if all extents of the dimensions are zero.
        See Also:
        Extent.isEmpty()
      • constrain

        public Dimensions constrain​(Dimensions constrainingDimensions)
        Constrains these inner dimensions within the given outer dimensions by scaling these dimensions so that no part lies outside the given outer dimensiona. This implementation currently only supports two dimensions.
        Parameters:
        constrainingDimensions - The outer constraining dimensions.
        Returns:
        A dimension representing the constrained dimension.
        Throws:
        java.lang.NullPointerException - if the given constraining dimensions is null.
        java.lang.IllegalArgumentException - if the given constraining dimensions use different units than these dimensions.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object object)

        This implementation returns whether the object is another dimensions with identical width, height, and depth.

        Overrides:
        equals in class java.lang.Object
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Object