diff options
| author | Aubrey Li <Aubrey-Li> | 2021-12-02 15:06:27 -0500 |
|---|---|---|
| committer | Aubrey Li <Aubrey-Li> | 2021-12-02 15:06:27 -0500 |
| commit | 3ce1455986d4f42c75c8aabc8aec56805e655747 (patch) | |
| tree | 82eb891e8f7093cf60962a6fb92a1ef642a4c194 /src/fields/InkField.ts | |
| parent | 657a4c11b6b1526bacc79fbefe4b461e932c75e7 (diff) | |
| parent | 2cb18e75aa487ff98086e15fef93e2f549c30496 (diff) | |
Merge branch 'trails-aubrey' of https://github.com/brown-dash/Dash-Web into trails-aubrey
Diffstat (limited to 'src/fields/InkField.ts')
| -rw-r--r-- | src/fields/InkField.ts | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts index f16e143d8..560cf3d63 100644 --- a/src/fields/InkField.ts +++ b/src/fields/InkField.ts @@ -3,6 +3,7 @@ import { Scripting } from "../client/util/Scripting"; import { Deserializable } from "../client/util/SerializationHelper"; import { Copy, ToScriptString, ToString } from "./FieldSymbols"; import { ObjectField } from "./ObjectField"; +import { Bezier } from "bezier-js"; // Helps keep track of the current ink tool in use. export enum InkTool { @@ -20,6 +21,8 @@ export interface PointData { Y: number; } +export type Segment = Array<Bezier>; + // Defines an ink as an array of points. export type InkData = Array<PointData>; @@ -67,6 +70,14 @@ export class InkField extends ObjectField { this.inkData = data; } + /** + * Extacts a simple segment from a compound Bezier curve + * @param segIndex the start index of the simple bezier segment to extact (eg., 0, 4, 8, ...) + */ + public static Segment(inkData: InkData, segIndex: number) { + return new Bezier(inkData.slice(segIndex, segIndex + 4).map(pt => ({ x: pt.X, y: pt.Y }))); + } + [Copy]() { return new InkField(this.inkData); } |
