forked from kofifus/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanvasToPixel.js
23 lines (20 loc) · 915 Bytes
/
canvasToPixel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { getEnabledElement } from './enabledElements.js';
import getTransform from './internal/getTransform.js';
/**
* Converts a point in the canvas coordinate system to the pixel coordinate system
* system. This can be used to reset tools' image coordinates after modifications
* have been made in canvas space (e.g. moving a tool by a few cm, independent of
* image resolution).
*
* @param {HTMLElement} element The Cornerstone element within which the input point lies
* @param {{x: Number, y: Number}} pt The input point in the canvas coordinate system
*
* @returns {{x: Number, y: Number}} The transformed point in the pixel coordinate system
* @memberof PixelCoordinateSystem
*/
export default function (element, pt) {
const enabledElement = getEnabledElement(element);
const transform = getTransform(enabledElement);
transform.invert();
return transform.transformPoint(pt.x, pt.y);
}