Skip to content

Commit 90a257a

Browse files
committed
more precise resize when ratio is fixed: bigger dimension is master, smaller dimension is slave
1 parent f6273ff commit 90a257a

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

src/utils.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
6767
height = heightAndDeltaH.height
6868
deltaH = heightAndDeltaH.deltaH
6969
if (ratio) {
70-
deltaW = deltaH * ratio
71-
width = height * ratio
70+
if (ratio > 1) {
71+
height = width / ratio
72+
deltaH = deltaW / ratio
73+
} else {
74+
width = height * ratio
75+
deltaW = deltaH * ratio
76+
}
7277
}
7378
centerX += deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
7479
centerY += deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
@@ -82,8 +87,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
8287
height = heightAndDeltaH.height
8388
deltaH = heightAndDeltaH.deltaH
8489
if (ratio) {
85-
deltaW = deltaH * ratio
86-
width = height * ratio
90+
if (ratio > 1) {
91+
height = width / ratio
92+
deltaH = deltaW / ratio
93+
} else {
94+
width = height * ratio
95+
deltaW = deltaH * ratio
96+
}
8797
}
8898
centerX += deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
8999
centerY += deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)
@@ -115,8 +125,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
115125
height = heightAndDeltaH.height
116126
deltaH = heightAndDeltaH.deltaH
117127
if (ratio) {
118-
height = width / ratio
119-
deltaH = deltaW / ratio
128+
if (ratio > 1) {
129+
height = width / ratio
130+
deltaH = deltaW / ratio
131+
} else {
132+
width = height * ratio
133+
deltaW = deltaH * ratio
134+
}
120135
}
121136
centerX -= deltaW / 2 * cos(rotateAngle) + deltaH / 2 * sin(rotateAngle)
122137
centerY -= deltaW / 2 * sin(rotateAngle) - deltaH / 2 * cos(rotateAngle)
@@ -150,8 +165,13 @@ export const getNewStyle = (type, rect, deltaW, deltaH, ratio, minWidth, minHeig
150165
height = heightAndDeltaH.height
151166
deltaH = heightAndDeltaH.deltaH
152167
if (ratio) {
153-
width = height * ratio
154-
deltaW = deltaH * ratio
168+
if (ratio > 1) {
169+
height = width / ratio
170+
deltaH = deltaW / ratio
171+
} else {
172+
width = height * ratio
173+
deltaW = deltaH * ratio
174+
}
155175
}
156176
centerX -= deltaW / 2 * cos(rotateAngle) - deltaH / 2 * sin(rotateAngle)
157177
centerY -= deltaW / 2 * sin(rotateAngle) + deltaH / 2 * cos(rotateAngle)

0 commit comments

Comments
 (0)