Browse Source

添加选中空间与业务空间差集算法;优化代码;新版本2.0.446

haojianlong 5 years ago
parent
commit
283e532d62

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
     "name": "@saga-web/cad-engine",
     "name": "@saga-web/cad-engine",
-    "version": "2.0.428",
+    "version": "2.0.446",
     "description": "上格云 CAD图形引擎。",
     "description": "上格云 CAD图形引擎。",
     "main": "lib/index.js",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
     "types": "lib/index.d.js",

+ 50 - 11
src/DivideFloorScene.ts

@@ -30,11 +30,11 @@ import { MinDis } from "./types/MinDis";
 import { PointToLine } from "./types/PointToLine";
 import { PointToLine } from "./types/PointToLine";
 import { RectSelectItem } from "./items/RectSelectItem";
 import { RectSelectItem } from "./items/RectSelectItem";
 // @ts-ignore
 // @ts-ignore
-import { intersect } from "polybooljs";
+import { intersect, difference } from "polybooljs";
 import { ShadeItem } from "./items/ShadeItem";
 import { ShadeItem } from "./items/ShadeItem";
 import { Point } from "./types/Point";
 import { Point } from "./types/Point";
 import { LikeSpaceItem } from "./items/LikeSpaceItem";
 import { LikeSpaceItem } from "./items/LikeSpaceItem";
-import { SpaceItem } from "./items/SpaceItem";
+import { Poly } from "./types/Poly";
 
 
 /**
 /**
  * 划分业务空间
  * 划分业务空间
@@ -756,20 +756,20 @@ export class DivideFloorScene extends FloorScene {
             );
             );
         }
         }
         if (poly2.regions.length) {
         if (poly2.regions.length) {
-            this.likeSpaceList.map(t => {
+            this.likeSpaceList.forEach((t): void => {
                 if (t.selected) {
                 if (t.selected) {
                     let poly1 = {
                     let poly1 = {
                         regions: [],
                         regions: [],
                         inverted: false
                         inverted: false
                     };
                     };
                     // @ts-ignore
                     // @ts-ignore
-                    poly1.regions = t.pointArr.map(item => {
+                    poly1.regions = t.pointArr.map((item): number[][] => {
                         return SMathUtil.transferToArray(item);
                         return SMathUtil.transferToArray(item);
                     });
                     });
                     console.log(poly1);
                     console.log(poly1);
                     let intersectObj = intersect(poly1, poly2);
                     let intersectObj = intersect(poly1, poly2);
                     if (intersectObj.regions.length) {
                     if (intersectObj.regions.length) {
-                        intersectObj.regions.map((t: number[][]) => {
+                        intersectObj.regions.map((t: number[][]): void => {
                             arr.push(SMathUtil.transferToSPoint(t));
                             arr.push(SMathUtil.transferToSPoint(t));
                         });
                         });
                     }
                     }
@@ -892,7 +892,7 @@ export class DivideFloorScene extends FloorScene {
     private groupSelectZone(): void {
     private groupSelectZone(): void {
         if (this.rectSelectItem) {
         if (this.rectSelectItem) {
             let item = this.rectSelectItem;
             let item = this.rectSelectItem;
-            let poly2 = {
+            const poly2: Poly = {
                 regions: [
                 regions: [
                     [
                     [
                         [item.startPoint.x, item.startPoint.y],
                         [item.startPoint.x, item.startPoint.y],
@@ -903,21 +903,60 @@ export class DivideFloorScene extends FloorScene {
                 ],
                 ],
                 inverted: false
                 inverted: false
             };
             };
-            this.zoneList.map(t => {
-                let poly1 = {
+            this.zoneList.forEach((t): void => {
+                const poly1: Poly = {
                     regions: [],
                     regions: [],
                     inverted: false
                     inverted: false
                 };
                 };
                 for (let i = 0; i < t.pointArr.length; i++) {
                 for (let i = 0; i < t.pointArr.length; i++) {
-                    // @ts-ignore
-                    poly1.regions = t.pointArr[i].map(item => {
+                    poly1.regions = t.pointArr[i].map((item): number[][] => {
                         return SMathUtil.transferToArray(item);
                         return SMathUtil.transferToArray(item);
                     });
                     });
                     let intersectObj = intersect(poly1, poly2);
                     let intersectObj = intersect(poly1, poly2);
-                    t.selected = intersectObj.regions.length ? true : false;
+                    t.selected = !!intersectObj.regions.length;
                     break;
                     break;
                 }
                 }
             });
             });
         }
         }
     } // Function groupSelectZone()
     } // Function groupSelectZone()
+
+    /**
+     * 选中的空间与所有业务空间的差集
+     */
+    getZoneDifference(): SPoint[][] {
+        let arr: SPoint[][] = [];
+        if (this.zoneList.length) {
+            const poly1: Poly = {
+                regions: [],
+                inverted: false
+            };
+            this.zoneList.forEach((t): void => {
+                t.pointArr.forEach((item): void => {
+                    item.forEach((po): void => {
+                        let point = SMathUtil.transferToArray(po);
+                        poly1.regions.push(point);
+                    });
+                });
+            });
+            const poly2: Poly = {
+                regions: [],
+                inverted: false
+            };
+            this.spaceList.forEach((t): void => {
+                if (t.selected) {
+                    poly2.regions = t.pointArr.map((item): number[][] => {
+                        return SMathUtil.transferToArray(item);
+                    });
+                    const diffObj: Poly = difference(poly2, poly1);
+                    if (diffObj.regions.length) {
+                        diffObj.regions.forEach((t: number[][]): void => {
+                            arr.push(SMathUtil.transferToSPoint(t));
+                        });
+                    }
+                    console.log(arr);
+                }
+            });
+        }
+        return arr;
+    } // getZoneIntersect()
 } // Class DivideFloorScene
 } // Class DivideFloorScene

