Explorar el Código

矩阵修改兼容ie

haojianlong hace 5 años
padre
commit
d9e9ed469e

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/base",
-    "version": "2.1.22",
+    "version": "2.1.24",
     "description": "上格云Web基础库。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 596 - 0
saga-web-base/src/SMatrix.ts

@@ -0,0 +1,596 @@
+/*
+ * ********************************************************************************************************************
+ *
+ *               iFHS7.
+ *              ;BBMBMBMc                  rZMBMBR              BMB
+ *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
+ *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
+ *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
+ *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
+ *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
+ *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
+ *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
+ *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
+ *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
+ *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
+ *         i0BM: SWKHKGO  MBDv
+ *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2020.  斯伯坦机器人
+ *              ,  XMW  ..
+ *                  r                                                                     All rights reserved.
+ *
+ * ********************************************************************************************************************
+ */
+
+/**
+ * 变换矩阵
+ *
+ * @author  庞利祥 <sybotan@126.com>
+ */
+export class SMatrix {
+    m11 = 1;
+    m21 = 0;
+    m31 = 0;
+    m41 = 0;
+
+    m12 = 0;
+    m22 = 1;
+    m32 = 0;
+    m42 = 0;
+
+    m13 = 0;
+    m23 = 0;
+    m33 = 1;
+    m43 = 0;
+
+    m14 = 0;
+    m24 = 0;
+    m34 = 0;
+    m44 = 1;
+
+    /** x轴方向的缩放比例   */
+    get a(): number {
+        return this.m11;
+    } //
+    set a(v: number) {
+        this.m11 = v;
+    }
+    /** x轴方向斜切  */
+    get b(): number {
+        return this.m12;
+    }
+    set b(v: number) {
+        this.m12 = v;
+    }
+    /** y轴方向斜切  */
+    get c(): number {
+        return this.m21;
+    }
+    set c(v: number) {
+        this.m21 = v;
+    }
+    /** y轴方向缩放比例    */
+    get d(): number {
+        return this.m22;
+    }
+    set d(v: number) {
+        this.m22 = v;
+    }
+    /** x轴方向平移  */
+    get e(): number {
+        return this.m41;
+    }
+    set e(v: number) {
+        this.m41 = v;
+    }
+    /** y轴方向平移  */
+    get f(): number {
+        return this.m42;
+    }
+    set f(v: number) {
+        this.m42 = v;
+    }
+
+    /**
+     * 是否为 2D 矩阵
+     */
+    get is2D(): boolean {
+        return true;
+    }
+
+    /**
+     * 是否为单位矩阵
+     */
+    get isIdentity(): boolean {
+        return (
+            this.m11 == 1 &&
+            this.m21 == 0 &&
+            this.m31 == 0 &&
+            this.m41 == 0 &&
+            this.m12 == 0 &&
+            this.m22 == 1 &&
+            this.m32 == 0 &&
+            this.m42 == 0 &&
+            this.m13 == 0 &&
+            this.m23 == 0 &&
+            this.m33 == 1 &&
+            this.m43 == 0 &&
+            this.m14 == 0 &&
+            this.m24 == 0 &&
+            this.m34 == 0 &&
+            this.m44 == 1
+        );
+    }
+
+    // /**
+    //  * 构造函数
+    //  */
+    // constructor() {}
+
+    /**
+     * 重置变换矩阵
+     *
+     * @return  返回自身
+     */
+    reset(): SMatrix {
+        this.m11 = 1;
+        this.m21 = 0;
+        this.m31 = 0;
+        this.m41 = 0;
+
+        this.m12 = 0;
+        this.m22 = 1;
+        this.m32 = 0;
+        this.m42 = 0;
+
+        this.m13 = 0;
+        this.m23 = 0;
+        this.m33 = 1;
+        this.m43 = 0;
+
+        this.m14 = 0;
+        this.m24 = 0;
+        this.m34 = 0;
+        this.m44 = 1;
+        return this;
+    }
+
+    /**
+     * 原始矩阵乘以给定的变换矩阵
+     *
+     * @param   mat         给定的变换矩阵
+     * @return  返回自身
+     */
+    multiply(mat: SMatrix): SMatrix {
+        [
+            this.m11,
+            this.m21,
+            this.m31,
+            this.m41,
+
+            this.m12,
+            this.m22,
+            this.m32,
+            this.m42,
+
+            this.m13,
+            this.m23,
+            this.m33,
+            this.m43,
+
+            this.m14,
+            this.m24,
+            this.m34,
+            this.m44
+        ] = [
+            this.m11 * mat.m11 +
+                this.m21 * mat.m12 +
+                this.m31 * mat.m13 +
+                this.m41 * mat.m14,
+            this.m11 * mat.m21 +
+                this.m21 * mat.m22 +
+                this.m31 * mat.m23 +
+                this.m41 * mat.m24,
+            this.m11 * mat.m31 +
+                this.m21 * mat.m32 +
+                this.m31 * mat.m33 +
+                this.m41 * mat.m34,
+            this.m11 * mat.m41 +
+                this.m21 * mat.m42 +
+                this.m31 * mat.m43 +
+                this.m41 * mat.m44,
+
+            this.m12 * mat.m11 +
+                this.m22 * mat.m12 +
+                this.m32 * mat.m13 +
+                this.m42 * mat.m14,
+            this.m12 * mat.m21 +
+                this.m22 * mat.m22 +
+                this.m32 * mat.m23 +
+                this.m42 * mat.m24,
+            this.m12 * mat.m31 +
+                this.m22 * mat.m32 +
+                this.m32 * mat.m33 +
+                this.m42 * mat.m34,
+            this.m12 * mat.m41 +
+                this.m22 * mat.m42 +
+                this.m32 * mat.m43 +
+                this.m42 * mat.m44,
+
+            this.m13 * mat.m11 +
+                this.m23 * mat.m12 +
+                this.m33 * mat.m13 +
+                this.m43 * mat.m14,
+            this.m13 * mat.m21 +
+                this.m23 * mat.m22 +
+                this.m33 * mat.m23 +
+                this.m43 * mat.m24,
+            this.m13 * mat.m31 +
+                this.m23 * mat.m32 +
+                this.m33 * mat.m33 +
+                this.m43 * mat.m34,
+            this.m13 * mat.m41 +
+                this.m23 * mat.m42 +
+                this.m33 * mat.m43 +
+                this.m43 * mat.m44,
+
+            this.m14 * mat.m11 +
+                this.m24 * mat.m12 +
+                this.m34 * mat.m13 +
+                this.m44 * mat.m14,
+            this.m14 * mat.m21 +
+                this.m24 * mat.m22 +
+                this.m34 * mat.m23 +
+                this.m44 * mat.m24,
+            this.m14 * mat.m31 +
+                this.m24 * mat.m32 +
+                this.m34 * mat.m33 +
+                this.m44 * mat.m34,
+            this.m14 * mat.m41 +
+                this.m24 * mat.m42 +
+                this.m34 * mat.m43 +
+                this.m44 * mat.m44
+        ];
+        return this;
+    }
+
+    /**
+     * 位移变换
+     *
+     * @param   dx          X轴位移
+     * @param   dy          Y轴位移
+     * @param   dz          Z轴位移
+     * @return  返回自身
+     */
+    translate(dx: number, dy: number, dz = 0): SMatrix {
+        const mat = new SMatrix();
+        mat.m41 = dx;
+        mat.m42 = dy;
+        mat.m43 = dz;
+        this.multiply(mat);
+        return this;
+    }
+
+    // /**
+    //  * 平移变换矩阵
+    //  *
+    //  * @param   dx          X轴位移
+    //  * @param   dy          Y轴位移
+    //  * @param   dz          Z轴位移
+    //  * @return  返回平移变换矩阵
+    //  */
+    // translated(dx: number, dy: number, dz = 0): SMatrix {
+    //     const mat = new SMatrix();
+    //     mat.m41 = dx;
+    //     mat.m42 = dy;
+    //     mat.m43 = dz;
+    //     return mat;
+    // }
+
+    /**
+     * 缩放变换
+     *
+     * @param   sx          X轴缩放比例
+     * @param   sy          Y轴缩放比例
+     * @return  返回自身
+     */
+    scale(sx: number, sy: number): SMatrix {
+        const mat = new SMatrix();
+        mat.m11 = sx;
+        mat.m22 = sy;
+        this.multiply(mat);
+        return this;
+    }
+
+    // /**
+    //  * 缩放变换矩阵
+    //  *
+    //  * @param   sx          X轴缩放比例
+    //  * @param   sy          Y轴缩放比例
+    //  * @return  返回缩放变换矩阵
+    //  */
+    // scaled(sx: number, sy: number): SMatrix {
+    //     const mat = new SMatrix();
+    //     mat.m11 = sx;
+    //     mat.m22 = sy;
+    //     return mat;
+    // }
+
+    /**
+     * 旋转变形
+     *
+     * @param   angle       绕 Z 轴旋转角度(单位角度度)
+     * @return  返回自身
+     */
+    rotate(angle: number): SMatrix;
+
+    /**
+     * 旋转变形
+     *
+     * @param   rotX        绕 X 轴旋转角度(单位角度度)
+     * @param   rotY        绕 X 轴旋转角度(单位角度度)
+     * @param   rotZ        绕 X 轴旋转角度(单位角度度)
+     * @return  返回自身
+     */
+    rotate(rotX: number, rotY: number, rotZ: number): SMatrix;
+
+    /**
+     * 旋转变形
+     *
+     * @param   rotX        绕 Z 轴旋转角度 | 绕 X 轴旋转角度(单位弧度)
+     * @param   rotY        绕 X 轴旋转角度(单位弧度)
+     * @param   rotZ        绕 X 轴旋转角度(单位弧度)
+     * @return  返回自身
+     */
+    rotate(rotX: number, rotY?: number, rotZ?: number): SMatrix {
+        return this;
+    }
+
+    /**
+     * 转置当前矩阵
+     *
+     * @return  返回自身
+     */
+    transpose(): SMatrix {
+        [this.m12, this.m21] = [this.m21, this.m12];
+        [this.m13, this.m31] = [this.m31, this.m13];
+        [this.m14, this.m41] = [this.m41, this.m14];
+
+        [this.m23, this.m32] = [this.m32, this.m23];
+        [this.m24, this.m42] = [this.m42, this.m24];
+
+        [this.m34, this.m43] = [this.m43, this.m34];
+        return this;
+    }
+
+    // /**
+    //  * 转置当前矩阵
+    //  *
+    //  * @return  返回自身
+    //  */
+    // transposed(): SMatrix {
+    //     const mat = new SMatrix();
+    //     mat.m11 = this.m11;
+    //     mat.m21 = this.m12;
+    //     mat.m31 = this.m13;
+    //     mat.m41 = this.m14;
+    //
+    //     mat.m12 = this.m21;
+    //     mat.m22 = this.m22;
+    //     mat.m32 = this.m23;
+    //     mat.m42 = this.m24;
+    //
+    //     mat.m13 = this.m31;
+    //     mat.m23 = this.m32;
+    //     mat.m33 = this.m33;
+    //     mat.m43 = this.m34;
+    //
+    //     mat.m14 = this.m41;
+    //     mat.m24 = this.m42;
+    //     mat.m34 = this.m43;
+    //     mat.m44 = this.m44;
+    //
+    //     return mat;
+    // }
+
+    /**
+     * 返回当前矩阵的逆矩阵
+     *
+     * @return  当前矩阵的逆矩阵
+     * */
+    inversed(): SMatrix {
+        const detMat = this.det();
+        const d = this.value();
+        const ret = new SMatrix();
+        ret.m11 = detMat.m11 / d;
+        ret.m21 = detMat.m21 / d;
+        ret.m31 = detMat.m31 / d;
+        ret.m41 = detMat.m41 / d;
+
+        ret.m12 = detMat.m12 / d;
+        ret.m22 = detMat.m22 / d;
+        ret.m32 = detMat.m32 / d;
+        ret.m42 = detMat.m42 / d;
+
+        ret.m13 = detMat.m13 / d;
+        ret.m23 = detMat.m23 / d;
+        ret.m33 = detMat.m33 / d;
+        ret.m43 = detMat.m43 / d;
+
+        ret.m14 = detMat.m14 / d;
+        ret.m24 = detMat.m24 / d;
+        ret.m34 = detMat.m34 / d;
+        ret.m44 = detMat.m44 / d;
+        return ret;
+    }
+
+    /**
+     * 返回当前矩阵的伴随矩阵
+     *
+     * @return  当前矩阵的伴随矩阵
+     * */
+    det(): SMatrix {
+        const m = new SMatrix();
+        m.m11 =
+            this.m22 * this.m33 * this.m44 +
+            this.m32 * this.m43 * this.m24 +
+            this.m42 * this.m23 * this.m34 -
+            this.m42 * this.m33 * this.m24 -
+            this.m32 * this.m23 * this.m44 -
+            this.m22 * this.m43 * this.m34;
+        m.m12 = -(
+            this.m12 * this.m33 * this.m44 +
+            this.m32 * this.m43 * this.m14 +
+            this.m42 * this.m13 * this.m34 -
+            this.m42 * this.m33 * this.m14 -
+            this.m32 * this.m13 * this.m44 -
+            this.m12 * this.m43 * this.m34
+        );
+        m.m13 =
+            this.m12 * this.m23 * this.m44 +
+            this.m22 * this.m43 * this.m14 +
+            this.m42 * this.m13 * this.m24 -
+            this.m42 * this.m23 * this.m14 -
+            this.m22 * this.m13 * this.m44 -
+            this.m12 * this.m43 * this.m24;
+        m.m14 = -(
+            this.m12 * this.m23 * this.m34 +
+            this.m22 * this.m33 * this.m14 +
+            this.m32 * this.m13 * this.m24 -
+            this.m32 * this.m23 * this.m14 -
+            this.m22 * this.m13 * this.m34 -
+            this.m12 * this.m33 * this.m24
+        );
+
+        m.m21 = -(
+            this.m21 * this.m33 * this.m44 +
+            this.m31 * this.m43 * this.m24 +
+            this.m41 * this.m23 * this.m34 -
+            this.m41 * this.m33 * this.m24 -
+            this.m31 * this.m23 * this.m44 -
+            this.m21 * this.m43 * this.m34
+        );
+        m.m22 =
+            this.m11 * this.m33 * this.m44 +
+            this.m31 * this.m43 * this.m14 +
+            this.m41 * this.m13 * this.m34 -
+            this.m41 * this.m33 * this.m14 -
+            this.m31 * this.m13 * this.m44 -
+            this.m11 * this.m43 * this.m34;
+        m.m23 = -(
+            this.m11 * this.m23 * this.m44 +
+            this.m21 * this.m43 * this.m14 +
+            this.m41 * this.m13 * this.m24 -
+            this.m41 * this.m23 * this.m14 -
+            this.m21 * this.m13 * this.m44 -
+            this.m11 * this.m43 * this.m24
+        );
+        m.m24 =
+            this.m11 * this.m23 * this.m34 +
+            this.m21 * this.m33 * this.m14 +
+            this.m31 * this.m13 * this.m24 -
+            this.m31 * this.m23 * this.m14 -
+            this.m21 * this.m13 * this.m34 -
+            this.m11 * this.m33 * this.m24;
+
+        m.m31 =
+            this.m21 * this.m32 * this.m44 +
+            this.m31 * this.m42 * this.m24 +
+            this.m41 * this.m22 * this.m34 -
+            this.m41 * this.m32 * this.m24 -
+            this.m31 * this.m22 * this.m44 -
+            this.m21 * this.m42 * this.m34;
+        m.m32 = -(
+            this.m11 * this.m32 * this.m44 +
+            this.m31 * this.m42 * this.m14 +
+            this.m41 * this.m12 * this.m34 -
+            this.m41 * this.m32 * this.m14 -
+            this.m31 * this.m12 * this.m44 -
+            this.m11 * this.m42 * this.m34
+        );
+        m.m33 =
+            this.m11 * this.m22 * this.m44 +
+            this.m21 * this.m42 * this.m14 +
+            this.m41 * this.m12 * this.m24 -
+            this.m41 * this.m22 * this.m14 -
+            this.m21 * this.m12 * this.m44 -
+            this.m11 * this.m42 * this.m24;
+        m.m34 = -(
+            this.m11 * this.m22 * this.m34 +
+            this.m21 * this.m32 * this.m14 +
+            this.m31 * this.m12 * this.m24 -
+            this.m31 * this.m22 * this.m14 -
+            this.m21 * this.m12 * this.m34 -
+            this.m11 * this.m32 * this.m24
+        );
+
+        m.m41 = -(
+            this.m21 * this.m32 * this.m43 +
+            this.m31 * this.m42 * this.m23 +
+            this.m41 * this.m22 * this.m33 -
+            this.m41 * this.m32 * this.m23 -
+            this.m31 * this.m22 * this.m43 -
+            this.m21 * this.m42 * this.m33
+        );
+        m.m42 =
+            this.m11 * this.m32 * this.m43 +
+            this.m31 * this.m42 * this.m13 +
+            this.m41 * this.m12 * this.m33 -
+            this.m41 * this.m32 * this.m13 -
+            this.m31 * this.m12 * this.m43 -
+            this.m11 * this.m42 * this.m33;
+        m.m43 = -(
+            this.m11 * this.m22 * this.m43 +
+            this.m21 * this.m42 * this.m13 +
+            this.m41 * this.m12 * this.m23 -
+            this.m41 * this.m22 * this.m13 -
+            this.m21 * this.m12 * this.m43 -
+            this.m11 * this.m42 * this.m23
+        );
+        m.m44 =
+            this.m11 * this.m22 * this.m33 +
+            this.m21 * this.m32 * this.m13 +
+            this.m31 * this.m12 * this.m23 -
+            this.m31 * this.m22 * this.m13 -
+            this.m21 * this.m12 * this.m33 -
+            this.m11 * this.m32 * this.m23;
+        return m;
+    }
+
+    /**
+     * 返回当前矩阵的值
+     *
+     * @return  当前矩阵的值
+     * */
+    value(): number {
+        return (
+            this.m11 *
+                (this.m22 * this.m33 * this.m44 +
+                    this.m32 * this.m43 * this.m24 +
+                    this.m42 * this.m23 * this.m34 -
+                    this.m42 * this.m33 * this.m24 -
+                    this.m32 * this.m23 * this.m44 -
+                    this.m22 * this.m43 * this.m34) -
+            this.m21 *
+                (this.m12 * this.m33 * this.m44 +
+                    this.m32 * this.m43 * this.m14 +
+                    this.m42 * this.m13 * this.m34 -
+                    this.m42 * this.m33 * this.m14 -
+                    this.m32 * this.m13 * this.m44 -
+                    this.m12 * this.m43 * this.m34) +
+            this.m31 *
+                (this.m12 * this.m23 * this.m44 +
+                    this.m22 * this.m43 * this.m14 +
+                    this.m42 * this.m13 * this.m24 -
+                    this.m42 * this.m23 * this.m14 -
+                    this.m22 * this.m13 * this.m44 -
+                    this.m12 * this.m43 * this.m24) -
+            this.m41 *
+                (this.m12 * this.m23 * this.m34 +
+                    this.m22 * this.m33 * this.m14 +
+                    this.m32 * this.m13 * this.m24 -
+                    this.m32 * this.m23 * this.m14 -
+                    this.m22 * this.m13 * this.m34 -
+                    this.m12 * this.m33 * this.m24)
+        );
+    }
+}

+ 2 - 1
saga-web-base/src/SMouseEvent.ts

@@ -3,6 +3,7 @@
  *
  * @author
  */
+import { SMatrix } from "./SMatrix";
 
 export class SMouseEvent {
     /** 事件类型 */
@@ -30,7 +31,7 @@ export class SMouseEvent {
     /** 鼠标按键 */
     buttons: number;
     /** 变换矩阵 */
-    matrix = new DOMMatrix();
+    matrix = new SMatrix();
 
     /**
      * 构造函数

+ 2 - 1
saga-web-base/src/index.ts

@@ -12,7 +12,8 @@ import { SStringBuilder } from "./utils/SStringBuilder";
 import { SStringUtil } from "./utils/SStringUtil";
 export { SNetUtil, SStringBuilder, SStringUtil };
 
+import { SMatrix } from "./SMatrix";
 import { SMouseEvent } from "./SMouseEvent";
 import { SObject } from "./SObject";
 import { SObjectObserver } from "./SObjectObserver";
-export { SMouseEvent, SObject, SObjectObserver };
+export { SMatrix, SMouseEvent, SObject, SObjectObserver };

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.86",
+    "version": "1.0.88",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.112"
+        "@saga-web/graph": "2.1.114"
     }
 }

+ 11 - 7
saga-web-big/src/items/SPolylineItem.ts

@@ -264,9 +264,11 @@ export class SPolylineItem extends SGraphItem {
             this.status = SItemStatus.Normal;
             this.releaseItem();
         } else if (this.status == SItemStatus.Create) {
-            this.status = SItemStatus.Normal;
-            this.releaseItem();
-            this.$emit("finishCreated");
+            if (this.pointList.length > 2) {
+                this.status = SItemStatus.Normal;
+                this.releaseItem();
+                this.$emit("finishCreated");
+            }
         }
         this.$emit("onDoubleClick", event);
         return true;
@@ -279,11 +281,13 @@ export class SPolylineItem extends SGraphItem {
      */
     onKeyUp(event: KeyboardEvent): void {
         if (event.keyCode == SKeyCode.Enter) {
-            if (this.status == SItemStatus.Create) {
-                this.$emit("finishCreated");
+            if (this.pointList.length > 2) {
+                if (this.status == SItemStatus.Create) {
+                    this.$emit("finishCreated");
+                }
+                this.status = SItemStatus.Normal;
+                this.releaseItem();
             }
-            this.status = SItemStatus.Normal;
-            this.releaseItem();
         }
         // delete删除点
         if (

+ 2 - 2
saga-web-draw/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/draw",
-    "version": "2.1.102",
+    "version": "2.1.104",
     "description": "上格云绘制引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -33,7 +33,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/base": "^2.1.22"
+        "@saga-web/base": "^2.1.24"
     },
     "jest": {
         "setupFiles": [

+ 2 - 2
saga-web-draw/src/SPainter.ts

@@ -1,4 +1,4 @@
-import { SObject } from "@saga-web/base/lib";
+import { SMatrix, SObject } from "@saga-web/base/lib";
 import { SPaintEngine } from "./engines/SPaintEngine";
 import {
     SBrush,
@@ -70,7 +70,7 @@ export class SPainter extends SObject {
     } // Set shadow
 
     /** 变换矩阵 */
-    get worldTransform(): DOMMatrix {
+    get worldTransform(): SMatrix {
         return this.engine.state.matrix;
     } // Get worldTransform
 

+ 5 - 4
saga-web-draw/src/engines/SPaintEngine.ts

@@ -1,5 +1,6 @@
 import { SFont, SLine, SPaintEngineType, SPath2D, SPoint, SRect } from "..";
 import { SPaintState } from "./SPaintState";
+import { SMatrix } from "@saga-web/base/lib";
 
 /**
  * 绘制引擎基类
@@ -48,7 +49,7 @@ export abstract class SPaintEngine {
      * @param   y       Y辆方向平移
      */
     translate(x: number, y: number): void {
-        this.state.matrix.translateSelf(x, y);
+        this.state.matrix.translate(x, y);
     } // Function translate()
 
     /**
@@ -58,7 +59,7 @@ export abstract class SPaintEngine {
      * @param   y       Y辆方向缩放
      */
     scale(x: number, y: number): void {
-        this.state.matrix.scaleSelf(x, y);
+        this.state.matrix.scale(x, y);
     } // Function scale()
 
     /**
@@ -67,7 +68,7 @@ export abstract class SPaintEngine {
      * @param   angle   旋转角度(单位弧度)
      */
     rotate(angle: number): void {
-        this.state.matrix.rotateSelf(0, 0, angle);
+        this.state.matrix.rotate(0, 0, angle);
     } // Function rotate()
 
     /**
@@ -112,7 +113,7 @@ export abstract class SPaintEngine {
      * 重置当前变形为单位矩阵。等价于调用setTransform(1, 0, 0, 1, 0, 0)
      */
     resetTransform(): void {
-        this.state.matrix = new DOMMatrix();
+        this.state.matrix = new SMatrix();
     } // Function resetTransform()
 
     // =================================================================================================================

+ 3 - 2
saga-web-draw/src/engines/SPaintState.ts

@@ -1,6 +1,7 @@
 import { SBrush, SFont, SPen } from "..";
 import { SCompositeType } from "../enums/SCompositeType";
 import { SShadow } from "../SShadow";
+import { SMatrix } from "@saga-web/base";
 
 /**
  * 绘制状态
@@ -9,7 +10,7 @@ import { SShadow } from "../SShadow";
  */
 export class SPaintState {
     /** 变换矩阵 */
-    matrix = new DOMMatrix();
+    matrix = new SMatrix();
 
     /** 画笔 */
     private _pen = new SPen();
@@ -62,7 +63,7 @@ export class SPaintState {
             this.font = new SFont(state.font);
             this._composite = state._composite;
             this.shadow = new SShadow(state.shadow);
-            let m = new DOMMatrix();
+            let m = new SMatrix();
             m.m11 = state.matrix.m11;
             m.m12 = state.matrix.m12;
             m.m13 = state.matrix.m13;

+ 14 - 0
saga-web-draw/src/types/SPoint.ts

@@ -3,6 +3,8 @@
  *
  * @author 庞利祥(sybotan@126.com)
  */
+import { SMatrix } from "@saga-web/base/lib";
+
 export class SPoint {
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 属性定义
@@ -89,4 +91,16 @@ export class SPoint {
         // noinspection JSSuspiciousNameCombination
         return Math.abs(this.x) + Math.abs(this.y);
     } // Function manhattanLength()
+
+    /**
+     * 返回点矩阵变换后的值
+     *
+     * @return  变换后的点
+     * */
+    matrixTransform(mat: SMatrix): SPoint {
+        const p = new SPoint();
+        p.x = this.x * mat.a + this.y * mat.b + mat.e;
+        p.y = this.x * mat.c + this.y * mat.d + mat.f;
+        return p;
+    } // Function matrixTransform()
 } // Class SPoint

+ 2 - 2
saga-web-fengmap/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/feng-map",
-    "version": "1.0.25",
+    "version": "1.0.26",
     "description": "上格云Web平面图。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -32,7 +32,7 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/big": "1.0.83",
+        "@saga-web/big": "1.0.87",
         "axios": "^0.18.0"
     }
 }

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.112",
+    "version": "2.1.114",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -40,7 +40,7 @@
         "typescript": "^3.5.3"
     },
     "dependencies": {
-        "@saga-web/draw": "2.1.102",
+        "@saga-web/draw": "2.1.104",
         "@types/uuid": "^8.0.0"
     }
 }

+ 34 - 23
saga-web-graph/src/SGraphItem.ts

@@ -1,4 +1,9 @@
-import { SMouseButton, SMouseEvent, SObject } from "@saga-web/base/lib";
+import {
+    SMouseButton,
+    SMouseEvent,
+    SObject,
+    SMatrix
+} from "@saga-web/base/lib";
 import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
 import { SGraphScene } from "./SGraphScene";
 
@@ -146,6 +151,9 @@ export class SGraphItem extends SObject {
     /** 鼠标样式    */
     cursor: string = "default";
 
+    /** 保存上一次的grabitem  */
+    private _lastGrab: SGraphItem | null = null;
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // 函数
     /**
@@ -292,9 +300,7 @@ export class SGraphItem extends SObject {
      */
     mapFromScene(x: number, y: number): SPoint {
         const m = this.scene2itemMattrix();
-
-        const mp = new DOMPoint(x, y).matrixTransform(m.inverse());
-        return new SPoint(mp.x, mp.y);
+        return new SPoint(x, y).matrixTransform(m.inversed());
     } // Function mapFromScene()
 
     /**
@@ -312,8 +318,7 @@ export class SGraphItem extends SObject {
 
         const m = this.scene2itemMattrix();
 
-        const mp = new DOMPoint(x, y).matrixTransform(m);
-        return new SPoint(mp.x, mp.y);
+        return new SPoint(x, y).matrixTransform(m);
     } // Function mapToScene()
 
     /**
@@ -321,17 +326,17 @@ export class SGraphItem extends SObject {
      *
      * @return  转换矩阵
      */
-    scene2itemMattrix(): DOMMatrix {
-        let m = new DOMMatrix();
+    scene2itemMattrix(): SMatrix {
+        let m = new SMatrix();
         let list = this.itemPath();
         for (let item of list) {
-            m.translateSelf(item.x, item.y);
-            m.scaleSelf(item.scale, item.scale);
-            m.rotateSelf(item.rolate);
+            m.translate(item.x, item.y);
+            m.scale(item.scale, item.scale);
+            m.rotate(item.rolate);
 
             // 如果不进行变形处理,则取消painter的变型操作
             if (!item.isTransform) {
-                m.scaleSelf(item._inverseScale, item._inverseScale);
+                m.scale(item._inverseScale, item._inverseScale);
             }
         }
 
@@ -411,6 +416,9 @@ export class SGraphItem extends SObject {
         if (this.moveable) {
             this._mouseDownPos = new SPoint(event.x, event.y);
             this._isMoving = true;
+            if (this.scene) {
+                this._lastGrab = this.scene.grabItem;
+            }
             this.grabItem(this);
             return true;
         }
@@ -488,6 +496,9 @@ export class SGraphItem extends SObject {
 
         this._isMoving = false;
         this.releaseItem();
+        if (this.scene) {
+            this.scene.grabItem = this._lastGrab;
+        }
         return false;
     } // Function onMouseUp()
 
@@ -605,16 +616,16 @@ export class SGraphItem extends SObject {
         event: SMouseEvent
     ): SMouseEvent {
         let ce = new SMouseEvent(event);
-        ce.matrix.translateSelf(child.x, child.y);
-        ce.matrix.scaleSelf(child.scale, child.scale);
-        ce.matrix.rotateSelf(0, 0, child.rolate);
+        ce.matrix.translate(child.x, child.y);
+        ce.matrix.scale(child.scale, child.scale);
+        ce.matrix.rotate(0, 0, child.rolate);
 
         if (!child.isTransform) {
-            ce.matrix.scaleSelf(child._inverseScale, child._inverseScale);
+            ce.matrix.scale(child._inverseScale, child._inverseScale);
         }
 
-        const mp = new DOMPoint(event.offsetX, event.offsetY).matrixTransform(
-            ce.matrix.inverse()
+        const mp = new SPoint(event.offsetX, event.offsetY).matrixTransform(
+            ce.matrix.inversed()
         );
 
         ce.x = mp.x;
@@ -651,14 +662,14 @@ export class SGraphItem extends SObject {
      * @return  在父节点的位置
      */
     private toParentChange(x: number, y: number): SPoint {
-        const m = new DOMMatrix();
-        m.scaleSelf(this.scale, this.scale);
-        m.rotateSelf(this.rolate);
+        const m = new SMatrix();
+        m.scale(this.scale, this.scale);
+        m.rotate(this.rolate);
         if (!this.isTransform) {
-            m.scaleSelf(this._inverseScale, this._inverseScale);
+            m.scale(this._inverseScale, this._inverseScale);
         }
 
-        const mp = new DOMPoint(x, y).matrixTransform(m);
+        const mp = new SPoint(x, y).matrixTransform(m);
         return new SPoint(mp.x, mp.y);
     }
 

+ 4 - 4
saga-web-graph/src/SGraphView.ts

@@ -428,11 +428,11 @@ export class SGraphView extends SCanvasView {
      */
     private toSceneMotionEvent(event: MouseEvent): SMouseEvent {
         let se = new SMouseEvent(event);
-        se.matrix.translateSelf(this.origin.x, this.origin.y);
-        se.matrix.scaleSelf(this.scale, this.scale);
+        se.matrix.translate(this.origin.x, this.origin.y);
+        se.matrix.scale(this.scale, this.scale);
 
-        const mp = new DOMPoint(event.offsetX, event.offsetY).matrixTransform(
-            se.matrix.inverse()
+        const mp = new SPoint(event.offsetX, event.offsetY).matrixTransform(
+            se.matrix.inversed()
         );
 
         se.x = mp.x;