Skip to content

Commit

Permalink
refactor(geom-axidraw): update asAxiDraw() impls
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 5, 2024
1 parent 76aa229 commit fca73d6
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions packages/geom-axidraw/src/as-axidraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DOWN, MOVE, UP } from "@thi.ng/axidraw/commands";
import { polyline } from "@thi.ng/axidraw/polyline";
import type { MultiFn1O } from "@thi.ng/defmulti";
import { defmulti } from "@thi.ng/defmulti/defmulti";
import type { ComplexPolygon, Group } from "@thi.ng/geom";
import type { Circle, ComplexPolygon, Group, Polyline } from "@thi.ng/geom";
import type { Attribs, IHiccupShape, IShape, PCLike } from "@thi.ng/geom-api";
import { clipPolylinePoly } from "@thi.ng/geom-clip-line/clip-poly";
import { pointInPolygon2 } from "@thi.ng/geom-isec/point";
Expand All @@ -13,8 +13,6 @@ import { asPolyline } from "@thi.ng/geom/as-polyline";
import { __dispatch } from "@thi.ng/geom/internal/dispatch";
import { __sampleAttribs } from "@thi.ng/geom/internal/vertices";
import { withAttribs } from "@thi.ng/geom/with-attribs";
import { concat } from "@thi.ng/transducers/concat";
import { map } from "@thi.ng/transducers/map";
import { mapcat } from "@thi.ng/transducers/mapcat";
import { takeNth } from "@thi.ng/transducers/take-nth";
import type { ReadonlyVec } from "@thi.ng/vectors";
Expand Down Expand Up @@ -73,7 +71,7 @@ export const asAxiDraw: MultiFn1O<
IShape,
Partial<AsAxiDrawOpts>,
Iterable<DrawCommand>
> = defmulti<IShape, Maybe<Partial<AsAxiDrawOpts>>, Iterable<DrawCommand>>(
> = defmulti<any, Maybe<Partial<AsAxiDrawOpts>>, Iterable<DrawCommand>>(
__dispatch,
{
arc: "circle",
Expand All @@ -88,42 +86,36 @@ export const asAxiDraw: MultiFn1O<
tri: "polyline",
},
{
points: ($, opts) =>
points: ($: PCLike, opts) =>
__points((<PCLike>applyTransforms($)).points, $.attribs, opts),

// used for all shapes which need to be sampled
circle: ($, opts) =>
circle: ($: Circle, opts) =>
mapcat(
(line) => __polyline(line.points, $.attribs, opts),
asPolyline(applyTransforms($), opts?.samples)
),

complexpoly: ($, opts) =>
concat(
asAxiDraw(
withAttribs((<ComplexPolygon>$).boundary, $.attribs, false),
opts
),
...map(
(child) =>
asAxiDraw(withAttribs(child, $.attribs, false), opts),
(<ComplexPolygon>$).children
)
complexpoly: ($: ComplexPolygon, opts) =>
mapcat(
(poly) => asAxiDraw(withAttribs(poly, $.attribs, false), opts),
[$.boundary, ...$.children]
),

// ignore sample opts for polyline & other polygonal shapes
// i.e. use points verbatim
polyline: ($, opts) =>
polyline: ($: Polyline, opts) =>
__polyline(
asPolyline(applyTransforms($))[0].points,
$.attribs,
opts
),

group: ($, opts) => __group(<Group>$, opts),
group: __group,
}
);

/** @internal */
function* __group(
$: Group,
opts?: Partial<AsAxiDrawOpts>
Expand Down Expand Up @@ -157,6 +149,7 @@ function* __group(
}
}

/** @internal */
function* __points(
pts: ReadonlyVec[],
attribs?: Attribs,
Expand Down Expand Up @@ -205,6 +198,7 @@ function* __points(
}
}

/** @internal */
function* __polyline(
pts: ReadonlyVec[],
attribs?: Attribs,
Expand Down

0 comments on commit fca73d6

Please sign in to comment.