|
@@ -331,15 +331,44 @@ export class SRect {
|
|
* @return 返回合并后的矩形
|
|
* @return 返回合并后的矩形
|
|
*/
|
|
*/
|
|
intersected(rect: SRect): SRect {
|
|
intersected(rect: SRect): SRect {
|
|
- let minX = this.left < rect.left ? this.left : rect.left;
|
|
|
|
- let minY = this.top < rect.top ? this.top : rect.top;
|
|
|
|
- let maxX = this.right > rect.right ? this.right : rect.right;
|
|
|
|
- let maxY = this.bottom > rect.bottom ? this.bottom : rect.bottom;
|
|
|
|
|
|
+ let minX, minY, maxX, maxY;
|
|
|
|
+ let intersectMinX, intersectMaxX, intersectMinY, intersectMaxY;
|
|
|
|
+ if (this.left < rect.left) {
|
|
|
|
+ minX = this.left;
|
|
|
|
+ intersectMinX = rect.left;
|
|
|
|
+ } else {
|
|
|
|
+ minX = rect.left;
|
|
|
|
+ intersectMinX = this.left;
|
|
|
|
+ }
|
|
|
|
+ if (this.top < rect.top) {
|
|
|
|
+ minY = this.top;
|
|
|
|
+ intersectMinY = rect.top;
|
|
|
|
+ } else {
|
|
|
|
+ minY = rect.top;
|
|
|
|
+ intersectMinY = rect.top;
|
|
|
|
+ }
|
|
|
|
+ if (this.right > rect.right) {
|
|
|
|
+ maxX = this.right;
|
|
|
|
+ intersectMaxX = rect.right;
|
|
|
|
+ } else {
|
|
|
|
+ maxX = rect.right;
|
|
|
|
+ intersectMaxX = rect.right;
|
|
|
|
+ }
|
|
|
|
+ if (this.bottom > rect.bottom) {
|
|
|
|
+ maxY = this.bottom;
|
|
|
|
+ intersectMaxY = rect.bottom;
|
|
|
|
+ } else {
|
|
|
|
+ maxY = rect.bottom;
|
|
|
|
+ intersectMaxY = rect.bottom;
|
|
|
|
+ }
|
|
if (
|
|
if (
|
|
this.width + rect.width > maxX - minX &&
|
|
this.width + rect.width > maxX - minX &&
|
|
this.height + rect.height > maxY - minY
|
|
this.height + rect.height > maxY - minY
|
|
) {
|
|
) {
|
|
- return new SRect(new SPoint(minX, minY), new SPoint(maxX, maxY));
|
|
|
|
|
|
+ return new SRect(
|
|
|
|
+ new SPoint(intersectMinX, intersectMinY),
|
|
|
|
+ new SPoint(intersectMaxX, intersectMaxY)
|
|
|
|
+ );
|
|
}
|
|
}
|
|
return new SRect();
|
|
return new SRect();
|
|
}
|
|
}
|