Class MathHelper

java.lang.Object
games.stendhal.common.MathHelper

public class MathHelper extends Object
Helper functions for various mathematical tasks.
  • Field Details

  • Constructor Details

    • MathHelper

      public MathHelper()
  • Method Details

    • parseDoubleDefault

      public static double parseDoubleDefault(String s, double def)
      Parses a double safely, returning a default if nothing can be sanely parsed from it.
      Parameters:
      s - the string to parse
      def - the default value
      Returns:
      double corresponding to s, or def if s can not be parsed to a double
    • parseDouble

      public static double parseDouble(String s)
      Parses a double safely, returning 0 if nothing can be sanely parsed from it.
      Parameters:
      s - the string to parse
      Returns:
      double corresponding to s, or 0 if s can not be parsed to a double
    • parseIntDefault

      public static int parseIntDefault(String s, int def)
      parses an integer safely. returning a default if nothing can be sanely parsed from it
      Parameters:
      s - the string to parse
      def - the default to set
      Returns:
      An integer
    • parseInt

      public static int parseInt(String s)
      parses an integer safely, returning 0 if nothing can be sanely parsed. from it
      Parameters:
      s - to parse
      Returns:
      An integer
    • parseLongDefault

      public static long parseLongDefault(String s, long def)
      parses a long safely. returning a default if nothing can be sanely parsed from it
      Parameters:
      s - the string to parse
      def - the default to set
      Returns:
      An integer
    • parseLong

      public static long parseLong(String s)
      parses a long safely, returning 0 if nothing can be sanely parsed. from it
      Parameters:
      s - to parse
      Returns:
      An integer
    • clamp

      public static int clamp(int value, int minValue, int maxValue)
      Limit an integer value to a specific range.
      Parameters:
      value - value to be limited
      minValue - minimum value. Should be <= maxValue.
      maxValue - maximum value. Should be >= minValue.
      Returns:
      if value is in range [minValue, maxValue], value is returned. Otherwise if value > maxValue, maxValue is returned, if value < minValue, minValue is returned.
    • clamp

      public static float clamp(float value, float minValue, float maxValue)
      Limit a float value to a specific range.
      Parameters:
      value - value to be limited
      minValue - minimum value. Should be <= maxValue.
      maxValue - maximum value. Should be >= minValue.
      Returns:
      if value is in range [minValue, maxValue], value is returned. Otherwise if value > maxValue, maxValue is returned, if value < minValue, minValue is returned.