Example #1
0
 public PiecewiseFunction(IEnumerable <Vector2> definedPoints, InterpolationBehavior interpolation, ExtrapolationBehavior leftExtrapolation, ExtrapolationBehavior rightExtrapolation)
 {
     _definedPoints = definedPoints.ToArray();
     if (_definedPoints.Length <= 0)
     {
         throw new ArgumentException("At least one defined value must be supplied.");
     }
     Array.Sort(_definedPoints, (a, b) => a.X.CompareTo(b.X));
     _interpolation      = interpolation;
     _leftExtrapolation  = leftExtrapolation;
     _rightExtrapolation = rightExtrapolation;
     _period             = double.NaN;
 }
Example #2
0
 public PiecewiseFunction(double period, IEnumerable <Vector2> definedPoints) // TODO: allow other interpolation styles
 {
     if (double.IsNaN(period) || double.IsInfinity(period) || period <= 0)
     {
         throw new ArgumentOutOfRangeException();
     }
     _definedPoints = definedPoints.Select(p => new Vector2(NormalizePeriodicArgument(period, p.X), p.Y)).ToArray();
     if (_definedPoints.Length <= 0)
     {
         throw new ArgumentException("At least one defined value must be supplied.");
     }
     Array.Sort(_definedPoints, (a, b) => a.X.CompareTo(b.X));
     _interpolation      = InterpolationBehavior.Linear;
     _leftExtrapolation  = ExtrapolationBehavior.NotDefined;
     _rightExtrapolation = ExtrapolationBehavior.NotDefined;
     _period             = period;
 }