Selaa lähdekoodia

修改矩形计算bug

haojianlong 4 vuotta sitten
vanhempi
commit
771ebd981a
1 muutettua tiedostoa jossa 34 lisäystä ja 5 poistoa
  1. 34 5
      persagy-web-draw/src/types/SRect.ts

+ 34 - 5
persagy-web-draw/src/types/SRect.ts

@@ -331,15 +331,44 @@ export class SRect {
      * @return 返回合并后的矩形
      */
     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 (
             this.width + rect.width > maxX - minX &&
             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();
     }