+ 62 - 46
src/FloorScene.ts

@@ -56,10 +56,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowSpace = v;
         this._isShowSpace = v;
-        this.spaceList.map((t: SpaceItem) => {
-            t.visible = this._isShowSpace;
-            return t;
-        });
+        this.spaceList.map(
+            (t: SpaceItem): SpaceItem => {
+                t.visible = this._isShowSpace;
+                return t;
+            }
+        );
     } // Set isShowSpace
     } // Set isShowSpace
 
 
     /** 是否显示柱子  */
     /** 是否显示柱子  */
@@ -72,10 +74,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowColumn = v;
         this._isShowColumn = v;
-        this.columnList.map((t: ColumnItem) => {
-            t.visible = this._isShowColumn;
-            return t;
-        });
+        this.columnList.map(
+            (t: ColumnItem): ColumnItem => {
+                t.visible = this._isShowColumn;
+                return t;
+            }
+        );
     } // Set isShowColumn
     } // Set isShowColumn
 
 
     /** 是否展示墙体  */
     /** 是否展示墙体  */
@@ -88,10 +92,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowWall = v;
         this._isShowWall = v;
-        this.wallList.map((t: WallItem) => {
-            t.visible = this._isShowWall;
-            return t;
-        });
+        this.wallList.map(
+            (t: WallItem): WallItem => {
+                t.visible = this._isShowWall;
+                return t;
+            }
+        );
     } // Set isShowWall
     } // Set isShowWall
 
 
     /** 是否展示虚拟墙  */
     /** 是否展示虚拟墙  */
@@ -104,10 +110,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowVirtualWall = v;
         this._isShowVirtualWall = v;
-        this.virtualWallList.map((t: VirtualWallItem) => {
-            t.visible = this._isShowVirtualWall;
-            return t;
-        });
+        this.virtualWallList.map(
+            (t: VirtualWallItem): VirtualWallItem => {
+                t.visible = this._isShowVirtualWall;
+                return t;
+            }
+        );
     } // Set isShowVirtualWall
     } // Set isShowVirtualWall
 
 
     /** 是否展示门  */
     /** 是否展示门  */
@@ -120,10 +128,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowDoor = v;
         this._isShowDoor = v;
-        this.doorList.map((t: DoorItem) => {
-            t.visible = this._isShowDoor;
-            return t;
-        });
+        this.doorList.map(
+            (t: DoorItem): DoorItem => {
+                t.visible = this._isShowDoor;
+                return t;
+            }
+        );
     } // Set isShowDoor
     } // Set isShowDoor
 
 
     /** 是否展示窗户  */
     /** 是否展示窗户  */
@@ -136,10 +146,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isShowWindow = v;
         this._isShowWindow = v;
-        this.casementList.map((t: WindowItem) => {
-            t.visible = this._isShowWindow;
-            return t;
-        });
+        this.casementList.map(
+            (t: WindowItem): WindowItem => {
+                t.visible = this._isShowWindow;
+                return t;
+            }
+        );
     } // Set isShowWindow
     } // Set isShowWindow
 
 
     /** 空间是否可选  */
     /** 空间是否可选  */
@@ -152,10 +164,12 @@ export class FloorScene extends SGraphyScene {
             return;
             return;
         }
         }
         this._isSpaceSelectable = v;
         this._isSpaceSelectable = v;
-        this.spaceList.map((t: SpaceItem) => {
-            t.selectable = this._isSpaceSelectable;
-            return t;
-        });
+        this.spaceList.map(
+            (t: SpaceItem): SpaceItem => {
+                t.selectable = this._isSpaceSelectable;
+                return t;
+            }
+        );
     } // Set isSpaceSelectable
     } // Set isSpaceSelectable
 
 
     /** 墙list   */
     /** 墙list   */
@@ -184,9 +198,9 @@ export class FloorScene extends SGraphyScene {
      *
      *
      *  @param  url     请求数据文件路径
      *  @param  url     请求数据文件路径
      */
      */
-    loadUrl(url: string) {
+    loadUrl(url: string): Promise<void> {
         let that = this;
         let that = this;
-        return new Promise((relove, reject) => {
+        return new Promise((resolve, reject): void => {
             Axios({
             Axios({
                 method: "get",
                 method: "get",
                 url: url,
                 url: url,
@@ -198,7 +212,7 @@ export class FloorScene extends SGraphyScene {
                     this.unzip(blob)
                     this.unzip(blob)
                         .then((jsonData: any) => {
                         .then((jsonData: any) => {
                             that.addBaseMapItem(jsonData);
                             that.addBaseMapItem(jsonData);
-                            relove(jsonData);
+                            resolve(jsonData);
                         })
                         })
                         .catch((error: any) => {
                         .catch((error: any) => {
                             console.log(error);
                             console.log(error);
@@ -273,34 +287,34 @@ export class FloorScene extends SGraphyScene {
      *
      *
      *  @param  data    itemList对象
      *  @param  data    itemList对象
      */
      */
-    private addBaseMapItem(data: FloorData) {
+    private addBaseMapItem(data: FloorData): void {
         if (data.Walls) {
         if (data.Walls) {
-            data.Walls.map((t: Wall) => {
+            data.Walls.forEach((t: Wall): void => {
                 this.addWall(t);
                 this.addWall(t);
             });
             });
         }
         }
         if (data.Columns) {
         if (data.Columns) {
-            data.Columns.map((t: Column) => {
+            data.Columns.forEach((t: Column): void => {
                 this.addColumn(t);
                 this.addColumn(t);
             });
             });
         }
         }
         if (data.Windows) {
         if (data.Windows) {
-            data.Windows.map((t: Casement) => {
+            data.Windows.forEach((t: Casement): void => {
                 this.addCasement(t);
                 this.addCasement(t);
             });
             });
         }
         }
         if (data.VirtualWalls) {
         if (data.VirtualWalls) {
-            data.VirtualWalls.map((t: VirtualWall) => {
+            data.VirtualWalls.forEach((t: VirtualWall): void => {
                 this.addVirtualWall(t);
                 this.addVirtualWall(t);
             });
             });
         }
         }
         if (data.Doors) {
         if (data.Doors) {
-            data.Doors.map((t: Door) => {
+            data.Doors.forEach((t: Door): void => {
                 this.addDoor(t);
                 this.addDoor(t);
             });
             });
         }
         }
         if (data.Spaces) {
         if (data.Spaces) {
-            data.Spaces.map((t: Space) => {
+            data.Spaces.forEach((t: Space): void => {
                 this.addSpace(t);
                 this.addSpace(t);
             });
             });
         }
         }
@@ -358,7 +372,7 @@ export class FloorScene extends SGraphyScene {
     /**
     /**
      *  添加门到scene 中
      *  添加门到scene 中
      *
      *
-     *  @param  doors   门item
+     * @param door
      */
      */
     addDoor(door: Door): void {
     addDoor(door: Door): void {
         let item = new DoorItem(null, door);
         let item = new DoorItem(null, door);
@@ -370,7 +384,7 @@ export class FloorScene extends SGraphyScene {
     /**
     /**
      *  添加窗户到scene 中
      *  添加窗户到scene 中
      *
      *
-     *  @param  windows   窗户item
+     * @param casement
      */
      */
     addCasement(casement: Casement): void {
     addCasement(casement: Casement): void {
         let item = new WindowItem(null, casement);
         let item = new WindowItem(null, casement);
@@ -386,7 +400,7 @@ export class FloorScene extends SGraphyScene {
      */
      */
     private unzipBase64(b64Data: any) {
     private unzipBase64(b64Data: any) {
         let strData = atob(b64Data);
         let strData = atob(b64Data);
-        let charData = strData.split("").map(function(x) {
+        let charData = strData.split("").map(x => {
             return x.charCodeAt(0);
             return x.charCodeAt(0);
         });
         });
         let binData = new Uint8Array(charData);
         let binData = new Uint8Array(charData);
@@ -412,7 +426,7 @@ export class FloorScene extends SGraphyScene {
      */
      */
     getSelectedSpaces(): SpaceItem[] {
     getSelectedSpaces(): SpaceItem[] {
         let arr: SpaceItem[] = [];
         let arr: SpaceItem[] = [];
-        this.spaceList.map(sp => {
+        this.spaceList.forEach((sp): void => {
             if (sp.selected) {
             if (sp.selected) {
                 arr.push(sp);
                 arr.push(sp);
             }
             }
@@ -425,9 +439,11 @@ export class FloorScene extends SGraphyScene {
      *
      *
      */
      */
     clearSelectedSpaces(): void {
     clearSelectedSpaces(): void {
-        this.spaceList.map(sp => {
-            sp.selected = false;
-            return sp;
-        });
+        this.spaceList.map(
+            (sp): SpaceItem => {
+                sp.selected = false;
+                return sp;
+            }
+        );
     } // Function clearSelectedSpaces()
     } // Function clearSelectedSpaces()
 } // Class FloorScene
 } // Class FloorScene

+ 10 - 16
src/FloorView.ts

@@ -94,9 +94,8 @@ export class FloorView extends SGraphyView {
         if (se.buttons & SMouseButton.LeftButton) {
         if (se.buttons & SMouseButton.LeftButton) {
             this._leftKeyPos.x = se.x;
             this._leftKeyPos.x = se.x;
             this._leftKeyPos.y = se.y;
             this._leftKeyPos.y = se.y;
-        } else {
-            super.onMouseDown(event);
         }
         }
+        super.onMouseDown(event);
     } // Function onMouseDown()
     } // Function onMouseDown()
 
 
     /**
     /**
@@ -105,21 +104,16 @@ export class FloorView extends SGraphyView {
      * @param   event       事件参数
      * @param   event       事件参数
      */
      */
     protected onMouseMove(event: MouseEvent): void {
     protected onMouseMove(event: MouseEvent): void {
-        // 如果可以移动
-        if (this.moveable) {
-            // 按左键移动
-            let se = new SMouseEvent(event);
-            if (se.buttons & SMouseButton.LeftButton) {
-                if (this.spaceKey) {
-                    this.origin.x += se.x - this._leftKeyPos.x;
-                    this.origin.y += se.y - this._leftKeyPos.y;
-                }
-                this._leftKeyPos.x = se.x;
-                this._leftKeyPos.y = se.y;
-                return;
-            } else {
-                super.onMouseMove(event);
+        // 按左键移动
+        let se = new SMouseEvent(event);
+        if (se.buttons & SMouseButton.LeftButton) {
+            if (this.spaceKey) {
+                this.origin.x += se.x - this._leftKeyPos.x;
+                this.origin.y += se.y - this._leftKeyPos.y;
             }
             }
+            this._leftKeyPos.x = se.x;
+            this._leftKeyPos.y = se.y;
         }
         }
+        super.onMouseMove(event);
     } // Function onMouseMove()
     } // Function onMouseMove()
 } // Class FloorScene
 } // Class FloorScene

+ 20 - 19
src/items/ColumnItem.ts

@@ -59,25 +59,26 @@ export class ColumnItem extends SGraphyItem {
             this.maxX = this.minX;
             this.maxX = this.minX;
             this.minY = -tempArr[0][0].Y;
             this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
-            this.pointArr = tempArr.map(t => {
-                let temp = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[] => {
+                return t.map(
+                    (it): SPoint => {
+                        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 SPoint(x, y);
                     }
                     }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
-                return temp;
+                );
             });
             });
         }
         }
     } // Constructor
     } // Constructor
@@ -105,7 +106,7 @@ export class ColumnItem extends SGraphyItem {
         painter.pen.color = Opt.columnColor;
         painter.pen.color = Opt.columnColor;
         painter.pen.lineWidth = 10;
         painter.pen.lineWidth = 10;
         painter.brush.color = Opt.columnColor;
         painter.brush.color = Opt.columnColor;
-        this.pointArr.map(t => {
+        this.pointArr.forEach((t): void => {
             painter.drawPolygon(t);
             painter.drawPolygon(t);
         });
         });
     } // Function onDraw()
     } // Function onDraw()

+ 34 - 25
src/items/DoorItem.ts

@@ -21,7 +21,7 @@
 import { Door } from "../types/Door";
 import { Door } from "../types/Door";
 import { Opt } from "../types/Opt";
 import { Opt } from "../types/Opt";
 import { SGraphyItem } from "@saga-web/graphy/lib";
 import { SGraphyItem } from "@saga-web/graphy/lib";
-import { SColor, SPainter, SPoint, SRect } from "@saga-web/draw/lib";
+import { SPainter, SPoint } from "@saga-web/draw/lib";
 import { SMathUtil } from "../utils/SMathUtil";
 import { SMathUtil } from "../utils/SMathUtil";
 import { ItemOrder } from "../types/ItemOrder";
 import { ItemOrder } from "../types/ItemOrder";
 
 
@@ -40,9 +40,9 @@ export class DoorItem extends SGraphyItem {
     /** 角度  */
     /** 角度  */
     private readonly ang: number = 0;
     private readonly ang: number = 0;
     /** 旋转点 */
     /** 旋转点 */
-    private p: SPoint = new SPoint(0, 0);
+    private readonly p: SPoint = new SPoint(0, 0);
     /** 旋转起始角度,结束角度+Math.PI/2 */
     /** 旋转起始角度,结束角度+Math.PI/2 */
-    private startAng: number = -Math.PI / 2;
+    private readonly startAng: number = -Math.PI / 2;
 
 
     /**
     /**
      * 构造函数
      * 构造函数
@@ -55,18 +55,30 @@ export class DoorItem extends SGraphyItem {
         this.data = data;
         this.data = data;
         this.zOrder = ItemOrder.doorOrder;
         this.zOrder = ItemOrder.doorOrder;
         if (this.data.OutLine.length) {
         if (this.data.OutLine.length) {
-            this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, -t.Y);
-            });
+            this.pointArr = this.data.OutLine[0].map(
+                (t): SPoint => {
+                    return new SPoint(t.X, -t.Y);
+                }
+            );
 
 
             let p1 = this.pointArr[0],
             let p1 = this.pointArr[0],
                 p2 = this.pointArr[1];
                 p2 = this.pointArr[1];
             // 旋转点
             // 旋转点
             this.p = p1;
             this.p = p1;
+            const HX = (this.data.HandDirection.X = Number(
+                this.data.HandDirection.X.toFixed()
+            ));
+            const HY = (this.data.HandDirection.Y = Number(
+                this.data.HandDirection.Y.toFixed()
+            ));
+            const FX = (this.data.FaceDirection.X = Number(
+                this.data.FaceDirection.X.toFixed()
+            ));
+            const FY = (this.data.FaceDirection.Y = Number(
+                this.data.FaceDirection.Y.toFixed()
+            ));
             // 向量点乘 => x1 * x2 + y1 * y2,大于0同向
             // 向量点乘 => x1 * x2 + y1 * y2,大于0同向
-            let dotProduct =
-                (p2.x - p1.x) * this.data.HandDirection.X +
-                (p2.y - p1.y) * -this.data.HandDirection.Y;
+            let dotProduct = (p2.x - p1.x) * HX + (p2.y - p1.y) * -HY;
             if (dotProduct > 0) {
             if (dotProduct > 0) {
                 this.p = p2;
                 this.p = p2;
                 p2 = p1;
                 p2 = p1;
@@ -75,14 +87,10 @@ export class DoorItem extends SGraphyItem {
             // 两点间距离
             // 两点间距离
             this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
             this.r = SMathUtil.pointDistance(p1.x, p1.y, p2.x, p2.y);
             // 门朝向角度
             // 门朝向角度
-            let fo = Math.atan(
-                -this.data.FaceDirection.Y / this.data.FaceDirection.X
-            );
-            this.ang = this.data.FaceDirection.X > 0 ? fo : fo + Math.PI;
+            let fo = Math.atan(-FY / FX);
+            this.ang = FX > 0 ? fo : fo + Math.PI;
             // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针
             // 向量叉乘 => x1 * y2 - x2 * y1,小于0是顺时针
-            let direction =
-                (p2.x - p1.x) * -this.data.FaceDirection.Y -
-                (p2.y - p1.y) * this.data.FaceDirection.X;
+            let direction = (p2.x - p1.x) * -FY - (p2.y - p1.y) * FX;
             if (direction > 0) {
             if (direction > 0) {
                 this.startAng = 0;
                 this.startAng = 0;
             }
             }
@@ -100,14 +108,15 @@ export class DoorItem extends SGraphyItem {
         painter.pen.lineWidth = 100;
         painter.pen.lineWidth = 100;
         painter.pen.color = Opt.doorColor;
         painter.pen.color = Opt.doorColor;
         painter.drawLine(0, 0, this.r, 0);
         painter.drawLine(0, 0, this.r, 0);
-        // painter.pen.lineDash = [50, 100];
-        // painter.drawArc(
-        //     -this.r,
-        //     -this.r,
-        //     this.r * 2,
-        //     this.r * 2,
-        //     this.startAng,
-        //     this.startAng + Math.PI / 2
-        // );
+        painter.pen.lineDash = [50, 100];
+        painter.pen.lineWidth = 50;
+        painter.drawArc(
+            -this.r,
+            -this.r,
+            this.r * 2,
+            this.r * 2,
+            this.startAng,
+            this.startAng + Math.PI / 2
+        );
     } // Function onDraw()
     } // Function onDraw()
 } // Class DoorItem
 } // Class DoorItem

+ 20 - 18
src/items/LikeSpaceItem.ts

@@ -77,24 +77,26 @@ export class LikeSpaceItem extends SGraphyItem {
             this.maxX = this.minX;
             this.maxX = this.minX;
             this.minY = -tempArr[0][0].Y;
             this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
-            this.pointArr = tempArr.map(t => {
-                let temp = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[] => {
+                let temp = t.map(
+                    (it): SPoint => {
+                        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 SPoint(x, y);
                     }
                     }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
+                );
                 this.path.polygon(temp);
                 this.path.polygon(temp);
                 return temp;
                 return temp;
             });
             });
@@ -136,7 +138,7 @@ export class LikeSpaceItem extends SGraphyItem {
      */
      */
     onMouseMove(event: SMouseEvent): boolean {
     onMouseMove(event: SMouseEvent): boolean {
         return false;
         return false;
-    }
+    } // Function onMouseMove()
 
 
     /**
     /**
      * 判断点是否在区域内
      * 判断点是否在区域内

+ 24 - 5
src/items/SceneMarkItem.ts

@@ -30,6 +30,7 @@ import {
 } from "@saga-web/draw/lib";
 } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 import { SMouseEvent } from "@saga-web/base/lib";
 import { ItemOrder } from "../types/ItemOrder";
 import { ItemOrder } from "../types/ItemOrder";
+import { SMathUtil } from "../utils/SMathUtil";
 
 
 /**
 /**
  * 蒙版item
  * 蒙版item
@@ -88,6 +89,14 @@ export class SceneMarkItem extends SGraphyItem {
      */
      */
     onMouseDown(event: SMouseEvent): boolean {
     onMouseDown(event: SMouseEvent): boolean {
         if (!this.closeFlag && event.buttons == 1) {
         if (!this.closeFlag && event.buttons == 1) {
+            if (
+                this.lastPoint.x == this.outLine[0].x &&
+                this.lastPoint.y == this.outLine[0].y &&
+                this.outLine.length >= 3
+            ) {
+                this.createMask();
+                return true;
+            }
             let p = new SPoint(event.x, event.y);
             let p = new SPoint(event.x, event.y);
             this.lastPoint.x = p.x;
             this.lastPoint.x = p.x;
             this.lastPoint.y = p.y;
             this.lastPoint.y = p.y;
@@ -105,6 +114,20 @@ export class SceneMarkItem extends SGraphyItem {
     onMouseMove(event: SMouseEvent): boolean {
     onMouseMove(event: SMouseEvent): boolean {
         if (!this.closeFlag) {
         if (!this.closeFlag) {
             this.lastPoint = new SPoint(event.x, event.y);
             this.lastPoint = new SPoint(event.x, event.y);
+            if (this.outLine.length >= 3) {
+                let le = SMathUtil.pointDistance(
+                    this.lastPoint.x,
+                    this.lastPoint.y,
+                    this.outLine[0].x,
+                    this.outLine[0].y
+                );
+                // @ts-ignore
+                let scale = this.parent.scene.view.scale;
+                if (le * scale < 10) {
+                    this.lastPoint.x = this.outLine[0].x;
+                    this.lastPoint.y = this.outLine[0].y;
+                }
+            }
         }
         }
         return true;
         return true;
     } // Function onMouseMove()
     } // Function onMouseMove()
@@ -152,17 +175,13 @@ export class SceneMarkItem extends SGraphyItem {
      */
      */
     contains(x: number, y: number): boolean {
     contains(x: number, y: number): boolean {
         let arr = this.outLine;
         let arr = this.outLine;
-        if (!SPolygonUtil.pointIn(x, y, arr)) {
-            return true;
-        }
-        return false;
+        return !SPolygonUtil.pointIn(x, y, arr);
     } // Function contains()
     } // Function contains()
 
 
     /**
     /**
      * Item绘制操作
      * Item绘制操作
      *
      *
      * @param   painter       painter对象
      * @param   painter       painter对象
-     * @param   rect          绘制区域
      */
      */
     onDraw(painter: SPainter): void {
     onDraw(painter: SPainter): void {
         painter.pen.lineCapStyle = SLineCapStyle.Square;
         painter.pen.lineCapStyle = SLineCapStyle.Square;

+ 1 - 5
src/items/ShadeItem.ts

@@ -136,17 +136,13 @@ export class ShadeItem extends SGraphyItem {
      */
      */
     contains(x: number, y: number): boolean {
     contains(x: number, y: number): boolean {
         let arr = this.outLine;
         let arr = this.outLine;
-        if (SPolygonUtil.pointIn(x, y, arr)) {
-            return true;
-        }
-        return false;
+        return SPolygonUtil.pointIn(x, y, arr);
     } // Function contains()
     } // Function contains()
 
 
     /**
     /**
      * Item绘制操作
      * Item绘制操作
      *
      *
      * @param   painter       painter对象
      * @param   painter       painter对象
-     * @param   rect          绘制区域
      */
      */
     onDraw(painter: SPainter): void {
     onDraw(painter: SPainter): void {
         painter.pen.lineCapStyle = SLineCapStyle.Square;
         painter.pen.lineCapStyle = SLineCapStyle.Square;

+ 19 - 17
src/items/SpaceItem.ts

@@ -78,24 +78,26 @@ export class SpaceItem extends SGraphyItem {
             this.maxX = this.minX;
             this.maxX = this.minX;
             this.minY = -tempArr[0][0].Y;
             this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
-            this.pointArr = tempArr.map(t => {
-                let temp = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[] => {
+                let temp = t.map(
+                    (it): SPoint => {
+                        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 SPoint(x, y);
                     }
                     }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
+                );
                 this.path.polygon(temp);
                 this.path.polygon(temp);
                 return temp;
                 return temp;
             });
             });

+ 20 - 20
src/items/VirtualWallItem.ts

@@ -59,25 +59,26 @@ export class VirtualWallItem extends SGraphyItem {
             this.maxX = this.minX;
             this.maxX = this.minX;
             this.minY = -tempArr[0][0].Y;
             this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
-            this.pointArr = tempArr.map(t => {
-                let temp = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[] => {
+                return t.map(
+                    (it): SPoint => {
+                        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 SPoint(x, y);
                     }
                     }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
-                return temp;
+                );
             });
             });
         }
         }
     } // Constructor
     } // Constructor
@@ -100,13 +101,12 @@ export class VirtualWallItem extends SGraphyItem {
      * Item绘制操作
      * Item绘制操作
      *
      *
      * @param   painter       painter对象
      * @param   painter       painter对象
-     * @param   rect          绘制区域
      */
      */
     onDraw(painter: SPainter): void {
     onDraw(painter: SPainter): void {
         painter.pen.lineWidth = 100;
         painter.pen.lineWidth = 100;
         painter.pen.color = Opt.virtualWallColor;
         painter.pen.color = Opt.virtualWallColor;
         painter.pen.lineDash = [200, 200];
         painter.pen.lineDash = [200, 200];
-        this.pointArr.map(t => {
+        this.pointArr.forEach((t): void => {
             painter.drawPolyline(t);
             painter.drawPolyline(t);
         });
         });
     } // Function onDraw()
     } // Function onDraw()

+ 20 - 19
src/items/WallItem.ts

@@ -59,25 +59,26 @@ export class WallItem extends SGraphyItem {
             this.maxX = this.minX;
             this.maxX = this.minX;
             this.minY = -tempArr[0][0].Y;
             this.minY = -tempArr[0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
-            this.pointArr = tempArr.map(t => {
-                let temp = t.map(it => {
-                    let x = it.X,
-                        y = -it.Y;
-                    if (x < this.minX) {
-                        this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[] => {
+                return t.map(
+                    (it): SPoint => {
+                        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 SPoint(x, y);
                     }
                     }
-                    if (y < this.minY) {
-                        this.minY = y;
-                    }
-                    if (x > this.maxX) {
-                        this.maxX = x;
-                    }
-                    if (y > this.maxY) {
-                        this.maxY = y;
-                    }
-                    return new SPoint(x, y);
-                });
-                return temp;
+                );
             });
             });
         }
         }
     } // Constructor
     } // Constructor
@@ -106,7 +107,7 @@ export class WallItem extends SGraphyItem {
         painter.pen.color = Opt.wallColor;
         painter.pen.color = Opt.wallColor;
         painter.pen.lineWidth = 10;
         painter.pen.lineWidth = 10;
         painter.brush.color = Opt.wallColor;
         painter.brush.color = Opt.wallColor;
-        this.pointArr.map(t => {
+        this.pointArr.forEach((t): void => {
             painter.drawPolygon(t);
             painter.drawPolygon(t);
         });
         });
     } // Function onDraw()
     } // Function onDraw()

+ 5 - 4
src/items/WindowItem.ts

@@ -46,9 +46,11 @@ export class WindowItem extends SGraphyItem {
         this.data = data;
         this.data = data;
         this.zOrder = ItemOrder.windowOrder;
         this.zOrder = ItemOrder.windowOrder;
         if (this.data.OutLine.length) {
         if (this.data.OutLine.length) {
-            this.pointArr = this.data.OutLine[0].map(t => {
-                return new SPoint(t.X, -t.Y);
-            });
+            this.pointArr = this.data.OutLine[0].map(
+                (t): SPoint => {
+                    return new SPoint(t.X, -t.Y);
+                }
+            );
         }
         }
     } // Constructor
     } // Constructor
 
 
@@ -56,7 +58,6 @@ export class WindowItem extends SGraphyItem {
      * Item绘制操作
      * Item绘制操作
      *
      *
      * @param   painter       painter对象
      * @param   painter       painter对象
-     * @param   rect          绘制区域
      */
      */
     onDraw(painter: SPainter): void {
     onDraw(painter: SPainter): void {
         painter.pen.color = Opt.windowColor;
         painter.pen.color = Opt.windowColor;

+ 24 - 22
src/items/ZoneItem.ts

@@ -93,30 +93,32 @@ export class ZoneItem extends SGraphyItem {
             this.minY = -tempArr[0][0][0].Y;
             this.minY = -tempArr[0][0][0].Y;
             this.maxY = this.minY;
             this.maxY = this.minY;
             // 处理轮廓点数组,同时计算最大最小值
             // 处理轮廓点数组,同时计算最大最小值
-            this.pointArr = tempArr.map(t => {
-                let spath = new SPath2D();
-                let tempArr = t.map(it => {
-                    let array = it.map(item => {
-                        let x = item.X,
-                            y = -item.Y;
-                        if (x < this.minX) {
-                            this.minX = x;
+            this.pointArr = tempArr.map((t): SPoint[][] => {
+                let sPath = new SPath2D();
+                let tempArr = t.map((it): SPoint[] => {
+                    let array = it.map(
+                        (item): SPoint => {
+                            let x = item.X,
+                                y = -item.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 SPoint(x, y);
                         }
                         }
-                        if (y < this.minY) {
-                            this.minY = y;
-                        }
-                        if (x > this.maxX) {
-                            this.maxX = x;
-                        }
-                        if (y > this.maxY) {
-                            this.maxY = y;
-                        }
-                        return new SPoint(x, y);
-                    });
-                    spath.polygon(array);
+                    );
+                    sPath.polygon(array);
                     return array;
                     return array;
                 });
                 });
-                this.pathList.push(spath);
+                this.pathList.push(sPath);
                 return tempArr;
                 return tempArr;
             });
             });
         }
         }
@@ -204,7 +206,7 @@ export class ZoneItem extends SGraphyItem {
             }
             }
         }
         }
         painter.pen.lineWidth = 200;
         painter.pen.lineWidth = 200;
-        this.pathList.map(t => {
+        this.pathList.forEach((t): void => {
             painter.drawPath(t);
             painter.drawPath(t);
         });
         });
         painter.brush.color = SColor.Black;
         painter.brush.color = SColor.Black;

+ 2 - 2
src/types/Zone.ts

@@ -35,9 +35,9 @@ export interface Zone {
     /** 颜色  */
     /** 颜色  */
     Color: string;
     Color: string;
     /** 高度  */
     /** 高度  */
-    Height: number;
+    Height?: number;
     /** 是否高亮  */
     /** 是否高亮  */
     HighLightFlag?: boolean;
     HighLightFlag?: boolean;
     /** 透明度  */
     /** 透明度  */
     Transparency?: number;
     Transparency?: number;
-} // Interface Space
+} // Interface Zone