private static void AddIntentsToElement(Element element, double[] allPointsTimeOrdered, Curve levelCurve, ColorGradient colorGradient, TimeSpan duration, EffectIntents elementData, bool allowZeroIntensity, Color? color = null)
{
if (element != null)
{
double lastPosition = allPointsTimeOrdered[0];
TimeSpan lastEnd = TimeSpan.Zero;
for (var i = 1; i < allPointsTimeOrdered.Length; i++)
{
double position = allPointsTimeOrdered[i];
TimeSpan startTime = lastEnd;
TimeSpan timeSpan = TimeSpan.FromMilliseconds(duration.TotalMilliseconds * (position - lastPosition));
if (color == null)
{
var startColor = colorGradient.GetColorAt(lastPosition);
var endColor = colorGradient.GetColorAt(position);
var startIntensity = levelCurve.GetValue(lastPosition * 100) / 100;
var endIntensity = levelCurve.GetValue(position * 100) / 100;
if (allowZeroIntensity || !(startIntensity.Equals(0) && endIntensity.Equals(0)))
{
IIntent intent = IntentBuilder.CreateIntent(startColor, endColor, startIntensity, endIntensity, timeSpan);
elementData.AddIntentForElement(element.Id, intent, startTime);
}
}
else
{
var startIntensity = (colorGradient.GetProportionOfColorAt(lastPosition, (Color)color) * levelCurve.GetValue(lastPosition * 100) / 100);
var endIntensity = (colorGradient.GetProportionOfColorAt(position, (Color)color) * levelCurve.GetValue(position * 100) / 100);
if (allowZeroIntensity || !(startIntensity.Equals(0) && endIntensity.Equals(0)))
{
IIntent intent = IntentBuilder.CreateDiscreteIntent((Color)color, startIntensity, endIntensity, timeSpan);
elementData.AddIntentForElement(element.Id, intent, startTime);
}
}
lastPosition = position;
lastEnd = startTime + timeSpan;
}
}
}