title: Intersection between two paths in a canvas using Android
body: <p>I'm adding 49 Rects in my canvas as well as storing the region for each Rect in an ArrayList:</p>
  
  <pre><code>private void addCoordinates(){
      if (regions.size() &gt; 0) {
          regions.clear();
      }
      Paint xpaint = new Paint();
      xpaint.setColor(Color.LTGRAY);
      xpaint.setStyle(Paint.Style.STROKE);
      xpaint.setStrokeWidth(10);
      for (int j=1;j&lt;8;j++){
          for (int i=1;i&lt;8;i++){
              Region reg = new Region();
              Path p = new Path();
              RectF rect = new RectF();
              rect.set(0, Calculations.convertscale(scale,(float) 91.43 * i), Calculations.convertscale(scale,(float) 91.43 * j), 0);
              canvas.drawRect(rect, xpaint);          
              p.computeBounds(rect, true);
              reg.setPath(p, new Region((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom)); 
              regions.add(reg);
          }
      }
  }
  </code></pre>
  
  <p>I'm then drawing an intersected area among four circles by clipping the path of each circle:</p>
  
  <pre><code> private void interSection(){
  
      canvas.clipPath(pathA, Region.Op.INTERSECT);
      canvas.clipPath(pathB, Region.Op.INTERSECT);  
      canvas.clipPath(pathC, Region.Op.INTERSECT);
      canvas.clipPath(pathD, Region.Op.INTERSECT);
  
      canvas.drawPath(pathA, mPaint);
      canvas.drawPath(pathB, mPaint);
      canvas.drawPath(pathC, mPaint);
      canvas.drawPath(pathD, mPaint);       
  
      drawingImageView.invalidate();
  }
  </code></pre>
  
  <p>My task is to know, which of those 49 Rects that actually intersects the drawn area as shown in the screenshot below:</p>
  
  <p><img src="https://i.stack.imgur.com/5ndki.png" alt="enter image description here"></p>
  
  <p>I have tried with the codeblock below, but it gives me all 49 Rects instead of 9 as expected. How do I determine the Rects that intersects with the red region ?. </p>
  
  <pre><code>private void checkRectangles() {
      int size = regions.size();
      for (Region reg:regions){
          Path path = reg.getBoundaryPath();
          if (path.op(path, pathA, Path.Op.INTERSECT)){
              count++;
          }
      }
  }
  </code></pre>