-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "@g43/tools", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"exports": "./src/index.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./g-map.ts"; | ||
export * from "./path-2d.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { ReadonlySimpleVector2 } from "@g43/types"; | ||
|
||
export class Path2D<T extends ReadonlySimpleVector2> { | ||
public constructor(protected readonly points: readonly T[]) { | ||
if (points.length < 2) { | ||
throw new Error("Cannot create path with less than 2 points"); | ||
} | ||
} | ||
|
||
public getFirstN(count: number): readonly ReadonlySimpleVector2[] { | ||
return this.points.slice(0, count); | ||
} | ||
|
||
public getLastN(count: number): readonly ReadonlySimpleVector2[] { | ||
return this.points.slice(this.points.length - count, this.points.length); | ||
} | ||
|
||
public get length(): number { | ||
return this.points.length; | ||
} | ||
|
||
public get first(): T { | ||
return this.points[0]; | ||
} | ||
|
||
public get last(): T { | ||
return this.points[this.points.length - 1]; | ||
} | ||
|
||
public getPoint(index: number): T { | ||
return this.points[index]; | ||
} | ||
} |