mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	 98784ad3cb
			
		
	
	
		98784ad3cb
		
	
	
	
	
		
			
			The algorithm I came up with is O(n^2) but given the small numbers of rects we're typically working with, it doesn't really matter. May need to revisit this in the future if we find ourselves with a huge number of rects.
		
			
				
	
	
		
			23 lines
		
	
	
	
		
			488 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
	
		
			488 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #pragma once
 | |
| 
 | |
| #include <AK/Vector.h>
 | |
| #include <SharedGraphics/Rect.h>
 | |
| 
 | |
| class DisjointRectSet {
 | |
| public:
 | |
|     DisjointRectSet() { }
 | |
|     ~DisjointRectSet() { }
 | |
|     DisjointRectSet(DisjointRectSet&& other) : m_rects(move(other.m_rects)) { }
 | |
| 
 | |
|     void add(const Rect&);
 | |
| 
 | |
|     void clear() { m_rects.clear(); }
 | |
|     void clear_with_capacity() { m_rects.clear_with_capacity(); }
 | |
|     const Vector<Rect>& rects() const { return m_rects; }
 | |
| 
 | |
| private:
 | |
|     void shatter();
 | |
| 
 | |
|     Vector<Rect> m_rects;
 | |
| };
 | |
| 
 |