Skip to content

Commit

Permalink
refactor(geom): update PCLike copy() impls, add copyShape() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 21, 2019
1 parent ded89c2 commit bc20135
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 27 deletions.
5 changes: 2 additions & 3 deletions packages/geom/src/api/cubic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupPathSegment, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Cubic extends APC implements IHiccupPathSegment {
Expand All @@ -9,7 +8,7 @@ export class Cubic extends APC implements IHiccupPathSegment {
}

copy(): Cubic {
return new Cubic(copyVectors(this.points), copyAttribs(this));
return <Cubic>copyShape(Cubic, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/line.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupPathSegment, IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Line extends APC implements IHiccupShape, IHiccupPathSegment {
Expand All @@ -9,7 +8,7 @@ export class Line extends APC implements IHiccupShape, IHiccupPathSegment {
}

copy(): Line {
return new Line(copyVectors(this.points), copyAttribs(this));
return <Line>copyShape(Line, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/points.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Points extends APC implements IHiccupShape {
Expand All @@ -9,7 +8,7 @@ export class Points extends APC implements IHiccupShape {
}

copy(): Points {
return new Points(copyVectors(this.points), copyAttribs(this));
return <Points>copyShape(Points, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Polygon extends APC implements IHiccupShape {
Expand All @@ -9,7 +8,7 @@ export class Polygon extends APC implements IHiccupShape {
}

copy(): Polygon {
return new Polygon(copyVectors(this.points), copyAttribs(this));
return <Polygon>copyShape(Polygon, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/polyline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupPathSegment, IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Polyline extends APC implements IHiccupShape, IHiccupPathSegment {
Expand All @@ -9,7 +8,7 @@ export class Polyline extends APC implements IHiccupShape, IHiccupPathSegment {
}

copy(): Polyline {
return new Polyline(copyVectors(this.points), copyAttribs(this));
return <Polyline>copyShape(Polyline, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/quad.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Quad extends APC implements IHiccupShape {
Expand All @@ -9,7 +8,7 @@ export class Quad extends APC implements IHiccupShape {
}

copy(): Quad {
return new Quad(copyVectors(this.points), copyAttribs(this));
return <Quad>copyShape(Quad, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/quad3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Quad3 extends APC implements IHiccupShape {
Expand All @@ -9,7 +8,7 @@ export class Quad3 extends APC implements IHiccupShape {
}

copy(): Quad3 {
return new Quad3(copyVectors(this.points), copyAttribs(this));
return <Quad3>copyShape(Quad3, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/quadratic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupPathSegment, IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Quadratic extends APC implements IHiccupShape, IHiccupPathSegment {
Expand All @@ -9,7 +8,7 @@ export class Quadratic extends APC implements IHiccupShape, IHiccupPathSegment {
}

copy(): Quadratic {
return new Quadratic(copyVectors(this.points), copyAttribs(this));
return <Quadratic>copyShape(Quadratic, this);
}

toHiccup() {
Expand Down
5 changes: 2 additions & 3 deletions packages/geom/src/api/triangle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";
import { copyShape } from "../internal/copy-shape";
import { APC } from "./apc";

export class Triangle extends APC implements IHiccupShape {
Expand All @@ -9,7 +8,7 @@ export class Triangle extends APC implements IHiccupShape {
}

copy(): Triangle {
return new Triangle(copyVectors(this.points), copyAttribs(this));
return <Triangle>copyShape(Triangle, this);
}

toHiccup() {
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 @@ -79,6 +79,7 @@ export * from "./ops/with-attribs";

export * from "./internal/coll-bounds";
export * from "./internal/copy-attribs";
export * from "./internal/copy-shape";
export * from "./internal/edges";
export * from "./internal/pclike";
export * from "./internal/points-as-shape";
Expand Down
6 changes: 6 additions & 0 deletions packages/geom/src/internal/copy-shape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PCLike, PCLikeConstructor } from "@thi.ng/geom-api";
import { copyVectors } from "@thi.ng/vectors";
import { copyAttribs } from "./copy-attribs";

export const copyShape = (ctor: PCLikeConstructor, inst: PCLike) =>
new ctor(copyVectors(inst.points), copyAttribs(inst));

0 comments on commit bc20135

Please sign in to comment.