import { Bezier } from 'bezier-js' import { DaumiShape, getDaumiElementLocation } from './daumiShape' import { getPointOnCurve } from './getPointOnCurve' import { angleBetweenTwoPoints, normalizeRad } from './helperFunctions' import { setDebugVar } from 'utils/debugPoints' import { NemiCurveBezier } from './nemiCurve' import { getAdjustedT } from './bezier' export const getAngleOnDaumiShape = ( chart: { daumiShape: DaumiShape }, percentage: number, ) => { const daumiShape = chart.daumiShape const elementLocation = getDaumiElementLocation(daumiShape, percentage) const curve = elementLocation.element.innerCurve switch (curve.type) { case 'line': { const angle = angleBetweenTwoPoints(curve.startPoint, curve.endPoint) return normalizeRad(angle + Math.PI / 2) } case 'arc': { const { startAngle, radians } = curve return normalizeRad(startAngle + radians * elementLocation.percentageOnElement + Math.PI / 2) } case 'bezier': { const bezier = new Bezier(curve.startPoint, curve.controlPoint1, curve.controlPoint2, curve.endPoint) const normal = bezier.normal(getAdjustedT(bezier, elementLocation.percentageOnElement)) return normalizeRad(Math.atan2(normal.y, normal.x) - Math.PI / 2) } } }