export type Position = { x: number y: number } export class SuperPath2D { pathData: string legacyPath: Path2D constructor() { this.pathData = '' this.legacyPath = new Path2D() } moveTo(position: Position): void { this.legacyPath.moveTo(position.x, position.y) this.pathData += `M ${position.x} ${position.y} ` } lineTo(position: Position): void { this.legacyPath.lineTo(position.x, position.y) this.pathData += `L ${position.x} ${position.y} ` } arc(centerPosition: Position, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void { this.legacyPath.arc(centerPosition.x, centerPosition.y, radius, startAngle, endAngle, anticlockwise) this.pathData += `A ${radius} ${radius} 0 0 ${anticlockwise ? 0 : 1} ${ centerPosition.x + radius * Math.cos(endAngle) } ${centerPosition.y + radius * Math.sin(endAngle)} ` } bezierCurveTo(cp1: Position, cp2: Position, endPoint: Position): void { this.legacyPath.bezierCurveTo(cp1.x, cp1.y, cp2.x, cp2.y, endPoint.x, endPoint.y) this.pathData += `C ${cp1.x} ${cp1.y} ${cp2.x} ${cp2.y} ${endPoint.x} ${endPoint.y} ` } toString(): string { return this.pathData.trim() } toPath2D(): Path2D { return this.legacyPath } addPath(path: Path2D): void { this.legacyPath.addPath(path) } closePath(): void { this.legacyPath.closePath() this.pathData += 'Z' } }