Beispiel #1
0
 /// <summary>
 /// Switch output between first input A and B based on threshold value.
 /// </summary>
 public static double Switch(double a, double b, double threshold, SwitchCriteriaEnum switchCriteria)
 {
     if (switchCriteria == SwitchCriteriaEnum.BIsGreaterThanThreshold && b > threshold ||
         switchCriteria == SwitchCriteriaEnum.BIsLessThanThreshold && b < threshold ||
         switchCriteria == SwitchCriteriaEnum.BIsGreaterOrEqualsThanThreshold && b >= threshold ||
         switchCriteria == SwitchCriteriaEnum.BIsLessOrEqualsThanThreshold && b <= threshold)
     {
         return(b);
     }
     return(a);
 }
Beispiel #2
0
        /// <summary>
        /// Switch output between first input A and B based on threshold value.
        /// </summary>
        public static double[] Switch(double[] a, double[] b, double threshold, SwitchCriteriaEnum switchCriteria)
        {
            var size   = Math.Max(a.Length, b.Length);
            var result = MemoryPool.Pool.New <double>(size);

            for (var i = 0; i < size; i++)
            {
                if (i < a.Length && i < b.Length)
                {
                    result[i] = Switch(a[i], b[i], threshold, switchCriteria);
                }
                else if (i < a.Length)
                {
                    result[i] = a[i];
                }
                else
                {
                    result[i] = b[i];
                }
            }
            return(result);
        }