Pārlūkot izejas kodu

圆角折线 最大圆角半径

haojianlong 4 gadi atpakaļ
vecāks
revīzija
02211871c2

+ 2 - 2
persagy-web-big-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big-edit",
-    "version": "2.2.42",
+    "version": "2.2.43",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/edit": "2.2.34",
+        "@persagy-web/edit": "2.2.35",
         "@types/uuid": "^8.0.0",
         "crypto-js": "^4.0.0",
         "axios": "^0.20.0"

+ 1 - 1
persagy-web-edit/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/edit",
-    "version": "2.2.34",
+    "version": "2.2.35",
     "description": "博锐尚格二维图形编辑器。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 51 - 1
persagy-web-edit/src/items/SBaseCirclePolylineEdit.ts

@@ -161,6 +161,8 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
     radiusIsPx: boolean = false;
     /** path 对象 */
     path: SPath = new SPath();
+    /** 圆角半径最大值 */
+    maxRadius: number = 0;
 
     /**
      * 构造函数
@@ -312,7 +314,7 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
                 if (event.altKey && this.canHandle(this.curIndex)) {
                     this.deletePoint(this.curIndex);
                 }
-
+                this.calMinEdge();
                 this.update();
                 return true;
             } else {
@@ -388,6 +390,7 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
                     p,
                     this.curIndex
                 ]);
+                this.calMinEdge();
             }
         } else if (this.status == SItemStatus.Normal) {
             // 处于正常态
@@ -413,14 +416,17 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
         } else if (this.status == SItemStatus.Edit) {
             // 处于编辑状态 双击则改为正常态
             this.status = SItemStatus.Normal;
+            this.calMinEdge();
             this.releaseItem();
         } else if (this.status == SItemStatus.Create) {
+            this.removeRepeat();
             // 处于创建状态
             if (this.pointList.length > 1) {
                 // 本对象点数据中已经给存在的点个数大于1个
                 this.status = SItemStatus.Normal;
                 this.releaseItem();
                 this.$emit("finishCreated");
+                this.calMinEdge();
             }
         }
 
@@ -441,6 +447,7 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
                 if (this.status == SItemStatus.Create) {
                     // 处于创建态
                     this.$emit("finishCreated");
+                    this.calMinEdge();
                 }
 
                 this.status = SItemStatus.Normal;
@@ -655,6 +662,49 @@ export default class SBaseCirclePolylineEdit extends SGraphEdit {
     }
 
     /**
+     * 计算最短边
+     */
+    calMinEdge(): void {
+        return;
+        // if (this.pointList.length > 1) {
+        //     this.maxRadius = 0;
+        //     for (let i = 0; i < this.pointList.length - 1; i++) {
+        //         const dis = SMathUtil.pointDistance(
+        //             this.pointList[i].x,
+        //             this.pointList[i].y,
+        //             this.pointList[i + 1].x,
+        //             this.pointList[i + 1].y
+        //         );
+        //         if (this.maxRadius == 0 || dis < this.maxRadius) {
+        //             this.maxRadius = dis;
+        //         }
+        //     }
+        //     // 与夹角有关 this.maxRadius = (this.maxRadius / 2;) * Math.tan(θ/2)
+        //     this.maxRadius = this.maxRadius / 2;
+        //     if (this.radius > this.maxRadius) {
+        //         this.radius = this.maxRadius;
+        //     }
+        // }
+    }
+
+    /**
+     * 去除重复点
+     */
+    removeRepeat(): void {
+        if (this.pointList.length > 1) {
+            for (let i = 0; i < this.pointList.length - 1; i++) {
+                if (
+                    this.pointList[i].x == this.pointList[i + 1].x &&
+                    this.pointList[i].y == this.pointList[i + 1].y
+                ) {
+                    this.pointList.splice(i, 1);
+                    i--;
+                }
+            }
+        }
+    }
+
+    /**
      * 撤销操作
      */
     undo(): void {