Fixed errors occurring with zero-length files

This commit is contained in:
Daniel Wolf 2017-01-02 10:37:31 +01:00
parent 3bc4384b44
commit da11232c31
2 changed files with 13 additions and 12 deletions

View File

@ -2,23 +2,20 @@
#include "animationRules.h" #include "animationRules.h"
JoiningContinuousTimeline<Shape> insertTweens(const JoiningContinuousTimeline<Shape>& animation) { JoiningContinuousTimeline<Shape> insertTweens(const JoiningContinuousTimeline<Shape>& animation) {
centiseconds minTweenDuration = 4_cs; const centiseconds minTweenDuration = 4_cs;
centiseconds maxTweenDuration = 8_cs; const centiseconds maxTweenDuration = 8_cs;
JoiningContinuousTimeline<Shape> result(animation); JoiningContinuousTimeline<Shape> result(animation);
for (auto first = animation.begin(), second = std::next(animation.begin()); for_each_adjacent(animation.begin(), animation.end(), [&](const auto& first, const auto& second) {
first != animation.end() && second != animation.end(); auto pair = getTween(first.getValue(), second.getValue());
++first, ++second) if (!pair) return;
{
auto pair = getTween(first->getValue(), second->getValue());
if (!pair) continue;
Shape tweenShape; Shape tweenShape;
TweenTiming tweenTiming; TweenTiming tweenTiming;
std::tie(tweenShape, tweenTiming) = *pair; std::tie(tweenShape, tweenTiming) = *pair;
TimeRange firstTimeRange = first->getTimeRange(); TimeRange firstTimeRange = first.getTimeRange();
TimeRange secondTimeRange = second->getTimeRange(); TimeRange secondTimeRange = second.getTimeRange();
centiseconds tweenStart, tweenDuration; centiseconds tweenStart, tweenDuration;
switch (tweenTiming) { switch (tweenTiming) {
@ -39,10 +36,10 @@ JoiningContinuousTimeline<Shape> insertTweens(const JoiningContinuousTimeline<Sh
} }
} }
if (tweenDuration < minTweenDuration) continue; if (tweenDuration < minTweenDuration) return;
result.set(tweenStart, tweenStart + tweenDuration, tweenShape); result.set(tweenStart, tweenStart + tweenDuration, tweenShape);
} });
return result; return result;
} }

View File

@ -5,6 +5,7 @@
#include <format.h> #include <format.h>
#include <iostream> #include <iostream>
#include <boost/algorithm/clamp.hpp> #include <boost/algorithm/clamp.hpp>
#include <cmath>
using std::string; using std::string;
@ -62,6 +63,9 @@ ProgressBar::~ProgressBar() {
void ProgressBar::reportProgress(double value) { void ProgressBar::reportProgress(double value) {
// Make sure value is in [0..1] range // Make sure value is in [0..1] range
value = boost::algorithm::clamp(value, 0.0, 1.0); value = boost::algorithm::clamp(value, 0.0, 1.0);
if (std::isnan(value)) {
value = 0.0;
}
currentProgress = value; currentProgress = value;
} }