Skip to content

Commit 1c55e9e

Browse files
committed
组合翻转
1 parent 0e82831 commit 1c55e9e

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

src/modules/elements/Element.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,39 +2704,55 @@ export default class Element implements IElement, ILinkedNodeValue {
27042704
}
27052705

27062706
/**
2707-
* 设置水平翻转
2707+
* 按照某一条线为翻转线,翻转组件
2708+
*
2709+
* @param flipLineStart 翻转线起点坐标
2710+
* @param flipLineEnd 翻转线终点坐标
27082711
*/
2709-
setFlipX(): void {
2712+
flipXBy(flipLineStart: IPoint, flipLineEnd: IPoint): void {
27102713
// 计算未倾斜的盒模型坐标
27112714
const unLeanBoxCoords = this.calcUnLeanBoxCoords();
27122715
// 计算未倾斜的坐标
27132716
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;
27232717
// 计算翻转后的盒模型坐标
2724-
this.model.boxCoords = MathUtils.batchCalcSymmetryPoints(unLeanBoxCoords, centerCoord, m_p0p1);
2718+
this.model.boxCoords = MathUtils.batchCalcSymmetryPoints(unLeanBoxCoords, flipLineStart, flipLineEnd);
27252719
// 计算翻转后的坐标
2726-
this.model.coords = MathUtils.batchCalcSymmetryPoints(unLeanCoords, centerCoord, m_p0p1);
2720+
this.model.coords = MathUtils.batchCalcSymmetryPoints(unLeanCoords, flipLineStart, flipLineEnd);
27272721
// 角度镜像
27282722
this.model.angle = -this.model.angle;
27292723
// 倾斜角度镜像
27302724
this.model.leanYAngle = -this.model.leanYAngle;
2725+
// 计算翻转参考的中心点,如果是单个翻转,那么此值与组件的centerCoord相同,如果是组合,则子组件计算出的翻转中心点实际为祖先组合的中心点
2726+
const flipCenterCoord = MathUtils.calcCenter(this.model.boxCoords);
27312727
// 计算倾斜后的盒模型坐标
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);
27332729
// 计算倾斜后的坐标
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];
27352752
}
27362753

27372754
/**
27382755
* 按照某一点为圆心,旋转指定角度
2739-
*
27402756
* @param value
27412757
* @param lockCenter
27422758
*/

src/modules/stage/StageShield.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default class StageShield extends DrawerBase implements IStageShield, ISt
235235

236236
/**
237237
* 重绘所有组件
238-
*
238+
*
239239
* TODO 有性能问题,比较直观的浮现方式
240240
* 1. 打开控制台
241241
* 2. 绘制一个矩形

src/modules/stage/StageStore.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,13 @@ export default class StageStore implements IStageStore {
594594
async setElementsFlipX(elements: IElement[]): Promise<void> {
595595
elements.forEach(element => {
596596
if (this.hasElement(element.id) && !element.isGroupSubject) {
597-
element.setFlipX();
597+
const [flipLineStart, flipLineEnd] = element.setFlipX();
598598
element.onFlipXAfter();
599599
if (element.isGroup) {
600-
(element as IElementGroup).deepSubs.forEach(sub => sub.onFlipXAfter());
600+
(element as IElementGroup).deepSubs.forEach(sub => {
601+
sub.flipXBy(flipLineStart, flipLineEnd);
602+
sub.onFlipXAfter();
603+
});
601604
}
602605
}
603606
});

src/types/IElement.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,15 @@ export default interface IElement {
732732
/**
733733
* 水平翻转
734734
*/
735-
setFlipX(): void;
735+
setFlipX(): [IPoint, IPoint];
736+
737+
/**
738+
* 给定参考线,进行水平翻转
739+
*
740+
* @param flipLineStart
741+
* @param flipLineEnd
742+
*/
743+
flipXBy(flipLineStart: IPoint, flipLineEnd: IPoint): void;
736744

737745
/**
738746
* 拉伸

0 commit comments

Comments
 (0)