Skip to content

Commit

Permalink
feat(geom): add complexPolygonFromPath()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 5, 2024
1 parent 83f3022 commit cd526f1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/geom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@
"./closest-point": {
"default": "./closest-point.js"
},
"./complex-polygon-from-path": {
"default": "./complex-polygon-from-path.js"
},
"./complex-polygon": {
"default": "./complex-polygon.js"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/geom/src/complex-polygon-from-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Attribs, SamplingOpts } from "@thi.ng/geom-api";
import { ComplexPolygon } from "./api/complex-polygon.js";
import type { Path } from "./api/path.js";
import { asPolygon } from "./as-polygon.js";

/**
* Converts given path into a {@link ComplexPolygon}, using `opts` to control
* the conversion (via {@link asPolygon}). If no new `attribs` are given, those
* of the path will be used (shallow copy).
*
* @param path
* @param opts
* @param attribs
*/
export const complexPolygonFromPath = (
path: Path,
opts?: number | Partial<SamplingOpts>,
attribs?: Attribs
) => {
const [boundary, ...children] = asPolygon(path, opts);
return new ComplexPolygon(boundary, children, attribs || boundary.attribs);
};
1 change: 1 addition & 0 deletions packages/geom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export * from "./arc.js";
export * from "./bpatch.js";
export * from "./circle.js";
export * from "./complex-polygon.js";
export * from "./complex-polygon-from-path.js";
export * from "./cubic.js";
export * from "./ellipse.js";
export * from "./group.js";
Expand Down

0 comments on commit cd526f1

Please sign in to comment.