Skip to content

Commit

Permalink
refactor(geom-axidraw): internal updates to use new geom types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 21, 2024
1 parent 89cff45 commit d75b4df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/geom-axidraw/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Fn } from "@thi.ng/api";
import type { DrawCommand } from "@thi.ng/axidraw";
import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
import type { IShape2, SamplingOpts } from "@thi.ng/geom-api";
import type { ReadonlyVec } from "@thi.ng/vectors";

/**
Expand Down Expand Up @@ -121,4 +121,4 @@ export interface InterleaveOpts {

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

export type ShapeOrdering = Fn<IShape[], Iterable<IShape>>;
export type ShapeOrdering = Fn<IShape2[], Iterable<IShape2>>;
6 changes: 3 additions & 3 deletions packages/geom-axidraw/src/as-axidraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { polyline } from "@thi.ng/axidraw/polyline";
import type { MultiFn1O } from "@thi.ng/defmulti";
import { defmulti } from "@thi.ng/defmulti/defmulti";
import type { Circle, ComplexPolygon, Group, Polyline } from "@thi.ng/geom";
import type { Attribs, IHiccupShape, IShape, PCLike } from "@thi.ng/geom-api";
import type { Attribs, IHiccupShape2, IShape2, 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";
Expand Down Expand Up @@ -68,7 +68,7 @@ import { pointsByNearestNeighbor } from "./sort.js";
* ```
*/
export const asAxiDraw: MultiFn1O<
IShape,
IShape2,
Partial<AsAxiDrawOpts>,
Iterable<DrawCommand>
> = defmulti<any, Maybe<Partial<AsAxiDrawOpts>>, Iterable<DrawCommand>>(
Expand Down Expand Up @@ -123,7 +123,7 @@ function* __group(
const $sampleOpts = __sampleAttribs(opts?.samples, $.attribs);
const { skip, sort, interleave } = __axiAttribs($.attribs);
const children = skip ? [...takeNth(skip + 1, $.children)] : $.children;
function* emitChunk(chunk: IHiccupShape[]) {
function* emitChunk(chunk: IHiccupShape2[]) {
const iter = sort ? (<ShapeOrdering>sort)(chunk) : chunk;
for (let child of iter) {
const shape = applyTransforms(child);
Expand Down
14 changes: 8 additions & 6 deletions packages/geom-axidraw/src/sort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { compareNumAsc } from "@thi.ng/compare/numeric";
import { KdTreeSet } from "@thi.ng/geom-accel/kd-tree-set";
import type {
IRegionQuery,
IShape,
IShape2,
ISpatialMap,
ISpatialSet,
} from "@thi.ng/geom-api";
Expand Down Expand Up @@ -66,7 +66,7 @@ export const pointsByProximity =
*/
export const shapesByProximity =
(ref: ReadonlyVec = ZERO2): ShapeOrdering =>
(shapes: IShape[]) => {
(shapes: IShape2[]) => {
return sortByCachedKey(
shapes.slice(),
(s) => distSq2(centroid(s) || ZERO2, ref!),
Expand All @@ -89,13 +89,15 @@ export const shapesByProximity =
* @param ref
*/
export const shapesByNearestNeighbor = (
accel: ISpatialMap<ReadonlyVec, IShape> &
IRegionQuery<ReadonlyVec, IShape, number>,
accel: ISpatialMap<ReadonlyVec, IShape2> &
IRegionQuery<ReadonlyVec, IShape2, number>,
ref: ReadonlyVec = ZERO2
): ShapeOrdering =>
function* (shapes: IShape[]) {
function* (shapes: IShape2[]) {
accel.into(
shapes.map((s) => <[ReadonlyVec, IShape]>[centroid(s) || [0, 0], s])
shapes.map(
(s) => <[ReadonlyVec, IShape2]>[centroid(s) || [0, 0], s]
)
);
while (accel.size) {
const pair = accel.query(ref, 1e4, 1)[0];
Expand Down

0 comments on commit d75b4df

Please sign in to comment.