UNPKG

web-ui-pack

Version:
19 lines (18 loc) 599 B
export function mathFixFP(v) { if (Number.isInteger(v)) { return v; } return Number(v.toPrecision(15)); } export function mathScaleValue(v, fromMin, fromMax, toMin, toMax) { const span = (toMax - toMin) / (fromMax - fromMin); return span * (v - fromMin) + toMin; } export function mathRotate(cx, cy, x, y, angle) { const rad = (Math.PI / 180) * angle; const cos = Math.cos(rad); const sin = Math.sin(rad); const nx = cos * (x - cx) - sin * (y - cy) + cx; const ny = cos * (y - cy) + sin * (x - cx) + cy; return [Math.round(nx), Math.round(ny)]; }