Class FlowUtil


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

      Constructors 
      Constructor Description
      FlowUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double[] reduceFlow​(double[] flow, int targetLength)
      Reduction causes loss of information, so the resulting flow is always 'good enough', but is not quaranteed to be equivalent, just a shorter version of the original flow
      static double[] stretchFlow​(double[] flow, int targetLength)
      Stretch flow to longer length.
      static double[] stretchFlow​(double[] flow, int targetLength, java.util.function.Function<java.lang.Double,​java.lang.Double> modifier)
      Stretch flow to longer length.
      • Methods inherited from class java.lang.Object

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

      • FlowUtil

        public FlowUtil()
    • Method Detail

      • stretchFlow

        public static double[] stretchFlow​(double[] flow,
                                           int targetLength)
        Stretch flow to longer length. Tries to fill the caps with averages.

        This is an unintuitive method, because it turns out that, for example, array size of 3 scales better to array size of 5 than it does to array size of 6. [1, 2, 3] can be easily scaled to [1, 1.5, 2, 2.5, 3], but it's not possible without recalculating middle number (2) with array size of 6, simplistic solutions quickly would run to trouble like this [1, 1.5, 2, 2.5, 3, (3)? ] or maybe: [1, 1.5, 2, 2.5, ..., 3 ]. The correct solution would correctly scale the middle numbers

        Parameters:
        flow - the original flow
        targetLength - the resulting flow length
        Returns:
        the resulting flow
      • stretchFlow

        public static double[] stretchFlow​(double[] flow,
                                           int targetLength,
                                           java.util.function.Function<java.lang.Double,​java.lang.Double> modifier)
        Stretch flow to longer length. Tries to fill the caps with averages.

        This is an unintuitive method, because it turns out that, for example, array size of 3 scales better to array size of 5 than it does to array size of 6. [1, 2, 3] can be easily scaled to [1, 1.5, 2, 2.5, 3], but it's not possible without recalculating middle number (2) with array size of 6, simplistic solutions quickly would run to trouble like this [1, 1.5, 2, 2.5, 3, (3)? ] or maybe: [1, 1.5, 2, 2.5, ..., 3 ]. The correct solution would correctly scale the middle numbers over several indexes.

        Parameters:
        flow - the original flow
        targetLength - the resulting flow length
        modifier - modifies the resulting values, you can use this to provide noise or amplify the flow characteristics.
        Returns:
        the resulting flow
      • reduceFlow

        public static double[] reduceFlow​(double[] flow,
                                          int targetLength)
        Reduction causes loss of information, so the resulting flow is always 'good enough', but is not quaranteed to be equivalent, just a shorter version of the original flow
        Parameters:
        flow - the original flow
        targetLength - the resulting array length
        Returns:
        the resulting flow