Is Overlap "and" operator

Hi,

I was wondering why we use an “and” operator instead of an “or” operator in the if statement for an overlap? Wouldn’t an overlap exist if either of these conditions are met?

Cheers.

Please define what you mean by “overlap”, and can you point to where you saw this in the course materials?

Hi, this is in the trigger word coding assignment where the block of code looks to see if the segment being overlaid overlaps with a previous segment. There is a conditional if statement that captures the overlap using start and end points for the current segment and the previous one.

Thanks for the additional details.

Keep in mind that the new sound clip could start either before or after another segment. It is not necessarily only a later time.

“and” is used in this logic because there is only an overlap if the end of clip A is before the start of clip B, and also the end of clip B is after the start of clip A.

You might be able to understand the logic better if you take two slips of paper, label them A and B, and slide them around into different positions.

This might be a better description.
The two logic cases of the ‘and’ logic come from:

  • when clip B starts after clip A
  • when clip B starts before clip A

I initially had the same thought so I’m adding this in case it helps.

In my case, I was assuming that the segments would come into this function as ordered by start time.

If you do not make this assumption and considering that the new segment can start before, during or after the previous segment it’s easier to understand the logic of “and”. This is:

  • if ‘new’ starts before ‘previous’ ends, you want to check if the whole ‘new’ segment happens before ‘previous’ or if the ending of ‘new’ overlaps with the beginning of ‘previous’

  • if ‘new’ ends after ‘previous’ starts, you want to check if the whole ‘new’ segment happens after ‘previous’ or if the beginning of ‘new’ overlaps with the ending of ‘previous’