Skip to content

Commit

Permalink
feat(geom): add asPath(), update pathFromCubics() to accept opt attribs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 12, 2019
1 parent 5ca4166 commit 980af9f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/geom/src/ctors/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { arcFrom2Points } from "./arc";
export const path = (segments: PathSegment[], attribs?: Attribs) =>
new Path(segments, attribs);

export const pathFromCubics = (cubics: Cubic[]) => {
const path = new Path([], cubics[0].attribs);
export const pathFromCubics = (cubics: Cubic[], attribs?: Attribs) => {
const path = new Path([], attribs || cubics[0].attribs);
path.segments.push({ type: SegmentType.MOVE, point: cubics[0].points[0] });
for (let c of cubics) {
path.segments.push({ type: SegmentType.CUBIC, geo: c });
Expand Down
1 change: 1 addition & 0 deletions packages/geom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from "./ctors/triangle";
export * from "./ops/arc-length";
export * from "./ops/area";
export * from "./ops/as-cubic";
export * from "./ops/as-path";
export * from "./ops/as-polygon";
export * from "./ops/as-polyline";
export * from "./ops/as-svg";
Expand Down
6 changes: 6 additions & 0 deletions packages/geom/src/ops/as-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Attribs, IShape } from "@thi.ng/geom-api";
import { pathFromCubics } from "../ctors/path";
import { asCubic } from "./as-cubic";

export const asPath = (src: IShape, attribs?: Attribs) =>
pathFromCubics(asCubic(src), attribs);

0 comments on commit 980af9f

Please sign in to comment.