Table of Contents

Method Interpolate

Namespace
Gamelogic.Extensions.Algorithms
Assembly
Gamelogic.Extensions.dll

Interpolate<TSource>(IGenerator<TSource>, int, Func<TSource, TSource, float, TSource>)

Makes a generator that interpolates between values of a given generator.

public static IGenerator<TSource> Interpolate<TSource>(this IGenerator<TSource> generator, int sampleCount, Func<TSource, TSource, float, TSource> interpolater)

Parameters

generator IGenerator<TSource>

The source generator.

sampleCount int

The sample count per cycle.

interpolater Func<TSource, TSource, float, TSource>

The interpolater function. This function takes three arguments: the first two are the left and right endpoints, and the third is a fraction between 0 and 1. For typical interpolation, the function must return the left endpoint if this fraction is 0, and the right endpoint if the fraction is 1.

Returns

IGenerator<TSource>

A new generator.

Type Parameters

TSource

The type of elements to generate.

Examples

var baseGenerator = Generator.Count(2); //Generates 0 1 0 1 0 1...
var interpolatedGenerator = 
	baseGenerator.Interpolate(2, (x, y, t) => x*(1 - t) + y*t); //Generates 0 0.5f 1 0.5f 0 0.5f....

Remarks

The expression (x, y, t) => x*(1 - t) + y*t) is standard linear interpolation.

Exceptions

ArgumentNullException

generator is $(null).

ArgumentOutOfRangeException

sampleCount not positive.

ArgumentNullException

interpolater is $(null).

Interpolate<TSource>(IGenerator<TSource>, IGenerator<int>, Func<TSource, TSource, float, TSource>)

Makes a generator that interpolates between values of a given generator.

public static IGenerator<TSource> Interpolate<TSource>(this IGenerator<TSource> generator, IGenerator<int> sampleCount, Func<TSource, TSource, float, TSource> interpolater)

Parameters

generator IGenerator<TSource>
sampleCount IGenerator<int>
interpolater Func<TSource, TSource, float, TSource>

Returns

IGenerator<TSource>

Type Parameters

TSource