Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,11 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
width = widthAndDeltaW.width
deltaW = widthAndDeltaW.deltaW
if (ratio) {
deltaH = deltaW / ratio
height = width / ratio
// 左上角固定
centerX += deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)
} else {
// 左边固定
centerX += deltaW / 2 * cos(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle)
}
// 左边固定
centerX += deltaW / 2 * cos(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle)
break
}
case 'tr': {
Expand All @@ -67,8 +62,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
height = heightAndDeltaH.height
deltaH = heightAndDeltaH.deltaH
if (ratio) {
deltaW = deltaH * ratio
width = height * ratio
if (ratio > 1) {
height = width / ratio
deltaH = deltaW / ratio
} else {
width = height * ratio
deltaW = deltaH * ratio
}
}
centerX += deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
Expand All @@ -82,8 +82,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
height = heightAndDeltaH.height
deltaH = heightAndDeltaH.deltaH
if (ratio) {
deltaW = deltaH * ratio
width = height * ratio
if (ratio > 1) {
height = width / ratio
deltaH = deltaW / ratio
} else {
width = height * ratio
deltaW = deltaH * ratio
}
}
centerX += deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)
Expand All @@ -94,16 +99,11 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
height = heightAndDeltaH.height
deltaH = heightAndDeltaH.deltaH
if (ratio) {
deltaW = deltaH * ratio
width = height * ratio
// 左上角固定
centerX += deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)
} else {
// 上边固定
centerX -= deltaH / 2 * sin(rotateAngle)
centerY += deltaH / 2 * cos(rotateAngle)
}
// 上边固定
centerX -= deltaH / 2 * sin(rotateAngle)
centerY += deltaH / 2 * cos(rotateAngle)
break
}
case 'bl': {
Expand All @@ -115,8 +115,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
height = heightAndDeltaH.height
deltaH = heightAndDeltaH.deltaH
if (ratio) {
height = width / ratio
deltaH = deltaW / ratio
if (ratio > 1) {
height = width / ratio
deltaH = deltaW / ratio
} else {
width = height * ratio
deltaW = deltaH * ratio
}
}
centerX -= deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
centerY -= deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
Expand All @@ -129,15 +134,10 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
deltaW = widthAndDeltaW.deltaW
if (ratio) {
height = width / ratio
deltaH = deltaW / ratio
// 右上角固定
centerX -= deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
centerY -= deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
} else {
// 右边固定
centerX -= deltaW / 2 * cos(rotateAngle)
centerY -= deltaW / 2 * sin(rotateAngle)
}
// 右边固定
centerX -= deltaW / 2 * cos(rotateAngle)
centerY -= deltaW / 2 * sin(rotateAngle)
break
}
case 'tl': {
Expand All @@ -150,8 +150,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
height = heightAndDeltaH.height
deltaH = heightAndDeltaH.deltaH
if (ratio) {
width = height * ratio
deltaW = deltaH * ratio
if (ratio > 1) {
height = width / ratio
deltaH = deltaW / ratio
} else {
width = height * ratio
deltaW = deltaH * ratio
}
}
centerX -= deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
centerY -= deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)
Expand All @@ -164,14 +169,9 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
deltaH = heightAndDeltaH.deltaH
if (ratio) {
width = height * ratio
deltaW = deltaH * ratio
// 左下角固定
centerX += deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
centerY += deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
} else {
centerX += deltaH / 2 * sin(rotateAngle)
centerY -= deltaH / 2 * cos(rotateAngle)
}
centerX += deltaH / 2 * sin(rotateAngle)
centerY -= deltaH / 2 * cos(rotateAngle)
break
}
}
Expand Down