@@ -2704,39 +2704,55 @@ export default class Element implements IElement, ILinkedNodeValue {
2704
2704
}
2705
2705
2706
2706
/**
2707
- * 设置水平翻转
2707
+ * 按照某一条线为翻转线,翻转组件
2708
+ *
2709
+ * @param flipLineStart 翻转线起点坐标
2710
+ * @param flipLineEnd 翻转线终点坐标
2708
2711
*/
2709
- setFlipX ( ) : void {
2712
+ flipXBy ( flipLineStart : IPoint , flipLineEnd : IPoint ) : void {
2710
2713
// 计算未倾斜的盒模型坐标
2711
2714
const unLeanBoxCoords = this . calcUnLeanBoxCoords ( ) ;
2712
2715
// 计算未倾斜的坐标
2713
2716
const unLeanCoords = this . calcUnLeanCoords ( ) ;
2714
- // p0是盒模型的左上角坐标,p1是盒模型的右上角坐标
2715
- const [ p0 , p1 ] = unLeanBoxCoords ;
2716
- // p0p1m是盒模型的中心点坐标
2717
- const m_p0p1 = {
2718
- x : ( p0 . x + p1 . x ) / 2 ,
2719
- y : ( p0 . y + p1 . y ) / 2 ,
2720
- } ;
2721
- // 中心点坐标
2722
- const centerCoord = this . centerCoord ;
2723
2717
// 计算翻转后的盒模型坐标
2724
- this . model . boxCoords = MathUtils . batchCalcSymmetryPoints ( unLeanBoxCoords , centerCoord , m_p0p1 ) ;
2718
+ this . model . boxCoords = MathUtils . batchCalcSymmetryPoints ( unLeanBoxCoords , flipLineStart , flipLineEnd ) ;
2725
2719
// 计算翻转后的坐标
2726
- this . model . coords = MathUtils . batchCalcSymmetryPoints ( unLeanCoords , centerCoord , m_p0p1 ) ;
2720
+ this . model . coords = MathUtils . batchCalcSymmetryPoints ( unLeanCoords , flipLineStart , flipLineEnd ) ;
2727
2721
// 角度镜像
2728
2722
this . model . angle = - this . model . angle ;
2729
2723
// 倾斜角度镜像
2730
2724
this . model . leanYAngle = - this . model . leanYAngle ;
2725
+ // 计算翻转参考的中心点,如果是单个翻转,那么此值与组件的centerCoord相同,如果是组合,则子组件计算出的翻转中心点实际为祖先组合的中心点
2726
+ const flipCenterCoord = MathUtils . calcCenter ( this . model . boxCoords ) ;
2731
2727
// 计算倾斜后的盒模型坐标
2732
- this . model . boxCoords = MathUtils . batchPrecisePoint ( MathUtils . batchLeanYWithCenter ( this . model . boxCoords , this . model . leanYAngle , centerCoord ) , 1 ) ;
2728
+ this . model . boxCoords = MathUtils . batchPrecisePoint ( MathUtils . batchLeanYWithCenter ( this . model . boxCoords , this . model . leanYAngle , flipCenterCoord ) , 1 ) ;
2733
2729
// 计算倾斜后的坐标
2734
- this . model . coords = MathUtils . batchPrecisePoint ( MathUtils . batchLeanYWithCenter ( this . model . coords , this . model . leanYAngle , centerCoord ) , 1 ) ;
2730
+ this . model . coords = MathUtils . batchPrecisePoint ( MathUtils . batchLeanYWithCenter ( this . model . coords , this . model . leanYAngle , flipCenterCoord ) , 1 ) ;
2731
+ }
2732
+
2733
+ /**
2734
+ * 设置水平翻转
2735
+ */
2736
+ setFlipX ( ) : [ IPoint , IPoint ] {
2737
+ // 计算未倾斜的盒模型坐标
2738
+ const unLeanBoxCoords = this . calcUnLeanBoxCoords ( ) ;
2739
+ // p0是盒模型的左上角坐标,p1是盒模型的右上角坐标
2740
+ const [ p0 , p1 ] = unLeanBoxCoords ;
2741
+ // p0p1m是p0p1的中点坐标,为参考线的结束点
2742
+ const m_p0p1 = {
2743
+ x : ( p0 . x + p1 . x ) / 2 ,
2744
+ y : ( p0 . y + p1 . y ) / 2 ,
2745
+ } ;
2746
+ // 组件的中心点坐标为其中参考线的起始点
2747
+ const centerCoord = this . centerCoord ;
2748
+ // 开始翻转
2749
+ this . flipXBy ( centerCoord , m_p0p1 ) ;
2750
+ // 返回参考线坐标,用于子节点的翻转参考
2751
+ return [ centerCoord , m_p0p1 ] ;
2735
2752
}
2736
2753
2737
2754
/**
2738
2755
* 按照某一点为圆心,旋转指定角度
2739
- *
2740
2756
* @param value
2741
2757
* @param lockCenter
2742
2758
*/
0 commit comments