Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Rectangle overlap
//Title of this code #include <iostream> using namespace std; struct rect { int x; int y; int width; int height; rect(int a, int b, int w, int h): x(a), y(b), width(w), height(h) {} }; inline bool valueInRange(int value, int min, int max) { return (value >= min) && (value <= max); } bool rectOverlap(rect A, rect B) { bool xOverlap = valueInRange(A.x, B.x, B.x + B.width) || valueInRange(B.x, A.x, A.x + A.width); bool yOverlap = valueInRange(A.y, B.y, B.y + B.height) || valueInRange(B.y, A.y, A.y + B.height); return xOverlap && yOverlap; } int main() { rect A(0,0,4,4); rect B(5,4,4,4); cout << boolalpha << rectOverlap(A,B); }
run
|
edit
|
history
|
help
0
HashTable
OTHER - Two robots
Graph DFS
Test 01 c++
Splitwise Problem - 2
HeapSort
Count edges in a graph
VolAreObject
Quiz 12/13
cache 内存消耗