我在画布中添加了 49 个 Rect,并将每个 Rect 的区域存储在 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);
}
}
}
我现在通过裁剪每个圆的路径来绘制四个圆之间的交集区域:
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();
}
我的任务是确定哪些49个矩形实际上与下面屏幕截图中所绘制的区域相交:
我已经尝试了下面的代码块,但它给出了全部的49个矩形,而不是期望的9个。如何确定与红色区域相交的矩形?
private void checkRectangles() {
int size = regions.size();
for (Region reg:regions){
Path path = reg.getBoundaryPath();
if (path.op(path, pathA, Path.Op.INTERSECT)){
count++;
}
}
}