本文共 1180 字,大约阅读时间需要 3 分钟。
好的,所以我似乎有工作代码,但我确信我可以做很多改进仍然是为了使它更有效等等 . 我现在也必须处理其他7个调整大小的句柄(这只是顶部 - 中间一个):
var RADIANS = Math.PI/180;
var rotated_coords = {x: coords.x, y: coords.y};
if (shape.rotate) {
var rads = -shape.rotate*RADIANS;
var middle = {x: shape.x + shape.w/2, y: shape.y + shape.h/2}; //
middle of rotation
var offset = {
x: middle.x - coords.x,
y: middle.y - coords.y
};
rotated_coords.x = middle.x - (offset.x * Math.cos(rads) - offset.y
* Math.sin(rads));
rotated_coords.y = middle.y - (offset.x * Math.sin(rads) + offset.y
* Math.cos(rads));
}
// 1. get centre before resize
var middle = {
x: shape.x + shape.w/2,
y: shape.y + shape.h/2
};
// 2. get bottom-middle of rotated shape
var bottom_middle = {
x: middle.x - shape.h/2 * sin_th,
y: middle.y + shape.h/2 * cos_th
};
// 3. resize (get difference in height, dh) from bottom-middle point
var dh = shape.y - rotated_coords.y;
// 4. get new centre point
var new_middle = {
x: bottom_middle.x + (shape.h + dh) / 2 * sin_th,
y: bottom_middle.y - (shape.h + dh) / 2 * cos_th
};
// 5. return to non-rotated top-left point
shape.x = new_middle.x - shape.w / 2;
shape.y = new_middle.y - (shape.h + dh) / 2;
// 6. set our new height
shape.h += dh;
转载地址:https://blog.csdn.net/weixin_32075843/article/details/114759207 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!