From 8b63f9d27f090adbad3d855dbe50276b35446be4 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Mon, 13 Jul 2020 22:00:19 +0100 Subject: [PATCH] refactor(geom): update various shape ctors --- packages/geom/src/api/aabb.ts | 8 ++----- packages/geom/src/api/apc.ts | 8 +------ packages/geom/src/api/arc.ts | 36 ++++++++------------------------ packages/geom/src/api/circle.ts | 14 +++++-------- packages/geom/src/api/ellipse.ts | 8 ++----- packages/geom/src/api/group.ts | 11 ++++------ packages/geom/src/api/plane.ts | 14 +++++-------- packages/geom/src/api/ray.ts | 10 +-------- packages/geom/src/api/rect.ts | 10 ++++----- packages/geom/src/api/sphere.ts | 14 +++++-------- 10 files changed, 39 insertions(+), 94 deletions(-) diff --git a/packages/geom/src/api/aabb.ts b/packages/geom/src/api/aabb.ts index ed5d0435b5..50bf93512a 100644 --- a/packages/geom/src/api/aabb.ts +++ b/packages/geom/src/api/aabb.ts @@ -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() { diff --git a/packages/geom/src/api/apc.ts b/packages/geom/src/api/apc.ts index 5e167e834f..cc58f9b33d 100644 --- a/packages/geom/src/api/apc.ts +++ b/packages/geom/src/api/apc.ts @@ -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; diff --git a/packages/geom/src/api/arc.ts b/packages/geom/src/api/arc.ts index 2fcede0814..2c00d686c0 100644 --- a/packages/geom/src/api/arc.ts +++ b/packages/geom/src/api/arc.ts @@ -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; diff --git a/packages/geom/src/api/circle.ts b/packages/geom/src/api/circle.ts index e44d26c927..bbc803d3cf 100644 --- a/packages/geom/src/api/circle.ts +++ b/packages/geom/src/api/circle.ts @@ -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; diff --git a/packages/geom/src/api/ellipse.ts b/packages/geom/src/api/ellipse.ts index 3825050391..56255d1757 100644 --- a/packages/geom/src/api/ellipse.ts +++ b/packages/geom/src/api/ellipse.ts @@ -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() { diff --git a/packages/geom/src/api/group.ts b/packages/geom/src/api/group.ts index db47898dbc..59cc9ef3d1 100644 --- a/packages/geom/src/api/group.ts +++ b/packages/geom/src/api/group.ts @@ -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; diff --git a/packages/geom/src/api/plane.ts b/packages/geom/src/api/plane.ts index 84a5865a29..e2b2cd9f89 100644 --- a/packages/geom/src/api/plane.ts +++ b/packages/geom/src/api/plane.ts @@ -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; diff --git a/packages/geom/src/api/ray.ts b/packages/geom/src/api/ray.ts index eab6fc0c7e..594f070e58 100644 --- a/packages/geom/src/api/ray.ts +++ b/packages/geom/src/api/ray.ts @@ -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; diff --git a/packages/geom/src/api/rect.ts b/packages/geom/src/api/rect.ts index 2ad1e91d9d..ceb4866409 100644 --- a/packages/geom/src/api/rect.ts +++ b/packages/geom/src/api/rect.ts @@ -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() { diff --git a/packages/geom/src/api/sphere.ts b/packages/geom/src/api/sphere.ts index 95f5f5aaf7..04fb486ea2 100644 --- a/packages/geom/src/api/sphere.ts +++ b/packages/geom/src/api/sphere.ts @@ -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;