Skip to content

Commit 24f8abe

Browse files
feat(geom-axidraw): add/update AsAxiDrawOpts
- update points & polyline handling
1 parent b6262c2 commit 24f8abe

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

packages/geom-axidraw/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
},
8181
"./as-axidraw": {
8282
"default": "./as-axidraw.js"
83+
},
84+
"./sort": {
85+
"default": "./sort.js"
8386
}
8487
},
8588
"thi.ng": {

packages/geom-axidraw/src/api.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type { ReadonlyVec } from "@thi.ng/vectors";
66
* Package-specific shape attributes used to control conversion behavior. MUST
77
* be stored under the `__axi` attribute name.
88
*
9+
* @remark
10+
* Important: TODO keep this in sync with
11+
* [PolylineOpts](https://docs.thi.ng/umbrella/axidraw/interfaces/PolylineOpts.html)
12+
*
913
* @example
1014
* ```ts
1115
* // a circle which will be drawn at 25% speed
@@ -23,12 +27,17 @@ export interface AxiDrawAttribs {
2327
*/
2428
speed: number;
2529
/**
26-
* Optional shape specific delay (in ms), e.g. hold time for pen down when
27-
* stippling...
30+
* Optional shape specific delay (in ms), i.e. initial hold time for the
31+
* stroke or when stippling...
32+
*/
33+
delayDown: number;
34+
/**
35+
* Delay for pen up command at the end this particular shape/polyline/point.
2836
*/
29-
delay: number;
37+
delayUp: number;
3038
/**
31-
* Optional pen down position (%).
39+
* PPen down position (%) for this particular shape/polyline. Will be reset
40+
* to globally configured default at the end of the shape.
3241
*/
3342
down: number;
3443
/**

packages/geom-axidraw/src/as-axidraw.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DrawCommand, UP } from "@thi.ng/axidraw/api";
2-
import { polyline } from "@thi.ng/axidraw/utils";
2+
import { polyline } from "@thi.ng/axidraw/polyline";
33
import type { MultiFn1O } from "@thi.ng/defmulti";
44
import { defmulti } from "@thi.ng/defmulti/defmulti";
55
import type { Group } from "@thi.ng/geom";
@@ -118,7 +118,8 @@ function* __points(
118118
opts?: Partial<AsAxiDrawOpts>
119119
): IterableIterator<DrawCommand> {
120120
if (!pts.length) return;
121-
const { clip, delay, down, speed, sort } = __axiAttribs(attribs);
121+
const { clip, delayDown, delayUp, down, speed, sort } =
122+
__axiAttribs(attribs);
122123
const clipPts = clip || opts?.clip;
123124
if (clipPts) {
124125
pts = pts.filter((p) => !!pointInPolygon2(p, clipPts));
@@ -127,7 +128,11 @@ function* __points(
127128
yield UP;
128129
if (down != undefined) yield ["pen", down];
129130
for (let p of sort ? (<PointOrdering>sort)(pts) : pts) {
130-
yield* [["m", p, speed], ["d", delay], UP];
131+
yield* <DrawCommand[]>[
132+
["m", p, speed],
133+
["d", delayDown],
134+
["up", delayUp],
135+
];
131136
}
132137
if (down != undefined) yield ["pen"];
133138
}
@@ -138,16 +143,13 @@ function* __polyline(
138143
opts?: Partial<AsAxiDrawOpts>
139144
): IterableIterator<DrawCommand> {
140145
if (!pts.length) return;
141-
const { clip, down, speed } = __axiAttribs(attribs);
146+
const { clip, down, delayDown, delayUp, speed } = __axiAttribs(attribs);
142147
const clipPts = clip || opts?.clip;
143148
const chunks = clipPts ? clipPolylinePoly(pts, clipPts) : [pts];
144149
if (!chunks.length) return;
145-
if (down != undefined) yield ["pen", down];
146150
for (let chunk of chunks) {
147-
yield* polyline(chunk, speed);
151+
yield* polyline(chunk, { down, delayDown, delayUp, speed });
148152
}
149-
// reset pen to configured defaults
150-
if (down != undefined) yield ["pen"];
151153
}
152154

153155
/** @internal */

0 commit comments

Comments
 (0)