Pārlūkot izejas kodu

折线item 外接矩阵添加

haojianlong 5 gadi atpakaļ
vecāks
revīzija
4d06382cdf
2 mainītis faili ar 46 papildinājumiem un 2 dzēšanām
  1. 1 1
      saga-web-big/package.json
  2. 45 1
      saga-web-big/src/items/SPolylineItem.ts

+ 1 - 1
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.37",
+    "version": "1.0.38",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 45 - 1
saga-web-big/src/items/SPolylineItem.ts

@@ -1,4 +1,4 @@
-import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
+import { SColor, SLine, SPainter, SPoint, SRect } from "@saga-web/draw";
 import { SMouseEvent, SUndoStack } from "@saga-web/base";
 import { SItemStatus } from "..";
 import { SMathUtil } from "../utils/SMathUtil";
@@ -15,6 +15,14 @@ import {
  * */
 
 export class SPolylineItem extends SGraphItem {
+    /** 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;
     /** 折点信息    */
     pointList: SPoint[] = [];
     /** 是否绘制完成  */
@@ -341,6 +349,42 @@ export class SPolylineItem extends SGraphItem {
     } // Function recordAction()
 
     /**
+     * Item对象边界区域
+     *
+     * @return  SRect   外接矩阵
+     * */
+    boundingRect(): SRect {
+        if (this.pointList.length) {
+            this.minX = this.pointList[0].x;
+            this.maxX = this.pointList[0].x;
+            this.minY = this.pointList[0].y;
+            this.maxY = this.pointList[0].y;
+            this.pointList.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;
+                }
+            });
+        }
+        return new SRect(
+            this.minX,
+            this.minY,
+            this.maxX - this.minX,
+            this.maxY - this.minY
+        );
+    } // Function boundingRect()
+
+    /**
      * 判断点是否在区域内
      *
      * @param   x