export interface EventWithPoint {
    readonly clientX: number;
    readonly clientY: number;
}

export const getRealPoint = (canvas: HTMLCanvasElement, e: EventWithPoint): DOMPoint => {
    const matrix = new DOMMatrix();

    const box = canvas.getBoundingClientRect();
    const scale = Math.min(box.width / canvas.width, box.height / canvas.height);

    matrix.translateSelf(box.left, box.top);
    matrix.scaleSelf(scale);
    matrix.invertSelf();

    const point = new DOMPoint(e.clientX, e.clientY);

    return point.matrixTransform(matrix);
}
