Browse Source

外接矩阵

haojianlong 3 years ago
parent
commit
384e61ef35
2 changed files with 49 additions and 3 deletions
  1. 2 2
      package.json
  2. 47 1
      src/items/ShadeItem.ts

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/cad-engine",
-    "version": "2.0.590",
+    "version": "2.0.591",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -31,7 +31,7 @@
         "typescript": "^3.9.7"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.136",
+        "@saga-web/graph": "2.1.137",
         "axios": "^0.18.0",
         "pako": "^1.0.10",
         "poly-decomp": "^0.3.0",

+ 47 - 1
src/items/ShadeItem.ts

@@ -25,7 +25,8 @@ import {
     SLineCapStyle,
     SPainter,
     SPoint,
-    SPolygonUtil
+    SPolygonUtil,
+    SRect
 } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 import { ItemOrder } from "../types/ItemOrder";
@@ -43,6 +44,14 @@ export class ShadeItem extends SGraphItem {
     closeFlag = false;
     /** 鼠标移动点  */
     private lastPoint = new SPoint();
+    /** X坐标最小值  */
+    private minX = Number.MAX_SAFE_INTEGER;
+    /** X坐标最大值  */
+    private maxX = Number.MIN_SAFE_INTEGER;
+    /** Y坐标最小值  */
+    private minY = Number.MAX_SAFE_INTEGER;
+    /** Y坐标最大值  */
+    private maxY = Number.MIN_SAFE_INTEGER;
 
     /**
      * 构造函数
@@ -163,10 +172,47 @@ export class ShadeItem extends SGraphItem {
             // @ts-ignore
             this.scene.isCutting = false;
         }
+        this.calRect();
         this.update();
     } // Function createMask()
 
     /**
+     * 计算 item 所占边界
+     */
+    calRect(): void {
+        if (this.outLine.length) {
+            this.outLine.forEach(it => {
+                let x = it.x,
+                    y = it.y;
+                if (x < this.minX) {
+                    this.minX = x;
+                }
+                if (y < this.minY) {
+                    this.minY = y;
+                }
+                if (x > this.maxX) {
+                    this.maxX = x;
+                }
+                if (y > this.maxY) {
+                    this.maxY = y;
+                }
+            });
+        }
+    } // Function calRect()
+
+    /**
+     * 外接矩阵
+     */
+    boundingRect(): SRect {
+        return new SRect(
+            this.minX,
+            this.minY,
+            this.maxX - this.minX,
+            this.maxY - this.minY
+        );
+    }
+
+    /**
      * 判断点是否在区域内
      *
      * @param x