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(draw): support draw line for element with angle #WIK-14850 #785

Merged
merged 5 commits into from
Mar 25, 2024

Conversation

MissLixf
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Mar 21, 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 Mar 25, 2024 0:19am
plait-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2024 0:19am

.changeset/rich-carrots-collect.md Outdated Show resolved Hide resolved
packages/draw/src/utils/line/elbow.ts Show resolved Hide resolved
packages/draw/src/utils/line/line-basic.ts Outdated Show resolved Hide resolved
packages/draw/src/utils/line/line-common.ts Outdated Show resolved Hide resolved
@@ -24,7 +24,8 @@ export const getHitOutlineGeometry = (board: PlaitBoard, point: Point, offset: n
let client = RectangleClient.getRectangleByPoints(node.points);
client = RectangleClient.getOutlineRectangle(client, offset);
const shape = getShape(node);
const isHit = getEngine(shape).isInsidePoint(client, point);
const rotatedPoint = rotatePoints([point], RectangleClient.getCenterPoint(client), -node.angle)[0];
const isHit = getEngine(shape).isInsidePoint(client, rotatedPoint);
Copy link
Collaborator

Choose a reason for hiding this comment

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

无角度不旋转,不行就抽取一个函数吧,根据元素是否有角度决定是否旋转点

if (line.source.boundId) {
const sourceElement = getElementById<PlaitGeometry>(board, line.source.boundId)!;
const sourceConnectionPoint = getConnectionPoint(sourceElement, line.source.connection!);
sourcePoint = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

验证 hasValidAngle

@@ -15,8 +27,13 @@ export const withLineAutoCompleteReaction = (board: PlaitBoard) => {
const targetElement = selectedElements.length === 1 && selectedElements[0];
const movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
if (!PlaitBoard.isReadonly(board) && !isSelectionMoving(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
const [rotatedMovingPoint] = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

验证 hasValidAngle

@@ -42,7 +44,12 @@ export const withLineAutoComplete = (board: PlaitBoard) => {
const clickPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
if (!PlaitBoard.isReadonly(board) && targetElement && PlaitDrawElement.isShape(targetElement)) {
const points = getAutoCompletePoints(targetElement);
const index = getHitIndexOfAutoCompletePoint(clickPoint, points);
const [rotatedClickPoint] = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

hasValidAngle

@@ -59,7 +66,12 @@ export const withLineAutoComplete = (board: PlaitBoard) => {
lineShapeG = createG();
let movingPoint = toViewBoxPoint(board, toHostPoint(board, event.x, event.y));
if (startPoint && sourceElement) {
const distance = distanceBetweenPointAndPoint(...movingPoint, ...startPoint);
const [rotatedStartPoint] = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

hasValidAngle

@@ -69,6 +81,10 @@ export const withLineAutoComplete = (board: PlaitBoard) => {
const crossingPoint = engine.getNearestCrossingPoint(rectangle, startPoint);
sourcePoint = crossingPoint;
}

if (sourceElement.angle) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hasValidAngle

@@ -80,7 +80,13 @@ export const withLineResize = (board: PlaitBoard) => {
const object = resizeRef.handle === LineResizeHandle.source ? source : target;
points[handleIndex] = resizeState.endPoint;
if (hitElement) {
object.connection = getConnectionByNearestPoint(board, resizeState.endPoint, hitElement);
const [rotatedEndPoint] = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

hasValidAngle

getStrokeWidthByElement(sourceElement) * 2

let sourceRectangle = RectangleClient.getRectangleByPoints(sourceElement.points);
const sourceShape = getShape(sourceElement);
Copy link
Collaborator

Choose a reason for hiding this comment

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

sourceShape 和 sourceEngine 有用到吗?

const sourceShape = getShape(sourceElement);
const sourceEngine = getEngine(sourceShape);
const sourceElementCornerPoints = sourceEngine.getCornerPoints(sourceRectangle);
const rotatedSourceElementCornerPoints = rotatePoints(
Copy link
Collaborator

Choose a reason for hiding this comment

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

判断 hasValidAngle

const isHit = getEngine(shape).isInsidePoint(client, point);

let isHit;
if (hasValidAngle(node)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

这样的场景都类似处理吧,写个函数或者用类似的代码结构:
const rotatedPoint = hasValidAngle ? rotatePoints : undefined


let isHit;
if (hasValidAngle(node)) {
const rotatedPoint = rotatePoints([point], RectangleClient.getCenterPoint(client), -node.angle)[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里返回的不是数组吗,下面调用类型为什么不报错

@pubuzhixing8 pubuzhixing8 merged commit 6964590 into develop Mar 25, 2024
3 checks passed
@pubuzhixing8 pubuzhixing8 deleted the #WIK-14850 branch March 25, 2024 13:06
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