Exemple #1
0
        public static double Project(this Range <long> fromRange, long value, Range <double> targetRange)
        {
            long   num1 = RangeHelper.Size(fromRange);
            double num2 = RangeHelper.Size(targetRange);

            if (num1 == 0L || num2 == 0.0)
            {
                return(targetRange.Minimum);
            }
            DoubleR10 doubleR10 = (DoubleR10)(value - fromRange.Minimum) / (DoubleR10)num1;

            return(targetRange.Minimum + (double)doubleR10 * num2);
        }
Exemple #2
0
        public static long Project(this Range <double> fromRange, double value, Range <long> targetRange)
        {
            double num1 = RangeHelper.Size(fromRange);
            long   num2 = RangeHelper.Size(targetRange);

            if (num1 == 0.0 || num2 == 0L)
            {
                return(targetRange.Minimum);
            }
            double num3 = (value - fromRange.Minimum) / num1;

            return(targetRange.Minimum + (long)(num3 * (double)num2));
        }
Exemple #3
0
        public static void BoxRangeInsideAnother(ref double min, ref double max, double outerMin, double outerMax, double minSize, double maxSize, double precision = 0.0)
        {
            RangeHelper.Normalize(ref min, ref max);
            RangeHelper.Normalize(ref outerMin, ref outerMax);
            double num1 = max - min;

            if (num1 < minSize)
            {
                max = min + minSize;
            }
            else if (num1 > maxSize)
            {
                max = min + maxSize;
            }
            double num2 = outerMax - outerMin;

            if (num1 > num2)
            {
                min = outerMin;
                max = outerMax;
            }
            else if (min < outerMin)
            {
                min = outerMin;
                max = outerMin + num1;
            }
            else if (max > outerMax)
            {
                max = outerMax;
                min = outerMax - num1;
            }
            if (precision <= 0.0)
            {
                return;
            }
            double num3 = num1 * precision;

            if (min - outerMin < num3)
            {
                min = outerMin;
            }
            if (outerMax - max >= num3)
            {
                return;
            }
            max = outerMax;
        }
Exemple #4
0
        public static double Project(this Range <double> fromRange, double value, Range <double> targetRange)
        {
            double d1 = RangeHelper.Size(fromRange);
            double d2 = RangeHelper.Size(targetRange);

            if (d1 == 0.0 || d2 == 0.0)
            {
                if (fromRange.Minimum <= value && value <= fromRange.Maximum)
                {
                    return(targetRange.Minimum);
                }
                return(double.NaN);
            }
            if (double.IsInfinity(d1) || double.IsInfinity(d2))
            {
                return(RangeHelper.ProjectOverflowingDoubles(fromRange, value, targetRange));
            }
            double num = (value - fromRange.Minimum) / d1;

            return(targetRange.Minimum + num * d2);
        }