I'm adding 49 Rects in my canvas as well as storing the region for each Rect in an ArrayList:
private void addCoordinates(){
if (regions.size() > 0) {
regions.clear();
}
Paint xpaint = new Paint();
xpaint.setColor(Color.LTGRAY);
xpaint.setStyle(Paint.Style.STROKE);
xpaint.setStrokeWidth(10);
for (int j=1;j<8;j++){
for (int i=1;i<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);
}
}
}
I'm then drawing an intersected area among four circles by clipping the path of each circle:
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();
}
My task is to know, which of those 49 Rects that actually intersects the drawn area as shown in the screenshot below:
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 ?.
private void checkRectangles() {
int size = regions.size();
for (Region reg:regions){
Path path = reg.getBoundaryPath();
if (path.op(path, pathA, Path.Op.INTERSECT)){
count++;
}
}
}