float AnimationSegment::overlap( const AnimationSegment& seg ) const { if( mAnim != seg.getAnimation() ) return 0; AnimationSegment seg1 = *this, seg2 = seg; if( seg2.mStartTime < seg1.mStartTime ) std::swap( seg1, seg2 ); float l_int = 0; // length of the intersection if( seg2.mStartTime < seg1.mEndTime ) { if( seg2.mEndTime <= seg1.mEndTime ) l_int = seg2.mEndTime - seg2.mStartTime; else l_int = seg1.mEndTime - seg2.mStartTime; } float l_seg = std::min<float>( seg1.mEndTime - seg1.mStartTime, seg2.mEndTime - seg2.mStartTime ); // length of the shorter segment return l_int/l_seg; }
AnimationSegment AnimationSegment::merge( const AnimationSegment& seg ) const { if( mAnim != seg.getAnimation() ) return AnimationSegment( mAnim, 0, 0 ); AnimationSegment seg1 = *this, seg2 = seg; if( seg2.mStartTime < seg1.mStartTime ) std::swap( seg1, seg2 ); if( seg2.mStartTime < seg1.mEndTime ) { if( seg2.mEndTime <= seg1.mEndTime ) return seg1; else return AnimationSegment( mAnim, seg1.mStartTime, seg2.mEndTime ); } return AnimationSegment( mAnim, 0, 0 ); }