import { NemiCurve } from './nemiCurve' import { Position } from './SuperPath2D' import { Bezier } from 'bezier-js' import { getAdjustedT } from './bezier' export const getPointOnCurve = (curve: NemiCurve, percentage: number): Position => { switch (curve.type) { case 'line': { return { x: curve.startPoint.x + percentage * (curve.endPoint.x - curve.startPoint.x), y: curve.startPoint.y + percentage * (curve.endPoint.y - curve.startPoint.y), } } case 'arc': { const angle = curve.startAngle + percentage * curve.radians return { x: curve.centerPoint.x + Math.cos(angle) * curve.radius, y: curve.centerPoint.y + Math.sin(angle) * curve.radius, } } case 'bezier': { // Using the functions above in your specific case const bezier = new Bezier(curve.startPoint, curve.controlPoint1, curve.controlPoint2, curve.endPoint) const pointOnCurve = bezier.get(getAdjustedT(bezier, percentage)) return { x: pointOnCurve.x, y: pointOnCurve.y, } } } }