Skip to content

computeRectWithPinnedLine 是不是应该以中心点还原旋转 #1

@yiminghe

Description

@yiminghe

而不是现在的绕原点?

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
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions