From d0ca68d014206a7e72299668fca597a8a140b984 Mon Sep 17 00:00:00 2001 From: hamed musallam Date: Mon, 16 Dec 2024 11:26:47 +0100 Subject: [PATCH] feat: improve path builder --- src/component/utility/PathBuilder.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/component/utility/PathBuilder.ts b/src/component/utility/PathBuilder.ts index 861f94db2..16c3b989e 100644 --- a/src/component/utility/PathBuilder.ts +++ b/src/component/utility/PathBuilder.ts @@ -1,28 +1,32 @@ export class PathBuilder { - private array: string[] = []; + private path = ''; + + private appendPath(segment: string) { + this.path += `${segment} `; + } public moveTo(x: number, y: number) { x = clamp(x); y = clamp(y); - this.array.push(`M ${x} ${y}`); + this.appendPath(`M ${x} ${y}`); } public lineTo(x: number, y: number) { x = clamp(x); y = clamp(y); - this.array.push(`L ${x} ${y}`); + this.appendPath(`L ${x} ${y}`); } public closePath() { - if (this.array.length > 0) this.array.push('Z'); + if (this.path.length > 0) this.appendPath('Z'); } public toString() { - return this.array.join(' '); + return this.path.trim(); } public concatPath(pathBuilder: PathBuilder) { - return this.array.concat(pathBuilder.array).join(' '); + return (this.path + pathBuilder.path).trim(); } }