Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const rotated = applyToPoint(regionTransform, mrzCropOptions);
const tmp = mrzCropOptions.width;
mrzCropOptions.width = mrzCropOptions.height;
mrzCropOptions.height = tmp;
mrzCropOptions.x = rotated.x;
mrzCropOptions.y = rotated.y - mrzCropOptions.height;
}
} else {
// convex hull relative to the original image's viewport
let hull = mrzRoi.roi.mask.monotoneChainConvexHull().map(([x, y]) => ({
x: (mrzRoi.roi.minX + x) * originalToTreatedRatio,
y: (mrzRoi.roi.minY + y) * originalToTreatedRatio
}));
if (regionTransform) {
hull = applyToPoints(regionTransform, hull);
}
const beforeRotate = toCrop;
const afterRotate = beforeRotate.rotate(angle, {
interpolation: 'bilinear'
});
const widthDiff = (afterRotate.width - beforeRotate.width) / 2;
const heightDiff = (afterRotate.height - beforeRotate.height) / 2;
const transformation = transform(
translate(widthDiff, heightDiff),
getRotationAround(beforeRotate, angle)
);
const rotatedHull = applyToPoints(transformation, hull);
export function pan(value, SVGDeltaX, SVGDeltaY) {
var panLimit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
var matrix = transform(fromObject(value), //2
translate(SVGDeltaX, SVGDeltaY) //1
);
// apply pan limits
if (panLimit) {
var _applyToPoints = applyToPoints(matrix, [{ x: panLimit, y: panLimit }, { x: value.SVGWidth - panLimit, y: value.SVGHeight - panLimit }]),
_applyToPoints2 = _slicedToArray(_applyToPoints, 2),
_applyToPoints2$ = _applyToPoints2[0],
x1 = _applyToPoints2$.x,
y1 = _applyToPoints2$.y,
_applyToPoints2$2 = _applyToPoints2[1],
x2 = _applyToPoints2$2.x,
y2 = _applyToPoints2$2.y;
//x limit
var moveX = 0;
if (value.viewerWidth - x1 < 0) moveX = value.viewerWidth - x1;else if (x2 < 0) moveX = -x2;
//y limit
var moveY = 0;
export function pan(value, SVGDeltaX, SVGDeltaY, panLimit = undefined) {
let matrix = transform(
fromObject(value), //2
translate(SVGDeltaX, SVGDeltaY) //1
);
// apply pan limits
if (panLimit) {
let [{x: x1, y: y1}, {x: x2, y: y2}] = applyToPoints(matrix, [
{x: value.SVGMinX + panLimit, y: value.SVGMinY + panLimit},
{x: value.SVGMinX + value.SVGWidth - panLimit, y: value.SVGMinY + value.SVGHeight - panLimit}
]);
//x limit
let moveX = 0;
if (value.viewerWidth - x1 < 0)
moveX = value.viewerWidth - x1;
else if (x2 < 0) moveX = -x2;
//y limit
let moveY = 0;
if (value.viewerHeight - y1 < 0)
moveY = value.viewerHeight - y1;
else if (y2 < 0) moveY = -y2;
}
const beforeRotate = toCrop;
const afterRotate = beforeRotate.rotate(angle, {
interpolation: 'bilinear'
});
const widthDiff = (afterRotate.width - beforeRotate.width) / 2;
const heightDiff = (afterRotate.height - beforeRotate.height) / 2;
const transformation = transform(
translate(widthDiff, heightDiff),
getRotationAround(beforeRotate, angle)
);
const rotatedHull = applyToPoints(transformation, hull);
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;
for (const point of rotatedHull) {
if (point.x < minX) minX = point.x;
if (point.x > maxX) maxX = point.x;
if (point.y < minY) minY = point.y;
if (point.y > maxY) maxY = point.y;
}
minX = Math.max(0, Math.round(minX));
minY = Math.max(0, Math.round(minY));
maxX = Math.min(afterRotate.width, Math.round(maxX));
maxY = Math.min(afterRotate.height, Math.round(maxY));