私はここで自分自身を心から混乱させています...実際に2つの長方形の交点の面積を返すのはどれですか? 説明してください(数学は私を苛立たせます)。任意の助けをいただければ幸いです。
アプローチ 1:
double newX = Math.max(this.x, rect2.x);
double newY = Math.max(this.y, rect2.y);
return new Rect(newX, newY, Math.min(this.x + this.width, rect2.x + rect2.width) - newX, Math.min(this.y
+ this.height, rect2.y + rect2.height)
- newY);
アプローチ 2:
double areaOfIntersection = Math.max(0, Math.max(rect1x2, rect2x2) - Math.min(rect1x1, rect2x1))
* Math.max(0, Math.max(rect1y2, rect2y2) - Math.min(rect1y1, rect2y1));