Skip to content

Commit

Permalink
refactor(geom): update various shape ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 13, 2020
1 parent deb9892 commit 8b63f9d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 94 deletions.
8 changes: 2 additions & 6 deletions packages/geom/src/api/aabb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import { add3, set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class AABB implements AABBLike {
pos: Vec;
size: Vec;
attribs?: Attribs;

constructor(
pos: Vec = [0, 0, 0],
public pos: Vec = [0, 0, 0],
size: number | Vec = 1,
attribs?: Attribs
public attribs?: Attribs
) {
this.pos = pos;
this.size = isNumber(size) ? [size, size, size] : size;
this.attribs = attribs;
}

get type() {
Expand Down
8 changes: 1 addition & 7 deletions packages/geom/src/api/apc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@ import type { Attribs, IShape, PCLike } from "@thi.ng/geom-api";
import type { Vec } from "@thi.ng/vectors";

export abstract class APC implements PCLike {
points: Vec[];
attribs?: Attribs;

constructor(points?: Vec[], attribs?: Attribs) {
this.points = points || [];
this.attribs = attribs;
}
constructor(public points: Vec[] = [], public attribs?: Attribs) {}

abstract get type(): number | string;
abstract copy(): IShape;
Expand Down
36 changes: 9 additions & 27 deletions packages/geom/src/api/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,16 @@ import { set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Arc implements IHiccupShape, IHiccupPathSegment {
pos: Vec;
r: Vec;
start: number;
end: number;
axis: number;
xl: boolean;
cw: boolean;
attribs?: Attribs;

constructor(
pos: Vec,
r: Vec,
axis: number,
start: number,
end: number,
xl = false,
cw = false,
attribs?: Attribs
) {
this.pos = pos;
this.r = r;
this.axis = axis;
this.start = start;
this.end = end;
this.xl = xl;
this.cw = cw;
this.attribs = attribs;
}
public pos: Vec,
public r: Vec,
public axis: number,
public start: number,
public end: number,
public xl = false,
public cw = false,
public attribs?: Attribs
) {}

get type() {
return Type.ARC;
Expand Down
14 changes: 5 additions & 9 deletions packages/geom/src/api/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import { set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Circle implements IHiccupShape {
pos: Vec;
r: number;
attribs?: Attribs;

constructor(pos: Vec = [0, 0], r = 1, attribs?: Attribs) {
this.pos = pos;
this.r = r;
this.attribs = attribs;
}
constructor(
public pos: Vec = [0, 0],
public r = 1,
public attribs?: Attribs
) {}

get type() {
return Type.CIRCLE;
Expand Down
8 changes: 2 additions & 6 deletions packages/geom/src/api/ellipse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@ import { set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Ellipse implements IHiccupShape {
pos: Vec;
r: Vec;
attribs?: Attribs;

constructor(
pos: Vec = [0, 0],
public pos: Vec = [0, 0],
r: number | Vec = [1, 1],
attribs?: Attribs
public attribs?: Attribs
) {
this.pos = pos;
this.r = isNumber(r) ? [r, r] : r;
this.attribs = attribs;
}

get type() {
Expand Down
11 changes: 4 additions & 7 deletions packages/geom/src/api/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ import { Attribs, IHiccupShape, Type } from "@thi.ng/geom-api";
import { copyAttribs } from "../internal/copy-attribs";

export class Group implements IHiccupShape {
children: IHiccupShape[];
attribs: Attribs;

constructor(attribs: Attribs, children?: IHiccupShape[]) {
this.attribs = attribs;
this.children = children || [];
}
constructor(
public attribs: Attribs,
public children: IHiccupShape[] = []
) {}

get type() {
return Type.GROUP;
Expand Down
14 changes: 5 additions & 9 deletions packages/geom/src/api/plane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import { set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Plane implements IHiccupShape {
normal: Vec;
w: number;
attribs?: Attribs;

constructor(normal: Vec = [0, 1, 0], w = 0, attribs?: Attribs) {
this.normal = normal;
this.w = w;
this.attribs = attribs;
}
constructor(
public normal: Vec = [0, 1, 0],
public w = 0,
public attribs?: Attribs
) {}

get type() {
return Type.PLANE;
Expand Down
10 changes: 1 addition & 9 deletions packages/geom/src/api/ray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,7 @@ import { maddN2, set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Ray implements IHiccupShape {
pos: Vec;
dir: Vec;
attribs?: Attribs;

constructor(pos: Vec, dir: Vec, attribs?: Attribs) {
this.pos = pos;
this.dir = dir;
this.attribs = attribs;
}
constructor(public pos: Vec, public dir: Vec, public attribs?: Attribs) {}

get type() {
return Type.RAY;
Expand Down
10 changes: 5 additions & 5 deletions packages/geom/src/api/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { add2, set, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Rect implements AABBLike, IHiccupShape {
pos: Vec;
size: Vec;
attribs?: Attribs;

constructor(pos: Vec = [0, 0], size: number | Vec = 1, attribs?: Attribs) {
this.pos = pos;
constructor(
public pos: Vec = [0, 0],
size: number | Vec = 1,
public attribs?: Attribs
) {
this.size = isNumber(size) ? [size, size] : size;
this.attribs = attribs;
}

get type() {
Expand Down
14 changes: 5 additions & 9 deletions packages/geom/src/api/sphere.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ import { set3, Vec } from "@thi.ng/vectors";
import { copyAttribs } from "../internal/copy-attribs";

export class Sphere implements IHiccupShape {
pos: Vec;
r: number;
attribs?: Attribs;

constructor(pos: Vec = [0, 0, 0], r = 1, attribs?: Attribs) {
this.pos = pos;
this.r = r;
this.attribs = attribs;
}
constructor(
public pos: Vec = [0, 0, 0],
public r = 1,
public attribs?: Attribs
) {}

get type() {
return Type.SPHERE;
Expand Down

0 comments on commit 8b63f9d

Please sign in to comment.