Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support equal line when resize #WIK-14483 #741

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

huanhuanwa
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Feb 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
plait ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 9:24am
plait-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 1, 2024 9:24am

return result;
}

handleAlign(direction?: ResizeAlignDirection | null): ResizeAlignRef {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResizeAlignOptions: { resizeDirectionFactors: [number, number], isMaintainAspectRatio: boolean}

for (let alignRectangle of alignRectangles) {
const offsetWidth = this.activeRectangle.width - alignRectangle.width;
const offsetHeight = this.activeRectangle.height - alignRectangle.height;
const absOffsetWidth = Math.abs(offsetWidth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以去掉这两个变量,在用的地方直接 Math.abs(xxx)

canDrawHorizontal = true;
}

if (absOffsetWidth === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要绝对值

const absOffsetHeight = Math.abs(offsetHeight);

let canDrawHorizontal = false;
if (!isCorrectWidth && absOffsetWidth < ALIGN_TOLERANCE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里也需要增加判断条件,如果只垂直拖动,canDrawHorizontal 也是 false

const absOffsetWidth = Math.abs(offsetWidth);
const absOffsetHeight = Math.abs(offsetHeight);

let canDrawHorizontal = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canDrawHorizontal 和 isCorrectWidth 是否重复

y = 'y'
}

export class ResizeAlignReaction {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件名也改成 resize-align-reaction

alignRectangles: RectangleClient[];

constructor(private board: PlaitBoard, private activeElements: PlaitElement[], private activeRectangle: RectangleClient) {
this.alignRectangles = this.getAlignRectangle();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该就不用调用了?

export function getResizeAlignRef(board: PlaitBoard, resizeRef: ResizeRef<PlaitDrawElement | PlaitDrawElement[]>,resizeState: ResizeState): ResizeAlignRef {
const isResizeFromCorner = isCornerHandle(board, resizeRef.handle);
const isMaintainAspectRatio = resizeState.isShift || PlaitDrawElement.isImage(resizeRef.element);
let result = getResizeOriginAndZoom(board, resizeRef, resizeState, isResizeFromCorner, isMaintainAspectRatio);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNormalizedResizeRef

@@ -82,6 +104,15 @@ export function withDrawResize(board: PlaitBoard) {
return board;
}

export const getResizeUnitVector = (board: PlaitBoard, resizeRef: ResizeRef<PlaitDrawElement | PlaitDrawElement[]>) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getResizeOriginPointAndHandlePoint

return movePointByZoomAndOriginPoint(p, result.originPoint, result.xZoom, result.yZoom);
}) as [Point, Point];
const newRectangle = RectangleClient.getRectangleByPoints(resizePoints);
const resizeAlignReaction = new ResizeAlignReaction(board, activeElements, newRectangle);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像 ResizeAlignReaction 也可以用一个函数解决了,handleResizeAlign -> ResizeAlignRef,放到 draw/src/utils 里面吧


getAlignRectangle() {
const result: RectangleClient[] = [];
depthFirstRecursion<Ancestor>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 findElements 做

@pubuzhixing8 pubuzhixing8 merged commit 7a107ae into develop Feb 1, 2024
3 checks passed
@pubuzhixing8 pubuzhixing8 deleted the wang/#WIK-14483 branch February 1, 2024 09:46
alignG = g;
alignG.classList.add(ACTIVE_MOVING_CLASS_NAME);
PlaitBoard.getElementActiveHost(board).append(alignG);
resizeState.endPoint = [resizeState.endPoint[0] - deltaWidth, resizeState.endPoint[1] - deltaHeight];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我的理解 + 才是正确的,不知道哪里出问题了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为了跟 reaction-manager 保持一致, 内部 deltaWidth 用的是 this.activeRectangle.width - alignRectangle.width,反过来外面就是 + 了,后面可以统一改下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants