Skip to content

Commit

Permalink
fix(geom): Path.copy() deep-clone behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 8, 2020
1 parent 2b60249 commit 2ade10e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/geom/src/api/path.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { equiv } from "@thi.ng/equiv";
import { illegalState } from "@thi.ng/errors";
import {
Attribs,
IHiccupShape,
PathSegment,
Type
} from "@thi.ng/geom-api";
import { Attribs, IHiccupShape, PathSegment, Type } from "@thi.ng/geom-api";
import { copyAttribs } from "../internal/copy-attribs";
import { copy } from "@thi.ng/vectors";

export class Path implements IHiccupShape {
segments: PathSegment[];
Expand All @@ -28,7 +24,15 @@ export class Path implements IHiccupShape {
}

copy(): Path {
const p = new Path([...this.segments], copyAttribs(this));
const p = new Path(
this.segments.map((s) => {
const d: PathSegment = { type: s.type };
s.point && (d.point = copy(s.point));
s.geo && (d.geo = <any>s.geo.copy());
return d;
}),
copyAttribs(this)
);
p.closed = this.closed;
return p;
}
Expand Down

0 comments on commit 2ade10e

Please sign in to comment.