2020-12-24 01:17:12 +02:00
|
|
|
// Converts world coordinate to screen coordinates by applying the current
|
2021-01-07 23:44:31 +02:00
|
|
|
// zoom. `windowContentZoomFactor` is the setting value.
|
|
|
|
export default function convertToScreenCoordinates(windowContentZoomFactor: number, o: any): any {
|
|
|
|
const percent = windowContentZoomFactor / 100;
|
2020-12-24 01:17:12 +02:00
|
|
|
|
2021-01-07 23:44:31 +02:00
|
|
|
if (typeof o === 'number') return o * percent;
|
2020-12-24 01:17:12 +02:00
|
|
|
|
|
|
|
if (typeof o === 'object' && o !== null) {
|
|
|
|
o = JSON.parse(JSON.stringify(o));
|
|
|
|
for (const k of Object.keys(o)) {
|
2021-01-07 23:44:31 +02:00
|
|
|
o[k] = convertToScreenCoordinates(windowContentZoomFactor, o[k]);
|
2020-12-24 01:17:12 +02:00
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error(`Cannot convert to screen coordinates: ${typeof o}`);
|
|
|
|
}
|