Class NumberRange

java.lang.Object
etithespirit.orimod.api.util.valuetypes.NumberRange
Direct Known Subclasses:
MutableNumberRange

public class NumberRange extends Object
A value representing a range between two numbers [min, max]
Author:
Eti
  • Field Details

    • ZERO

      public static final NumberRange ZERO
      A NumberRange whose min and max are both zero. This can be used as a lazy default.
    • rng

      protected final Random rng
      A randomizer used for random()
    • min

      protected double min
      The minimum possible value this will return.
    • max

      protected double max
      The maximum possible value this will return.
  • Constructor Details

    • NumberRange

      public NumberRange(double min, double max) throws IllegalArgumentException
      Creates a new range between min and max, as well as a new randomizer for use in the random() method. If min is greater than max, an IllegalArgumentException is thrown.
      Parameters:
      min - The minimum possible value to contain.
      max - The maximum possible value to contain.
      Throws:
      IllegalArgumentException - If min is greater than max.
    • NumberRange

      public NumberRange(double min, double max, Random rng) throws IllegalArgumentException
      Creates a new range between min and max, using the given randomizer for the random() method. If min is greater than max, an IllegalArgumentException is thrown.
      Parameters:
      min - The minimum possible value to contain.
      max - The maximum possible value to contain.
      rng - The randomizer to use in the random() method.
      Throws:
      IllegalArgumentException - If min is greater than max.
  • Method Details

    • getMin

      public double getMin()
      Returns:
      The minimum possible value that this can return.
    • getMax

      public double getMax()
      Returns:
      The maximum possible value that this can return.
    • isSingular

      public boolean isSingular()
      Returns:
      Whether or not this has a range of zero, or, min is equal to max.
    • lerp

      public double lerp(double alpha)
      Returns the value of this range interpolated to the given percentage. This is unclamped and accepts alpha values outside of the range of 0-1.
      Parameters:
      alpha - The percentage to go from min to max.
      Returns:
      A value linearly interpolated from min to max by alpha percent.
    • random

      public double random()
      Returns:
      A random value in the range [min, max), unless min and max are equal, from which that value will be returned verbatim.
    • isMutable

      public boolean isMutable()
      Returns:
      Whether or not this NumberRange is able to have its minimum and maximum edited.
    • immutableCopy

      public NumberRange immutableCopy()
      Returns:
      A copy of this NumberRange as an immutable instance.
    • mutableCopy

      public MutableNumberRange mutableCopy()
      Returns:
      A copy of this NumberRange as a mutable instance.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object