diff options
author | mehekj <mehek.jethani@gmail.com> | 2022-02-03 18:03:52 -0500 |
---|---|---|
committer | mehekj <mehek.jethani@gmail.com> | 2022-02-03 18:03:52 -0500 |
commit | 922747ad959e95b592b4cde951b31f5503b8970b (patch) | |
tree | e25d747ba02b4cbfd76910b862b6aac104614daf /src/fields/InkField.ts | |
parent | 30369cd78c1815a81bfe153c5a2d4551ad90dbe0 (diff) | |
parent | 4cdfa6c29701d372064eb4dc612807a27cb19857 (diff) |
Merge branch 'master' into temporalmedia-mehek
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); } |