Skip to content

Commit

Permalink
feat(geom): update edges(), support more types
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 28, 2022
1 parent e2f3ab9 commit 3e1b340
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions packages/geom/src/edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,41 @@ import { defmulti } from "@thi.ng/defmulti/defmulti";
import type { IShape, SamplingOpts } from "@thi.ng/geom-api";
import type { VecPair } from "@thi.ng/vectors";
import type { AABB } from "./api/aabb.js";
import type { Arc } from "./api/arc.js";
import type { BPatch } from "./api/bpatch.js";
import type { Circle } from "./api/circle.js";
import type { Path } from "./api/path.js";
import type { Polygon } from "./api/polygon.js";
import type { Polyline } from "./api/polyline.js";
import type { Rect } from "./api/rect.js";
import { asPolygon } from "./as-polygon.js";
import { asPolyline } from "./as-polyline.js";
import { __dispatch } from "./internal/dispatch.js";
import { __edges } from "./internal/edges.js";
import { vertices } from "./vertices.js";

/**
* Extracts the edges of given shape's boundary and returns them as an iterable.
* Some shapes also support {@link @thi.ng/geom-api#SamplingOpts}.
* Extracts the edges of given shape's boundary and returns them as an iterable
* of vector pairs. Some shapes also support
* {@link @thi.ng/geom-api#SamplingOpts}.
*
* @remarks
* Currently implemented for:
*
* - {@line AABB}
* - {@line Line}
* - {@line Polygon}
* - {@line Polyline}
* - {@line Quad}
* - {@line Rect}
* - {@line Triangle}
* - {@link AABB}
* - {@link Arc}
* - {@link BPatch}
* - {@link Circle}
* - {@link Cubic}
* - {@link Ellipse}
* - {@link Line}
* - {@link Path}
* - {@link Polygon}
* - {@link Polyline}
* - {@link Quad}
* - {@link Quadratic}
* - {@link Rect}
* - {@link Triangle}
*
* @param shape
* @param opts
Expand All @@ -39,8 +53,11 @@ export const edges: MultiFn1O<
>(
__dispatch,
{
cubic: "arc",
ellipse: "circle",
line: "polyline",
quad: "poly",
quadratic: "arc",
tri: "poly",
},
{
Expand All @@ -62,6 +79,14 @@ export const edges: MultiFn1O<
];
},

arc: ($: Arc, opts) => __edges(asPolyline($, opts).points, false),

bpatch: ($: BPatch) => $.edges(),

circle: ($: Circle, opts) => __edges(asPolygon($, opts).points, true),

path: ($: Path, opts) => __edges(asPolygon($, opts).points, $.closed),

poly: ($: Polygon) => __edges($.points, true),

polyline: ($: Polyline) => __edges($.points),
Expand Down

0 comments on commit 3e1b340

Please sign in to comment.