Class RectSizeLimits

java.lang.Object
jme3utilities.math.RectSizeLimits

public class RectSizeLimits extends Object
Limits on the size of a non-degenerate rectangle. Immutable.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    maximum height (≥minHeight)
    final int
    maximum width (≥minWidth)
    final int
    minimum height (≤maxHeight)
    final int
    minimum width (≤maxWidth)
  • Constructor Summary

    Constructors
    Constructor
    Description
    RectSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight)
    Instantiate a set of limits.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    clampHeight(int height)
    Clamp the specified height to the limits.
    int
    clampWidth(int width)
    Clamp the specified width to the limits.
    boolean
    equals(Object otherObject)
    Test for exact equivalence with another Object.
    feedbackInRange(int width, int height)
    Explain why the specified size is invalid.
    int
    Generate the hash code for these limits.
    boolean
    isInRange(int width, int height)
    Test the validity of the specified dimensions.
    Represent these limits as a text string.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • maxHeight

      public final int maxHeight
      maximum height (≥minHeight)
    • maxWidth

      public final int maxWidth
      maximum width (≥minWidth)
    • minHeight

      public final int minHeight
      minimum height (≤maxHeight)
    • minWidth

      public final int minWidth
      minimum width (≤maxWidth)
  • Constructor Details

    • RectSizeLimits

      public RectSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight)
      Instantiate a set of limits.
      Parameters:
      minWidth - the desired minimum width (>0, ≤maxWidth)
      minHeight - the desired minimum height (>0, ≤maxHeight)
      maxWidth - the desired maximum width (≥minWidth)
      maxHeight - the desired maximum height (≥minHeight)
  • Method Details

    • clampHeight

      public int clampHeight(int height)
      Clamp the specified height to the limits.
      Parameters:
      height - the height to be clamped
      Returns:
      the value between minHeight and maxHeight inclusive that is closest to height
    • clampWidth

      public int clampWidth(int width)
      Clamp the specified width to the limits.
      Parameters:
      width - the width to be clamped
      Returns:
      the value between minWidth and maxWidth inclusive that is closest to width
    • feedbackInRange

      public String feedbackInRange(int width, int height)
      Explain why the specified size is invalid.
      Parameters:
      width - the width to test
      height - the height to test
      Returns:
      message text in English or "" if in range (not null)
    • isInRange

      public boolean isInRange(int width, int height)
      Test the validity of the specified dimensions.

      This test is inclusive, so both (minWidth, minHeight) and (maxWidth, maxHeight) are considered valid.

      Parameters:
      width - the width to test
      height - the height to test
      Returns:
      true if in range, otherwise false
    • equals

      public boolean equals(Object otherObject)
      Test for exact equivalence with another Object.
      Overrides:
      equals in class Object
      Parameters:
      otherObject - the object to compare to (may be null, unaffected)
      Returns:
      true if the objects are equivalent, otherwise false
    • hashCode

      public int hashCode()
      Generate the hash code for these limits.
      Overrides:
      hashCode in class Object
      Returns:
      the value to use for hashing
    • toString

      public String toString()
      Represent these limits as a text string.

      The format is: (minWidth, minHeight)-(maxWidth, maxHeight)

      Overrides:
      toString in class Object
      Returns:
      a descriptive string of text (not null)