Class ContourPlot.Utils

  • Enclosing class:
    ContourPlot

    public static class ContourPlot.Utils
    extends java.lang.Object
    Class containing utility methods
    Author:
    hageldave
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double clamp​(double lower, double v, double upper)
      Clamps value between specified bounds
      static float clamp​(float lower, float v, float upper)
      Clamps value between specified bounds
      static int clamp​(int lower, int v, int upper)
      Clamps value between specified bounds
      static <T extends java.awt.geom.Point2D>
      T
      copy​(T p)
      Copies the specified Point2D (calls clone) and casts the copy to the class of the original.
      static double hypot​(double x, double y)
      Calculates sqrt(x*x + y*y) which is the hypotenuse length given catheti x and y.
      static java.awt.image.ImageObserver imageObserver​(int flags)
      Creates an ImageObserver that checks the for the specified infoflags.
      static <T extends java.lang.Comparable<T>>
      boolean
      isSorted​(java.util.Iterator<T> iter)
      Checks if specified iterator is sorted according to natural ordering.
      static double max3​(double v0, double v1, double v2)
      Returns the maximum of 3 values
      static double min3​(double v0, double v1, double v2)
      Returns the minimum of 3 values
      static <T> java.util.stream.Stream<T> parallelize​(java.util.stream.Stream<T> stream, boolean parallel)
      Syntactic sugar for conditional stream.parallel().
      private static boolean pointInTri​(double px, double py, double x0, double y0, double x1, double y1, double x2, double y2)  
      static boolean rectIntersectsOrIsContainedInTri​(java.awt.geom.Rectangle2D rect, double x0, double y0, double x1, double y1, double x2, double y2)
      tests intersection or containment of rectangle and triangle.
      private static double sign​(double x1, double y1, double x2, double y2, double x3, double y3)  
      static <P extends java.awt.geom.Point2D>
      P
      swapYAxis​(P point, int height)
      Swaps between GL and AWT coordinates, AWT coordinate system has its origin in the top left corner of a component and downwards pointing y axis, whereas GL has its origin in the bottom left corner of the viewport (at least in JPlotter) and upwards pointing y axis.
      • 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

      • copy

        public static <T extends java.awt.geom.Point2D> T copy​(T p)
        Copies the specified Point2D (calls clone) and casts the copy to the class of the original.
        Type Parameters:
        T - type of Point2D
        Parameters:
        p - point to copy
        Returns:
        the copied point
      • copy

        public static <T extends java.awt.geom.RectangularShape> T copy​(T r)
        Copies the specified RectangularShape (calls clone) and casts the copy to the class of the original.
        Type Parameters:
        T - type of RectangularShape
        Parameters:
        r - rectangle to copy
        Returns:
        the copied rectangle
      • isSorted

        public static <T extends java.lang.Comparable<T>> boolean isSorted​(java.util.Iterator<T> iter)
        Checks if specified iterator is sorted according to natural ordering.
        Type Parameters:
        T - element type that implements Comparable
        Parameters:
        iter - iterator
        Returns:
        true if sorted, false otherwise
      • parallelize

        public static <T> java.util.stream.Stream<T> parallelize​(java.util.stream.Stream<T> stream,
                                                                 boolean parallel)
        Syntactic sugar for conditional stream.parallel().
        Type Parameters:
        T - element type of stream
        Parameters:
        stream - to make parallel
        parallel - whether to make parallel or not
        Returns:
        stream.parallel() if true
      • clamp

        public static double clamp​(double lower,
                                   double v,
                                   double upper)
        Clamps value between specified bounds
        Parameters:
        lower - minimum value
        v - value to clamp
        upper - maximum value
        Returns:
        max(lower,min(upper,v))
      • clamp

        public static float clamp​(float lower,
                                  float v,
                                  float upper)
        Clamps value between specified bounds
        Parameters:
        lower - minimum value
        v - value to clamp
        upper - maximum value
        Returns:
        max(lower,min(upper,v))
      • clamp

        public static int clamp​(int lower,
                                int v,
                                int upper)
        Clamps value between specified bounds
        Parameters:
        lower - minimum value
        v - value to clamp
        upper - maximum value
        Returns:
        max(lower,min(upper,v))
      • min3

        public static double min3​(double v0,
                                  double v1,
                                  double v2)
        Returns the minimum of 3 values
        Parameters:
        v0 - value
        v1 - value
        v2 - value
        Returns:
        minimum
      • max3

        public static double max3​(double v0,
                                  double v1,
                                  double v2)
        Returns the maximum of 3 values
        Parameters:
        v0 - value
        v1 - value
        v2 - value
        Returns:
        maximum
      • rectIntersectsOrIsContainedInTri

        public static boolean rectIntersectsOrIsContainedInTri​(java.awt.geom.Rectangle2D rect,
                                                               double x0,
                                                               double y0,
                                                               double x1,
                                                               double y1,
                                                               double x2,
                                                               double y2)
        tests intersection or containment of rectangle and triangle.
        Parameters:
        rect - rectangle to test
        x0 - x coordinate of 0th triangle vertex
        y0 - y coordinate of 0th triangle vertex
        x1 - x coordinate of 1st triangle vertex
        y1 - y coordinate of 1st triangle vertex
        x2 - x coordinate of 2nd triangle vertex
        y2 - y coordinate of 2nd triangle vertex
        Returns:
        true when intersecting
      • sign

        private static double sign​(double x1,
                                   double y1,
                                   double x2,
                                   double y2,
                                   double x3,
                                   double y3)
      • pointInTri

        private static boolean pointInTri​(double px,
                                          double py,
                                          double x0,
                                          double y0,
                                          double x1,
                                          double y1,
                                          double x2,
                                          double y2)
      • imageObserver

        public static java.awt.image.ImageObserver imageObserver​(int flags)
        Creates an ImageObserver that checks the for the specified infoflags. See ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int).
        Parameters:
        flags - infoflags to check
        Returns:
        a new ImageObserver
      • hypot

        public static final double hypot​(double x,
                                         double y)
        Calculates sqrt(x*x + y*y) which is the hypotenuse length given catheti x and y.
        Parameters:
        x - a value
        y - a value
        Returns:
        hypotenuse length
      • swapYAxis

        public static <P extends java.awt.geom.Point2D> P swapYAxis​(P point,
                                                                    int height)
        Swaps between GL and AWT coordinates, AWT coordinate system has its origin in the top left corner of a component and downwards pointing y axis, whereas GL has its origin in the bottom left corner of the viewport (at least in JPlotter) and upwards pointing y axis.
        Type Parameters:
        P - type of Point2D
        Parameters:
        point - to swap the y axis of
        height - of the component or viewport
        Returns:
        point in coordinates of the other reference coordinate system.