Class Dimensions

java.lang.Object
io.guise.framework.geometry.Dimensions

public class Dimensions extends 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 Details

    • ZERO_DIMENSIONS

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

    • 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:
      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:
      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:
      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:
      NullPointerException - if the given width, and/or height is null.
      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:
      NullPointerException - if the given width, height, and/or depth is null.
      IllegalArgumentException - if the degree of any extent is not 1.
  • Method Details

    • 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:
    • 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:
      NullPointerException - if the given constraining dimensions is null.
      IllegalArgumentException - if the given constraining dimensions use different units than these dimensions.
    • hashCode

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

      public boolean equals(Object object)

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

      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object