! @excsafety{No-fail} */
| 394 | |
| 395 | /*! @excsafety{No-fail} */ |
| 396 | void Envelope::CollapseRegion(double t0, double t1, double sampleDur) noexcept |
| 397 | { |
| 398 | if ( t1 <= t0 ) |
| 399 | return; |
| 400 | |
| 401 | // This gets called when somebody clears samples. |
| 402 | |
| 403 | // Snip points in the interval (t0, t1), shift values left at times after t1. |
| 404 | // For the boundaries of the interval, preserve the left-side limit at the |
| 405 | // start and right-side limit at the end. |
| 406 | |
| 407 | const auto epsilon = sampleDur / 2; |
| 408 | t0 = std::max( 0.0, std::min( mTrackLen, t0 - mOffset ) ); |
| 409 | t1 = std::max( 0.0, std::min( mTrackLen, t1 - mOffset ) ); |
| 410 | bool leftPoint = true, rightPoint = true; |
| 411 | |
| 412 | // Determine the start of the range of points to remove from the array. |
| 413 | auto range0 = EqualRange(t0, 0); |
| 414 | auto begin = range0.first; |
| 415 | if ( begin == range0.second ) { |
| 416 | if ( t0 > epsilon ) { |
| 417 | // There was no point exactly at t0; |
| 418 | // insert a point to preserve the value. |
| 419 | auto val = GetValueRelative( t0 ); |
| 420 | InsertOrReplaceRelative( t0, val ); |
| 421 | ++begin; |
| 422 | } |
| 423 | else |
| 424 | leftPoint = false; |
| 425 | } |
| 426 | else |
| 427 | // We will keep the first (or only) point that was at t0. |
| 428 | ++begin; |
| 429 | |
| 430 | // We want end to be the index one past the range of points to remove from |
| 431 | // the array. |
| 432 | // At first, find index of the first point after t1: |
| 433 | auto range1 = EqualRange( t1, 0 ); |
| 434 | auto end = range1.second; |
| 435 | if ( range1.first == end ) { |
| 436 | if ( mTrackLen - t1 > epsilon ) { |
| 437 | // There was no point exactly at t1; insert a point to preserve the value. |
| 438 | auto val = GetValueRelative( t1 ); |
| 439 | InsertOrReplaceRelative( t1, val ); |
| 440 | // end is now the index of this NEW point and that is correct. |
| 441 | } |
| 442 | else |
| 443 | rightPoint = false; |
| 444 | } |
| 445 | else |
| 446 | // We will keep the last (or only) point that was at t1. |
| 447 | --end; |
| 448 | |
| 449 | if ( end < begin ) { |
| 450 | if ( leftPoint ) |
| 451 | rightPoint = false; |
| 452 | } |
| 453 | else |
no test coverage detected