Beispiel #1
0
        private double GetCalibratedValue(double keyValue, double epsilon = Extensions.EPSILON)
        {
            if (fDataRows != null && fDataRows.Length > 0)
            {
                double prevKey   = double.NaN;
                double prevValue = double.NaN;

                for (int i = 0; i < fDataRows.Length; i++)
                {
                    var row = fDataRows[i];

                    double currKey   = Convert.ToDouble(row[fKeyField]);
                    double currValue = Convert.ToDouble(row[fValueField]);

                    if (Extensions.Equals(currKey, keyValue, epsilon))
                    {
                        return(currValue);
                    }
                    else
                    {
                        if (i > 0)
                        {
                            if (Extensions.GreaterThan(keyValue, prevKey, epsilon) && Extensions.LessThan(keyValue, currKey, epsilon))
                            {
                                double hk = (keyValue - prevKey) / (currKey - prevKey);
                                double k  = prevValue + (currValue - prevValue) * hk;
                                return(k);
                            }
                        }
                    }

                    prevKey   = currKey;
                    prevValue = currValue;
                }

                return(double.NaN);
            }
            else
            {
                throw new ArgumentException("Table is empty");
            }
        }