Created
March 22, 2020 18:03
-
-
Save chrisdel101/23b2b7ab80930cff9389e3a592a3a328 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool Rectangle::isIntersection(const Rectangle &otherRect) const | |
{ | |
assert(invariant()); | |
// cout << "current " << getColumnCount() << endl; | |
// cout << "current " << getMinColumn() << endl; | |
// cout << "other " << otherRect.getColumnCount() << endl; | |
// cout << "other " << otherRect.getMinColumn() << endl; | |
int currentRectCheck = abs(getMinColumn()) + abs(getColumnCount()) - 2; | |
int otherRectCheck = abs(otherRect.getMinColumn()) - abs(otherRect.getColumnCount()) + 2; | |
// cout << "check 1 " << currentRectCheck << endl; | |
// cout << "check 2 " << otherRectCheck << endl; | |
; | |
// col with second rect can only occur in this range | |
if (abs(currentRectCheck) <= abs(otherRectCheck)) | |
{ | |
// cout << "row check 1 " << getMinRow() << endl; | |
// cout << "row check 1 " << getRowCount() << endl; | |
// cout << "row check 2 " << otherRect.getMinRow() << endl; | |
// cout << "row check 2 " << otherRect.getRowCount() << endl; | |
// cout << "row check 3 " << abs(otherRect.getMinRow()) - 1 + abs(otherRect.getRowCount()) << endl; | |
// cout << "row check 4 " << (abs(getMinRow()) + abs(getRowCount()) - 1) << endl; | |
// cout << (abs(getMinRow()) > (abs(otherRect.getMinRow()) - 1 + abs(otherRect.getRowCount()))) << endl; | |
// cout << ((abs(getMinRow()) + abs(getRowCount())) - 1 < abs(otherRect.getMinRow())) << endl; | |
// check if rows overlap | |
if ( | |
( | |
abs(getMinRow()) > (abs(otherRect.getMinRow()) - 1 + abs(otherRect.getRowCount())) || | |
(abs(getMinRow()) + abs(getRowCount())) - 1 < abs(otherRect.getMinRow()))) | |
{ | |
return false; | |
} | |
// cout << "true" << endl; | |
return true; | |
} | |
return false; | |
assert(invariant()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment