Skip to content

Commit

Permalink
refactor(geom-axidraw): internal restructure, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 10, 2022
1 parent 2a9e4f7 commit 443c12c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
22 changes: 20 additions & 2 deletions packages/geom-axidraw/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Fn } from "@thi.ng/api";
import type { IShape } from "@thi.ng/geom-api";
import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
import type { ReadonlyVec } from "@thi.ng/vectors";

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ export interface AxiDrawAttribs {
*/
delayUp: number;
/**
* PPen down position (%) for this particular shape/polyline. Will be reset
* Pen down position (%) for this particular shape/polyline. Will be reset
* to globally configured default at the end of the shape.
*/
down: number;
Expand All @@ -55,6 +55,24 @@ export interface AxiDrawAttribs {
sort: PointOrdering | ShapeOrdering;
}

export interface AsAxiDrawOpts {
/**
* Global options for sampling non-polygonal shape. Shapes can also provide
* a `__samples` attribute to override these global options.
*
* @remarks
* References:
* - https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html
* - https://docs.thi.ng/umbrella/geom/functions/vertices.html
*/
samples: number | Partial<SamplingOpts>;
/**
* Clip polygon vertices. Can also be provided per-shape as
* {@link AxiDrawAttribs.clip} (i.e. as part of a shape's `__axi` attrib).
*/
clip: ReadonlyVec[];
}

export type PointOrdering = Fn<ReadonlyVec[], Iterable<ReadonlyVec>>;

export type ShapeOrdering = Fn<IShape[], Iterable<IShape>>;
37 changes: 17 additions & 20 deletions packages/geom-axidraw/src/as-axidraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,21 @@ 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";
import type { Attribs, IShape, PCLike, SamplingOpts } from "@thi.ng/geom-api";
import type { Attribs, 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";
import { applyTransforms } from "@thi.ng/geom/apply-transforms";
import { asPolyline } from "@thi.ng/geom/as-polyline";
import { __dispatch } from "@thi.ng/geom/internal/dispatch";
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { AxiDrawAttribs, PointOrdering, ShapeOrdering } from "./api.js";
import type {
AsAxiDrawOpts,
AxiDrawAttribs,
PointOrdering,
ShapeOrdering,
} from "./api.js";
import { pointsByNearestNeighbor } from "./sort.js";

export interface AsAxiDrawOpts {
/**
* Global options for sampling non-polygonal shape. Shapes can also provide
* a `__samples` attribute to override these global options.
*
* @remarks
* References:
* - https://docs.thi.ng/umbrella/geom-api/interfaces/SamplingOpts.html
* - https://docs.thi.ng/umbrella/geom/functions/vertices.html
*/
samples: number | Partial<SamplingOpts>;
/**
* Clip polygon vertices. Can also be provided per-shape as
* {@link AxiDrawAttribs.clip} (i.e. as part of a shape's `__axi` attrib).
*/
clip: ReadonlyVec[];
}

/**
* Lazily converts given shape (or group) into an iterable of thi.ng/axidraw
* drawing commands, using optionally provided config options.
Expand Down Expand Up @@ -59,6 +46,16 @@ export interface AsAxiDrawOpts {
* - rect
* - triangle
*
* @example
* ```ts
* [...asAxiDraw(circle(100), { samples: 100 })]
* [
* [ 'm', [ 10, 0 ] ],
* [ 'd' ],
* [ 'm', [ 9.980267284282716, 0.6279051952931337 ], undefined ],
* ...
* ]
* ```
*/
export const asAxiDraw: MultiFn1O<
IShape,
Expand Down

0 comments on commit 443c12c

Please sign in to comment.