rlottie/trim: Fix trim segment calculation.

In AE start and end value can naver be -ve. but the final
start and end value after applting interpolator curve could be -ve.

So refactor to always take the -ve value into account.
This commit is contained in:
subhransu mohanty 2019-05-23 09:54:16 +09:00 committed by Subhransu
parent 0fa16936d1
commit 281d3f3a00

View File

@ -768,44 +768,43 @@ public:
if (vCompare(diff, 0.0f)) return Segment(0, 0); if (vCompare(diff, 0.0f)) return Segment(0, 0);
if (vCompare(diff, 1.0f)) return Segment(0, 1); if (vCompare(diff, 1.0f)) return Segment(0, 1);
// no offset case if (offset > 0) {
if (vCompare(fabs(offset), 0.0f)) { start += offset;
return noloop(start, end); end += offset;
} else { if (start <= 1 && end <=1) {
if (offset > 0) { return noloop(start, end);
start += offset; } else if (start > 1 && end > 1) {
end += offset; return noloop(start - 1, end - 1);
if (start <= 1 && end <=1) {
return noloop(start, end);
} else if (start > 1 && end > 1) {
return noloop(start - 1, end - 1);
} else {
if (start > 1) return loop(start - 1 , end);
else return loop(start , end - 1);
}
} else { } else {
start += offset; if (start > 1) return loop(start - 1 , end);
end += offset; else return loop(start , end - 1);
if (start >= 0 && end >= 0) { }
return noloop(start, end); } else {
} else if (start < 0 && end < 0) { start += offset;
return noloop(-start, -end); end += offset;
} else { if (start >= 0 && end >= 0) {
if (start < 0) return loop(1 + start, end); return noloop(start, end);
else return loop(start , 1 + end); } else if (start < 0 && end < 0) {
} return noloop(1 + start, 1 + end);
} else {
if (start < 0) return loop(1 + start, end);
else return loop(start , 1 + end);
} }
} }
} }
LOTTrimData::TrimType type() const {return mTrimType;} LOTTrimData::TrimType type() const {return mTrimType;}
private: private:
Segment noloop(float start, float end) const{ Segment noloop(float start, float end) const{
assert(start >= 0);
assert(end >= 0);
Segment s; Segment s;
s.start = std::min(start, end); s.start = std::min(start, end);
s.end = std::max(start, end); s.end = std::max(start, end);
return s; return s;
} }
Segment loop(float start, float end) const{ Segment loop(float start, float end) const{
assert(start >= 0);
assert(end >= 0);
Segment s; Segment s;
s.start = std::max(start, end); s.start = std::max(start, end);
s.end = std::min(start, end); s.end = std::min(start, end);