Skip to content

Commit

Permalink
fix(geom): fix #268 add Group.copyTransformed()
Browse files Browse the repository at this point in the history
- update transformVertices(), transform(), translate() impls
  • Loading branch information
postspectacular committed Dec 22, 2020
1 parent bda4f75 commit 2da6c63
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
10 changes: 6 additions & 4 deletions packages/geom/src/api/group.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Fn } from "@thi.ng/api";
import { equiv } from "@thi.ng/equiv";
import type { Attribs, IHiccupShape } from "@thi.ng/geom-api";
import { copyAttribs } from "../internal/copy-attribs";
Expand All @@ -17,10 +18,11 @@ export class Group implements IHiccupShape {
}

copy(): Group {
return new Group(
copyAttribs(this),
<IHiccupShape[]>this.children.map((c) => c.copy())
);
return this.copyTransformed((c) => <IHiccupShape>c.copy());
}

copyTransformed(fn: Fn<IHiccupShape, IHiccupShape>) {
return new Group(copyAttribs(this), this.children.map(fn));
}

equiv(o: any) {
Expand Down
7 changes: 2 additions & 5 deletions packages/geom/src/ops/transform-vertices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { mulV, ReadonlyMat } from "@thi.ng/matrices";
import { map } from "@thi.ng/transducers";
import type { ReadonlyVec } from "@thi.ng/vectors";
import { Cubic } from "../api/cubic";
import { Group } from "../api/group";
import type { Group } from "../api/group";
import { Line } from "../api/line";
import { Path } from "../api/path";
import { Points, Points3 } from "../api/points";
Expand Down Expand Up @@ -51,10 +51,7 @@ transformVertices.addAll(<
cubic: tx(Cubic),

group: ($: Group, fn) =>
new Group(
copyAttribs($),
$.children.map((x) => <IHiccupShape>transformVertices(x, fn))
),
$.copyTransformed((x) => <IHiccupShape>transformVertices(x, fn)),

line: tx(Line),

Expand Down
7 changes: 2 additions & 5 deletions packages/geom/src/ops/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IHiccupShape, IShape, PathSegment } from "@thi.ng/geom-api";
import { mulV, ReadonlyMat } from "@thi.ng/matrices";
import { map } from "@thi.ng/transducers";
import { Cubic } from "../api/cubic";
import { Group } from "../api/group";
import type { Group } from "../api/group";
import { Line } from "../api/line";
import { Path } from "../api/path";
import { Points, Points3 } from "../api/points";
Expand Down Expand Up @@ -43,10 +43,7 @@ transform.addAll(<IObjectOf<Implementation2<unknown, ReadonlyMat, IShape>>>{
cubic: tx(Cubic),

group: ($: Group, mat) =>
new Group(
copyAttribs($),
$.children.map((x) => <IHiccupShape>transform(x, mat))
),
$.copyTransformed((x) => <IHiccupShape>transform(x, mat)),

line: tx(Line),

Expand Down
7 changes: 2 additions & 5 deletions packages/geom/src/ops/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { Arc } from "../api/arc";
import { Circle } from "../api/circle";
import { Cubic } from "../api/cubic";
import { Ellipse } from "../api/ellipse";
import { Group } from "../api/group";
import type { Group } from "../api/group";
import { Line } from "../api/line";
import { Path } from "../api/path";
import { Points, Points3 } from "../api/points";
Expand Down Expand Up @@ -45,10 +45,7 @@ translate.addAll(<IObjectOf<Implementation2<unknown, ReadonlyVec, IShape>>>{
new Ellipse(add2([], $.pos, delta), set2([], $.r), copyAttribs($)),

group: ($: Group, delta) =>
new Group(
copyAttribs($),
$.children.map((s) => <IHiccupShape>translate(s, delta))
),
$.copyTransformed((x) => <IHiccupShape>translate(x, delta)),

line: tx(Line),

Expand Down

0 comments on commit 2da6c63

Please sign in to comment.