haojianlong преди 4 години
родител
ревизия
424fbf7c08
променени са 2 файла, в които са добавени 8 реда и са изтрити 13 реда
  1. 1 1
      persagy-web-big/src/utils/SMathUtil.ts
  2. 7 12
      persagy-web-draw/src/types/SRect.ts

+ 1 - 1
persagy-web-big/src/utils/SMathUtil.ts

@@ -205,7 +205,7 @@ export class SMathUtil {
         let minX = rect1.x < rect2.x ? rect1.x : rect2.x;
         let minY = rect1.y < rect2.y ? rect1.y : rect2.y;
         let maxX = rect1.right > rect2.right ? rect1.right : rect2.right;
-        let maxY = rect1.bottom > rect2.bottom ? rect2.bottom : rect2.bottom;
+        let maxY = rect1.bottom > rect2.bottom ? rect1.bottom : rect2.bottom;
         return (
             rect1.width + rect2.width > maxX - minX &&
             rect1.height + rect2.height > maxY - minY

+ 7 - 12
persagy-web-draw/src/types/SRect.ts

@@ -152,7 +152,6 @@ export class SRect {
         height?: number
     ) {
         if (x == undefined) {
-
             this.leftTop = new SPoint(0, 0);
             this.size = new SSize(0, 0);
         } else if (x instanceof SPoint && y instanceof SPoint) {
@@ -302,8 +301,6 @@ export class SRect {
 
     /**
      * 合并矩形
-     *
-     * @param rect    合并的矩形
      */
     union(rect: SRect): void {
         let r = this.unioned(rect);
@@ -342,21 +339,19 @@ export class SRect {
             this.width + rect.width > maxX - minX &&
             this.height + rect.height > maxY - minY
         ) {
-            return new SRect();
+            return new SRect(new SPoint(minX, minY), new SPoint(maxX, maxY));
         }
         return new SRect();
     }
 
     /**
      * 相交矩形
-     *
-     * @param rect    合并的矩形
      */
-    intersect(rect: SRect): SRect {
-        let left = Math.min(this.left, rect.left);
-        let top = Math.min(this.top, rect.top);
-        let right = Math.max(this.right, rect.right);
-        let bottom = Math.max(this.bottom, rect.bottom);
-        return new SRect(left, top, right - left, bottom - top);
+    intersect(rect: SRect): void {
+        let r = this.intersected(rect);
+        this.x = r.x;
+        this.y = r.y;
+        this.width = r.width;
+        this.height = r.height;
     }
 }