import*as Platform from"../platform/platform.js";import*as UI from"../ui/ui.js";export const CSSAngleRegex=/(?<value>[+-]?\d*\.?\d+)(?<unit>deg|grad|rad|turn)/;export const parseText=e=>{const t=e.match(CSSAngleRegex);return t&&t.groups?{value:Number(t.groups.value),unit:t.groups.unit}:null};export const getAngleFromRadians=(e,t)=>{let r=e;switch(t){case"grad":r=UI.Geometry.radiansToGradians(e);break;case"deg":r=UI.Geometry.radiansToDegrees(e);break;case"turn":r=UI.Geometry.radiansToTurns(e)}return{value:r,unit:t}};export const getRadiansFromAngle=e=>{switch(e.unit){case"deg":return UI.Geometry.degreesToRadians(e.value);case"grad":return UI.Geometry.gradiansToRadians(e.value);case"turn":return UI.Geometry.turnsToRadians(e.value)}return e.value};export const get2DTranslationsForAngle=(e,t)=>{const r=getRadiansFromAngle(e);return{translateX:Math.sin(r)*t,translateY:-Math.cos(r)*t}};export const roundAngleByUnit=e=>{let t=e.value;switch(e.unit){case"deg":case"grad":t=Math.round(e.value);break;case"rad":t=Math.round(1e4*e.value)/1e4;break;case"turn":t=Math.round(100*e.value)/100;break;default:Platform.assertNever(e.unit,`Unknown angle unit: ${e.unit}`)}return{value:t,unit:e.unit}};export const getNextUnit=e=>{switch(e){case"deg":return"grad";case"grad":return"rad";case"rad":return"turn";default:return"deg"}};export const convertAngleUnit=(e,t)=>{if(e.unit===t)return e;const r=getRadiansFromAngle(e);return getAngleFromRadians(r,t)};export const getNewAngleFromEvent=(e,t)=>{const r=UI.UIUtils.getValueModificationDirection(t);if(null===r)return;let n="Up"===r?Math.PI/180:-Math.PI/180;t.shiftKey&&(n*=10);const a=getRadiansFromAngle(e);return getAngleFromRadians(a+n,e.unit)};