title: Find group of intersecting rectangles
body: <p>I've a list of rectangles (they cannot rotate):</p>
  
  <pre><code>struct Rectangle {
    double centerX;
    double centerY;
    double width;
    double height;
  
    Rectangle(double x, double y, double w, double h):centerx(x),centery(y),width(w),height(h){}
  };
  
  std::vector&lt;Rectangle&gt; rectangles;
  rectangles.push_back(Rectangle(0  ,  0  , 1  , 1  );
  rectangles.push_back(Rectangle(0.5,  0.5, 1  , 1  );
  rectangles.push_back(Rectangle(3  ,  2  , 0.5, 0.6);
  rectangles.push_back(Rectangle(0.2,  0.5, 0.5, 0.6);
  rectangles.push_back(Rectangle(2  , -0.3, 0.4, 0.4);
  rectangles.push_back(Rectangle(0.2, -0.4, 0.3, 0.4);
  </code></pre>
  
  <p>I want to calculate group of rectangles that have at least one intersection, with transitivity property. i.e. if r1 intersect r2 and r2 intersect r3, r1, r2, r3 are part of the same group.</p>
  
  <p>In this sample, group will be</p>
  
  <pre><code>{{3}, {4, 1, 2}, {5, 6}}
  </code></pre>
  
  <p>Group order and element order inside group is not important.</p>
  
  <p>How can I calculate these groups? I can change data structure if necessary.</p>
  
  <p>For example, I can change <code>std::vector</code> to <code>std::set</code> and order rectangles by left vertex X coordinate. In this way I can use a sweep line algorithm. But I am not be able to find any sample that can be applied to my problem.</p>
  
  <p>How can I obtain intersecting groups?</p>
  
  <p><img src="https://i.stack.imgur.com/fKHoV.png" alt="enter image description here"></p>