Here's an image illustrating what I mean:

[![enter image description here](https://i.stack.imgur.com/kCvOq.png)](https://i.stack.imgur.com/kCvOq.png)

Basically I want to merge set1 into set2, but each interval from set1 is not allowed to exist unless it is contained within the bounds of an interval from set2. 

Any suggestions are greatly appreciated!

PS: My next task would be to figure out how to merge *n* number of \*set1\*s (i.e. green layers that may overlap with each other) into a set2 with the same rules applying... but I'll start with this first!