Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (parentScale) {
scaleX = parentScale[0];
scaleY = parentScale[1];
} else if (pinchFlag) {
if (parentDistance) {
scaleX = (width + parentDistance) / width;
scaleY = (height + parentDistance * height / width) / height;
}
} else {
const dist = getDragDist({ datas, distX, distY });
let distWidth = direction[0] * dist[0];
let distHeight = direction[1] * dist[1];
if (keepRatio && width && height) {
const rad = getRad([0, 0], dist);
const standardRad = getRad([0, 0], direction);
const ratioRad = getRad([0, 0], [startWidth, startHeight]);
const size = Math.sqrt(distWidth * distWidth + distHeight * distHeight);
const signSize = Math.cos(rad - standardRad) * size;
if (!direction[0]) {
// top, bottom
distHeight = signSize;
distWidth = getKeepRatioWidth(distHeight, isWidth, ratio);
} else if (!direction[1]) {
// left, right
distWidth = signSize;
distHeight = getKeepRatioHeight(distWidth, isWidth, ratio);
} else {
// two-way
distWidth = Math.cos(ratioRad) * signSize;
distHeight = Math.sin(ratioRad) * signSize;
function getTriangleRad(pos1: number[], pos2: number[], pos3: number[]) {
// pos1 Rad
const rad1 = getRad(pos1, pos2);
const rad2 = getRad(pos1, pos3);
const rad = rad2 - rad1;
return rad >= 0 ? rad : rad + 2 * Math.PI;
}
function getTriangleRad(pos1: number[], pos2: number[], pos3: number[]) {
// pos1 Rad
const rad1 = getRad(pos1, pos2);
const rad2 = getRad(pos1, pos3);
const rad = rad2 - rad1;
return rad >= 0 ? rad : rad + 2 * Math.PI;
}
function getRotatiion(touches: Client[]) {
return getRad([
touches[0].clientX,
touches[0].clientY,
], [
touches[1].clientX,
touches[1].clientY,
]) / Math.PI * 180;
}
x3 = (x3 - left) || 0;
x4 = (x4 - left) || 0;
y1 = (y1 - top) || 0;
y2 = (y2 - top) || 0;
y3 = (y3 - top) || 0;
y4 = (y4 - top) || 0;
originX = (originX - left) || 0;
originY = (originY - top) || 0;
const center = [
(x1 + x2 + x3 + x4) / 4,
(y1 + y2 + y3 + y4) / 4,
];
const pos1Rad = getRad(center, [x1, y1]);
const pos2Rad = getRad(center, [x2, y2]);
const direction =
(pos1Rad < pos2Rad && pos2Rad - pos1Rad < Math.PI) || (pos1Rad > pos2Rad && pos2Rad - pos1Rad < -Math.PI)
? 1 : -1;
return [
[left, top, right, bottom],
[originX, originY],
[x1, y1],
[x2, y2],
[x3, y3],
[x4, y4],
direction,
];
}
export function getRotationRad(
poses: number[][],
direction: number,
) {
return getRad(direction > 0 ? poses[0] : poses[1], direction > 0 ? poses[1] : poses[0]);
}
export function getTargetInfo(
function setRotateStartInfo(
datas: IObject, clientX: number, clientY: number, origin: number[], rotationPos: number[]) {
datas.startAbsoluteOrigin = [
clientX - rotationPos[0] + origin[0],
clientY - rotationPos[1] + origin[1],
];
datas.prevDeg = getRad(datas.startAbsoluteOrigin, [clientX, clientY]) / Math.PI * 180;
datas.startDeg = datas.prevDeg;
datas.loop = 0;
}
function getDeg(
function getRotateInfo(
datas: IObject,
direction: number,
clientX: number, clientY: number,
startRotate: number,
throttleRotate: number,
) {
return getDeg(
datas,
getRad(datas.startAbsoluteOrigin, [clientX, clientY]) / Math.PI * 180,
direction,
startRotate,
throttleRotate,
);
}