-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
而不是现在的绕原点?
Lines 134 to 159 in ad556a7
| export const computeRectWithPinnedLine = (pinnedPoints, dragPoint, angle) => { | |
| const [rotateP0, rotateP1] = pinnedPoints.map(p => rotatePosition(p, -angle)) | |
| const rotateDrag = rotatePosition(dragPoint, -angle) | |
| let w, h, rotatedCenter | |
| if (roughlyEqual(rotateP0.y, rotateP1.y)) { | |
| w = Math.abs(rotateP0.x - rotateP1.x) | |
| h = Math.abs(rotateDrag.y - rotateP0.y) | |
| rotatedCenter = { | |
| x: (rotateP0.x + rotateP1.x) / 2, | |
| y: (rotateP0.y + rotateDrag.y) / 2 | |
| } | |
| } else if (roughlyEqual(rotateP0.x, rotateP1.x)) { | |
| h = Math.abs(rotateP0.y - rotateP1.y) | |
| w = Math.abs(rotateDrag.x - rotateP0.x) | |
| rotatedCenter = { | |
| x: (rotateP0.x + rotateDrag.x) / 2, | |
| y: (rotateP0.y + rotateP1.y) / 2 | |
| } | |
| } | |
| const center = rotatePosition(rotatedCenter, angle) | |
| const x = center.x - w / 2 | |
| const y = center.y - h / 2 | |
| return { | |
| x, y, w, h, r: angle | |
| } | |
| } |
export const computeRectWithPinnedLine = (pinnedPoints, dragPoint, e) => {
const angle = e.rect.r;
const center = e.center;
const [rotateP0, rotateP1] = pinnedPoints.map(p => rotatePositionRelatively(p,center, -angle))
const rotateDrag = rotatePositionRelatively(dragPoint, center,-angle)
let w, h, rotatedCenter
if (roughlyEqual(rotateP0.y, rotateP1.y)) {
w = Math.abs(rotateP0.x - rotateP1.x)
h = Math.abs(rotateDrag.y - rotateP0.y)
rotatedCenter = {
x: (rotateP0.x + rotateP1.x) / 2,
y: (rotateP0.y + rotateDrag.y) / 2
}
} else if (roughlyEqual(rotateP0.x, rotateP1.x)) {
h = Math.abs(rotateP0.y - rotateP1.y)
w = Math.abs(rotateDrag.x - rotateP0.x)
rotatedCenter = {
x: (rotateP0.x + rotateDrag.x) / 2,
y: (rotateP0.y + rotateP1.y) / 2
}
}
const center2 = rotatePositionRelatively(rotatedCenter,center, angle)
const x = center2.x - w / 2
const y = center2.y - h / 2
return {
x, y, w, h, r: angle
}
}ioslh
Metadata
Metadata
Assignees
Labels
No labels