Explorar el Código

修改绘制带箭头的线段方法 rotate只能传角度 不能传弧度

haojianlong hace 4 años
padre
commit
9b5b242d25

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

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/big",
-    "version": "2.2.6",
+    "version": "2.2.7",
     "description": "博锐尚格建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -41,6 +41,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@persagy-web/graph": "2.2.8"
+        "@persagy-web/graph": "2.2.9"
     }
 }

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

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/draw",
-    "version": "2.2.4",
+    "version": "2.2.5",
     "description": "博锐尚格绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 25 - 40
persagy-web-draw/src/SPainter.ts

@@ -674,36 +674,33 @@ export class SPainter extends SObject {
      * */
     private drawBasicArrow(line: SLine, isEnd: boolean = true): void {
         // 定义箭头长度
-        const d = 5;
+        const d = this.toPx(10);
         // 箭头横坐标
         const x1 = d * Math.cos(Math.PI / 4);
         // 箭头纵坐标
         const y1 = d * Math.sin(Math.PI / 4);
         // 线段与x轴夹角
         const fo = Math.atan(line.dy / line.dx);
-        const ang = line.dx >= 0 ? fo : fo + Math.PI;
+        this.save();
         // 是否为终点画箭头
         if (isEnd) {
-            this.save();
             this.translate(line.x2, line.y2);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolyline([
                 new SPoint(-x1, y1),
                 new SPoint(0, 0),
                 new SPoint(-x1, -y1)
             ]);
-            this.restore();
         } else {
-            this.save();
             this.translate(line.x1, line.y1);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolyline([
                 new SPoint(x1, y1),
                 new SPoint(0, 0),
                 new SPoint(x1, -y1)
             ]);
-            this.restore();
         }
+        this.restore();
     } // Function drawArrow()
 
     /**
@@ -714,36 +711,33 @@ export class SPainter extends SObject {
      * */
     private drawTriangleArrow(line: SLine, isEnd: boolean = true): void {
         // 定义箭头长度
-        const d = 5;
+        const d = this.toPx(10);
         // 箭头横坐标
         const x1 = d * Math.cos(Math.PI / 12);
         // 箭头纵坐标
         const y1 = d * Math.sin(Math.PI / 12);
         // 线段与x轴夹角
         const fo = Math.atan(line.dy / line.dx);
-        const ang = line.dx >= 0 ? fo : fo + Math.PI;
+        this.save();
         // 是否为终点画箭头
         if (isEnd) {
-            this.save();
             this.translate(line.x2, line.y2);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(-x1, y1),
                 new SPoint(0, 0),
                 new SPoint(-x1, -y1)
             ]);
-            this.restore();
         } else {
-            this.save();
             this.translate(line.x1, line.y1);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(x1, y1),
                 new SPoint(0, 0),
                 new SPoint(x1, -y1)
             ]);
-            this.restore();
         }
+        this.restore();
     } // Function drawTriangleArrow()
 
     /**
@@ -754,38 +748,35 @@ export class SPainter extends SObject {
      * */
     private drawDiamondArrow(line: SLine, isEnd: boolean = true): void {
         // 定义箭头长度
-        const d = 2;
+        const d = this.toPx(5);
         // 箭头横坐标
         const x1 = d * Math.cos(Math.PI / 4);
         // 箭头纵坐标
         const y1 = d * Math.sin(Math.PI / 4);
         // 线段与x轴夹角
         const fo = Math.atan(line.dy / line.dx);
-        const ang = line.dx >= 0 ? fo : fo + Math.PI;
+        this.save();
         // 是否为终点画箭头
         if (isEnd) {
-            this.save();
             this.translate(line.x2, line.y2);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(-x1, y1),
                 new SPoint(0, 0),
                 new SPoint(-x1, -y1),
                 new SPoint(-Math.sqrt(2) * d, 0)
             ]);
-            this.restore();
         } else {
-            this.save();
             this.translate(line.x1, line.y1);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(x1, y1),
                 new SPoint(0, 0),
                 new SPoint(x1, -y1),
                 new SPoint(Math.sqrt(2) * d, 0)
             ]);
-            this.restore();
         }
+        this.restore();
     } // Function drawDiamondArrow()
 
     /**
@@ -796,34 +787,31 @@ export class SPainter extends SObject {
      * */
     private drawSquareArrow(line: SLine, isEnd: boolean = true): void {
         // 定义箭头长度
-        const d = 2;
+        const d = this.toPx(5);
         // 线段与x轴夹角
         const fo = Math.atan(line.dy / line.dx);
-        const ang = line.dx >= 0 ? fo : fo + Math.PI;
+        this.save();
         // 是否为终点画箭头
         if (isEnd) {
-            this.save();
             this.translate(line.x2, line.y2);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(-d, d / 2),
                 new SPoint(0, d / 2),
                 new SPoint(0, -d / 2),
                 new SPoint(-d, -d / 2)
             ]);
-            this.restore();
         } else {
-            this.save();
             this.translate(line.x1, line.y1);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawPolygon([
                 new SPoint(0, d / 2),
                 new SPoint(d, d / 2),
                 new SPoint(d, -d / 2),
                 new SPoint(0, -d / 2)
             ]);
-            this.restore();
         }
+        this.restore();
     } // Function drawSquareArrow()
 
     /**
@@ -834,23 +822,20 @@ export class SPainter extends SObject {
      * */
     private drawCircleArrow(line: SLine, isEnd: boolean = true): void {
         // 定义箭头长度
-        const d = 2;
+        const d = this.toPx(5);
         // 线段与x轴夹角
         const fo = Math.atan(line.dy / line.dx);
-        const ang = line.dx >= 0 ? fo : fo + Math.PI;
         // 是否为终点画箭头
+        this.save();
         if (isEnd) {
-            this.save();
             this.translate(line.x2, line.y2);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawCircle(-d / 2, 0, d / 2);
-            this.restore();
         } else {
-            this.save();
             this.translate(line.x1, line.y1);
-            this.rotate(ang);
+            this.rotate((fo * 180) / Math.PI);
             this.engine.drawCircle(d / 2, 0, d / 2);
-            this.restore();
         }
+        this.restore();
     } // Function drawCircleArrow()
 } // Class SPainter

+ 2 - 2
persagy-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@persagy-web/graph",
-    "version": "2.2.8",
+    "version": "2.2.9",
     "description": "博锐尚格二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@persagy-web/draw": "2.2.4",
+        "@persagy-web/draw": "2.2.5",
         "@types/uuid": "^8.0.0"
     }
 }