| 81 | } |
| 82 | |
| 83 | bool Image::overlaps(const Image& other) const |
| 84 | { |
| 85 | if (!*this || !other) |
| 86 | return false; |
| 87 | |
| 88 | // If any of the images are not backed by non-shared buffers, we cannot determine whether they |
| 89 | // overlap due to potential virtual address aliasing, so we conservatively assume they do |
| 90 | if (!buffer || buffer->isShared() || !other.buffer || other.buffer->isShared()) |
| 91 | return true; |
| 92 | |
| 93 | // If the images are backed by different non-shared buffers, they cannot overlap |
| 94 | if (buffer != other.buffer) |
| 95 | return false; |
| 96 | |
| 97 | // Check whether the memory ranges inside the same buffer overlap |
| 98 | const char* begin1 = ptr; |
| 99 | const char* end1 = ptr + getByteSize(); |
| 100 | const char* begin2 = other.ptr; |
| 101 | const char* end2 = other.ptr + other.getByteSize(); |
| 102 | |
| 103 | return begin1 < end2 && begin2 < end1; |
| 104 | } |
| 105 | |
| 106 | OIDN_NAMESPACE_END |
no test coverage detected