-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无角度不旋转,不行就抽取一个函数吧,根据元素是否有角度决定是否旋转点
packages/draw/src/interfaces/line.ts
Outdated
if (line.source.boundId) { | ||
const sourceElement = getElementById<PlaitGeometry>(board, line.source.boundId)!; | ||
const sourceConnectionPoint = getConnectionPoint(sourceElement, line.source.connection!); | ||
sourcePoint = rotatePoints( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里返回的不是数组吗,下面调用类型为什么不报错
No description provided.