2024-04-15 02:48:03 -05:00
|
|
|
import { applyMatrixToPoint } from '@plugin/utils/applyMatrixToPoint';
|
|
|
|
import { matrixInvert } from '@plugin/utils/matrixInvert';
|
|
|
|
|
2024-05-13 09:44:00 -05:00
|
|
|
export const calculateLinearGradient = (t: Transform): { start: number[]; end: number[] } => {
|
2024-04-15 02:48:03 -05:00
|
|
|
const transform = t.length === 2 ? [...t, [0, 0, 1]] : [...t];
|
|
|
|
const mxInv = matrixInvert(transform);
|
|
|
|
|
|
|
|
if (!mxInv) {
|
|
|
|
return {
|
|
|
|
start: [0, 0],
|
|
|
|
end: [0, 0]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const startEnd = [
|
|
|
|
[0, 0.5],
|
|
|
|
[1, 0.5]
|
|
|
|
].map(p => applyMatrixToPoint(mxInv, p));
|
2024-05-13 09:44:00 -05:00
|
|
|
|
2024-04-15 02:48:03 -05:00
|
|
|
return {
|
2024-05-13 09:44:00 -05:00
|
|
|
start: [startEnd[0][0], startEnd[0][1]],
|
|
|
|
end: [startEnd[1][0], startEnd[1][1]]
|
2024-04-15 02:48:03 -05:00
|
|
|
};
|
|
|
|
};
|