UNPKG

@ui-tars/shared

Version:
12 lines (11 loc) 392 B
function parseBoxToScreenCoords(boxStr, width, height, factor) { const coords = boxStr.replace("[", "").replace("]", "").split(",").map((num) => parseFloat(num.trim())); const [x1, y1, x2 = x1, y2 = y1] = coords; return { x: Math.round((x1 + x2) / 2 * width * factor) / factor, y: Math.round((y1 + y2) / 2 * height * factor) / factor }; } export { parseBoxToScreenCoords };