Class Utils


  • public class Utils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int ceil​(double x)
      A fast implementation of Math.ceil(double).
      static double clamp​(double value, double min, double max)
      Clamp the value into the range [min..max].
      static java.awt.geom.Rectangle2D dilateRect​(java.awt.geom.Rectangle2D r, double marginX, double marginY)
      Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.
      static java.awt.Rectangle enlargeRectToGrid​(java.awt.geom.Rectangle2D r)
      Create a rectangle with the same area as the given input rectangle but with all of its edges snapped (rounded) to the integer grid.
      static int floor​(double x)
      A fast implementation of Math.floor(double).
      static int round​(double x)
      A fast implementation of Math.round(double).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • enlargeRectToGrid

        public static java.awt.Rectangle enlargeRectToGrid​(java.awt.geom.Rectangle2D r)
        Create a rectangle with the same area as the given input rectangle but with all of its edges snapped (rounded) to the integer grid. The resulting rectangle is guaranteed to cover all of the input rectangle's area, so that enlargeToGrid(r).contains(r) == true holds. This can be depicted as the edges being stretched in an outward direction.
        Parameters:
        r - the given rectangle
        Returns:
        the resulting rectangle
      • dilateRect

        public static java.awt.geom.Rectangle2D dilateRect​(java.awt.geom.Rectangle2D r,
                                                           double marginX,
                                                           double marginY)
        Return a new rectangle which covers the area of the given rectangle with an additional margin on the sides.
        Parameters:
        r - the given rectangle
        marginX - horizontal value of the additional margin
        marginY - vertical value of the additional margin
        Returns:
        the resulting rectangle
      • clamp

        public static double clamp​(double value,
                                   double min,
                                   double max)
        Clamp the value into the range [min..max].
        Parameters:
        value - input value
        min - minimal value
        max - maximal value
        Returns:
        the clamped value
      • floor

        public static int floor​(double x)
        A fast implementation of Math.floor(double).
        Parameters:
        x - the argument
        Returns:
        resulting floor value
      • round

        public static int round​(double x)
        A fast implementation of Math.round(double).
        Parameters:
        x - the argument
        Returns:
        rounded value
      • ceil

        public static int ceil​(double x)
        A fast implementation of Math.ceil(double).
        Parameters:
        x - the argument
        Returns:
        resulting ceil value