Only if we know about the mathematical logic behind the terms (contains and overlaps), we could compare the mathematical logic and what your code are doing.
We cant go to Wikipedia and check the terms first, you should provide them, you should provide the original problem :-)