Skip to content

Commit

Permalink
feat(geom-axidraw): add/update AsAxiDrawOpts
Browse files Browse the repository at this point in the history
- update points & polyline handling
  • Loading branch information
postspectacular committed Dec 9, 2022
1 parent b6262c2 commit 24f8abe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/geom-axidraw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
},
"./as-axidraw": {
"default": "./as-axidraw.js"
},
"./sort": {
"default": "./sort.js"
}
},
"thi.ng": {
Expand Down
17 changes: 13 additions & 4 deletions packages/geom-axidraw/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
* Package-specific shape attributes used to control conversion behavior. MUST
* be stored under the `__axi` attribute name.
*
* @remark
* Important: TODO keep this in sync with
* [PolylineOpts](https://docs.thi.ng/umbrella/axidraw/interfaces/PolylineOpts.html)
*
* @example
* ```ts
* // a circle which will be drawn at 25% speed
Expand All @@ -23,12 +27,17 @@ export interface AxiDrawAttribs {
*/
speed: number;
/**
* Optional shape specific delay (in ms), e.g. hold time for pen down when
* stippling...
* Optional shape specific delay (in ms), i.e. initial hold time for the
* stroke or when stippling...
*/
delayDown: number;
/**
* Delay for pen up command at the end this particular shape/polyline/point.
*/
delay: number;
delayUp: number;
/**
* Optional pen down position (%).
* PPen down position (%) for this particular shape/polyline. Will be reset
* to globally configured default at the end of the shape.
*/
down: number;
/**
Expand Down
18 changes: 10 additions & 8 deletions packages/geom-axidraw/src/as-axidraw.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DrawCommand, UP } from "@thi.ng/axidraw/api";
import { polyline } from "@thi.ng/axidraw/utils";
import { polyline } from "@thi.ng/axidraw/polyline";
import type { MultiFn1O } from "@thi.ng/defmulti";
import { defmulti } from "@thi.ng/defmulti/defmulti";
import type { Group } from "@thi.ng/geom";
Expand Down Expand Up @@ -118,7 +118,8 @@ function* __points(
opts?: Partial<AsAxiDrawOpts>
): IterableIterator<DrawCommand> {
if (!pts.length) return;
const { clip, delay, down, speed, sort } = __axiAttribs(attribs);
const { clip, delayDown, delayUp, down, speed, sort } =
__axiAttribs(attribs);
const clipPts = clip || opts?.clip;
if (clipPts) {
pts = pts.filter((p) => !!pointInPolygon2(p, clipPts));
Expand All @@ -127,7 +128,11 @@ function* __points(
yield UP;
if (down != undefined) yield ["pen", down];
for (let p of sort ? (<PointOrdering>sort)(pts) : pts) {
yield* [["m", p, speed], ["d", delay], UP];
yield* <DrawCommand[]>[
["m", p, speed],
["d", delayDown],
["up", delayUp],
];
}
if (down != undefined) yield ["pen"];
}
Expand All @@ -138,16 +143,13 @@ function* __polyline(
opts?: Partial<AsAxiDrawOpts>
): IterableIterator<DrawCommand> {
if (!pts.length) return;
const { clip, down, speed } = __axiAttribs(attribs);
const { clip, down, delayDown, delayUp, speed } = __axiAttribs(attribs);
const clipPts = clip || opts?.clip;
const chunks = clipPts ? clipPolylinePoly(pts, clipPts) : [pts];
if (!chunks.length) return;
if (down != undefined) yield ["pen", down];
for (let chunk of chunks) {
yield* polyline(chunk, speed);
yield* polyline(chunk, { down, delayDown, delayUp, speed });
}
// reset pen to configured defaults
if (down != undefined) yield ["pen"];
}

/** @internal */
Expand Down

0 comments on commit 24f8abe

Please sign in to comment.