Пример #1
0
        /// <summary>
        /// Factory method to create the required implementation of the interpolation algorithm
        /// </summary>
        /// <param name="fit">interpolation algorithm type</param>
        /// <param name="standards">Data points to be fitted</param>
        /// <returns>Interpolation algorithm</returns>
        public static Interpolator Create(CurveFits fit, IEnumerable <DPoint> standards)
        {
            Interpolator interp = null;
            //ensure points are sorted in order of x values
            List <DPoint> standardsList = new List <DPoint>(standards);

            standardsList.Sort((a, b) => a.X.CompareTo(b.X));
            switch (fit)
            {
            case CurveFits.Interpolate:
                interp = new SimpleInterpolator(standardsList);
                break;

            case CurveFits.LinearZero:
                interp = new BestLineThruOriginInterpolation(standardsList);
                break;

            case CurveFits.Linear:
                interp = new BestLineInterpolation(standardsList);
                break;

            case CurveFits.Quadratic:
                interp = new QuadraticInterpolator(standardsList);
                break;

            case CurveFits.QuadraticThruZero:
                interp = new QuadraticThruZeroInterpolator(standardsList);
                break;

            default:
                break;
            }
            return(interp);
        }
Пример #2
0
 /// <summary>
 /// Factory method to create the required implementation of the interpolation algorithm
 /// </summary>
 /// <param name="fit">interpolation algorithm type</param>
 /// <param name="standards">Data points to be fitted</param>
 /// <returns>Interpolation algorithm</returns>
 public static Interpolator Create(CurveFits fit, IEnumerable<DPoint> standards)
 {
     Interpolator interp = null;
     //ensure points are sorted in order of x values
     List<DPoint> standardsList = new List<DPoint>(standards);
     standardsList.Sort((a, b) => a.X.CompareTo(b.X));
     switch (fit)
     {
         case CurveFits.Interpolate:
             interp = new SimpleInterpolator(standardsList);
             break;
         case CurveFits.LinearZero:
             interp = new BestLineThruOriginInterpolation(standardsList);
             break;
         case CurveFits.Linear:
             interp = new BestLineInterpolation(standardsList);
             break;
         case CurveFits.Quadratic:
             interp = new QuadraticInterpolator(standardsList);
             break;
         case CurveFits.QuadraticThruZero:
             interp = new QuadraticThruZeroInterpolator(standardsList);
             break;
         default:
             break;
     }
     return interp;
 }
        public void InterpolatorCalculateTest()
        {
            List<DPoint> standards = new List<DPoint>();
            standards.Add(new DPoint(3, 2));
            standards.Add(new DPoint(4, 3));
            standards.Add(new DPoint(5, 6));
            standards.Add(new DPoint(6, 4));
            standards.Add(new DPoint(7, 5));
            SimpleInterpolator target = new SimpleInterpolator(standards);
            Assert.AreEqual(2, target.Calculate(3));
            Assert.AreEqual(3, target.Calculate(4));
            Assert.AreEqual(6, target.Calculate(5));
            Assert.AreEqual(4, target.Calculate(6));
            Assert.AreEqual(5, target.Calculate(7));

            //half-way between
            Assert.AreEqual(2.5, target.Calculate(3.5));
            Assert.AreEqual(4.5, target.Calculate(4.5));
            Assert.AreEqual(5, target.Calculate(5.5));
            Assert.AreEqual(4.5, target.Calculate(6.5));
        }