2020-05-20 16:21:37 +03:00
|
|
|
export const getZoomOrigin = (
|
|
|
|
canvas: HTMLCanvasElement | null,
|
|
|
|
scale: number,
|
|
|
|
) => {
|
2020-02-15 21:03:32 +01:00
|
|
|
if (canvas === null) {
|
|
|
|
return { x: 0, y: 0 };
|
|
|
|
}
|
|
|
|
const context = canvas.getContext("2d");
|
|
|
|
if (context === null) {
|
|
|
|
return { x: 0, y: 0 };
|
|
|
|
}
|
|
|
|
|
2020-03-15 12:25:18 -07:00
|
|
|
const normalizedCanvasWidth = canvas.width / scale;
|
|
|
|
const normalizedCanvasHeight = canvas.height / scale;
|
2020-02-15 21:03:32 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
x: normalizedCanvasWidth / 2,
|
|
|
|
y: normalizedCanvasHeight / 2,
|
|
|
|
};
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|
2020-02-15 21:03:32 +01:00
|
|
|
|
2020-05-20 16:21:37 +03:00
|
|
|
export const getNormalizedZoom = (zoom: number): number => {
|
2020-02-16 14:38:53 +01:00
|
|
|
const normalizedZoom = parseFloat(zoom.toFixed(2));
|
|
|
|
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 2));
|
|
|
|
return clampedZoom;
|
2020-05-20 16:21:37 +03:00
|
|
|
};
|