Skip to content

Commit

Permalink
feat(geom): update asPolyline() impls
Browse files Browse the repository at this point in the history
- add arc & quadratic support
  • Loading branch information
postspectacular committed Apr 24, 2020
1 parent ef68a27 commit cca8574
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/geom/src/ops/as-polyline.ts
@@ -1,3 +1,4 @@
import type { IObjectOf } from "@thi.ng/api";
import { defmulti, Implementation1O, MultiFn1O } from "@thi.ng/defmulti";
import { IShape, SamplingOpts, Type } from "@thi.ng/geom-api";
import { Cubic } from "../api/cubic";
Expand All @@ -6,7 +7,6 @@ import { Polyline } from "../api/polyline";
import { copyAttribs } from "../internal/copy-attribs";
import { dispatch } from "../internal/dispatch";
import { vertices } from "./vertices";
import type { IObjectOf } from "@thi.ng/api";

export const asPolyline: MultiFn1O<
IShape,
Expand All @@ -19,7 +19,7 @@ asPolyline.addAll(<
Implementation1O<unknown, number | Partial<SamplingOpts>, Polyline>
>
>{
[Type.CUBIC]: ($:Cubic, opts) => new Polyline(vertices($, opts)),
[Type.CUBIC]: ($: Cubic, opts) => new Polyline(vertices($, opts)),

[Type.POINTS]: ($: IShape, opts) =>
new Polyline(vertices($, opts), copyAttribs($)),
Expand All @@ -35,13 +35,15 @@ asPolyline.addAll(<
[Type.POLYGON]: ($: IShape, opts) => {
const pts = vertices($, opts);
return new Polyline(pts.concat([pts[0]]), copyAttribs($));
}
},
});

asPolyline.isa(Type.ARC, Type.CUBIC);
asPolyline.isa(Type.CIRCLE, Type.POLYGON);
asPolyline.isa(Type.ELLIPSE, Type.POLYGON);
asPolyline.isa(Type.LINE, Type.POINTS);
asPolyline.isa(Type.POLYLINE, Type.POINTS);
asPolyline.isa(Type.QUAD, Type.POLYGON);
asPolyline.isa(Type.QUADRATIC, Type.CUBIC);
asPolyline.isa(Type.RECT, Type.POLYGON);
asPolyline.isa(Type.TRIANGLE, Type.POLYGON);

0 comments on commit cca8574

Please sign in to comment.