2024-06-17 05:14:16 -05:00
|
|
|
import { translateRotation, translateZeroRotation } from '@plugin/translators';
|
2024-06-19 01:10:20 -05:00
|
|
|
import { applyInverseRotation, getRotation, hasRotation } from '@plugin/utils';
|
2024-06-14 03:33:23 -05:00
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
import { ShapeBaseAttributes, ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';
|
|
|
|
|
2024-06-17 05:14:16 -05:00
|
|
|
export const transformRotation = (
|
2024-06-19 01:10:20 -05:00
|
|
|
node: LayoutMixin
|
2024-06-17 05:14:16 -05:00
|
|
|
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> => {
|
2024-06-19 01:10:20 -05:00
|
|
|
const rotation = getRotation(node.absoluteTransform);
|
2024-06-17 05:14:16 -05:00
|
|
|
|
|
|
|
if (!hasRotation(rotation)) {
|
|
|
|
return translateZeroRotation();
|
|
|
|
}
|
|
|
|
|
|
|
|
return translateRotation(node.absoluteTransform, rotation);
|
|
|
|
};
|
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
export const transformRotationAndPosition = (
|
2024-06-19 01:10:20 -05:00
|
|
|
node: LayoutMixin
|
2024-05-29 03:30:56 -05:00
|
|
|
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> &
|
|
|
|
Pick<ShapeGeomAttributes, 'x' | 'y'> => {
|
2024-06-14 09:28:01 -05:00
|
|
|
const x = node.absoluteTransform[0][2];
|
|
|
|
const y = node.absoluteTransform[1][2];
|
2024-06-19 01:10:20 -05:00
|
|
|
const rotation = getRotation(node.absoluteTransform);
|
2024-05-29 03:30:56 -05:00
|
|
|
|
2024-06-14 03:33:23 -05:00
|
|
|
if (!hasRotation(rotation) || !node.absoluteBoundingBox) {
|
2024-05-29 03:30:56 -05:00
|
|
|
return {
|
|
|
|
x,
|
|
|
|
y,
|
2024-06-17 05:14:16 -05:00
|
|
|
...translateZeroRotation()
|
2024-05-29 03:30:56 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-14 03:33:23 -05:00
|
|
|
const referencePoint = applyInverseRotation(
|
|
|
|
{ x, y },
|
|
|
|
node.absoluteTransform,
|
|
|
|
node.absoluteBoundingBox
|
|
|
|
);
|
2024-05-29 03:30:56 -05:00
|
|
|
|
|
|
|
return {
|
2024-06-14 03:33:23 -05:00
|
|
|
...referencePoint,
|
2024-06-17 05:14:16 -05:00
|
|
|
...translateRotation(node.absoluteTransform, rotation)
|
2024-05-29 03:30:56 -05:00
|
|
|
};
|
|
|
|
};
|