import { UpdatedRecorder } from "./UpdatedRecorder"; /** * A vector with three dimensions */ class Vector3D extends UpdatedRecorder implements ArrayLike, Iterable { private value0: number = 0; private value1: number = 0; private value2: number = 0; readonly [n: number]: number; /** * Vector length */ public get length(): number { return 3; }; public override toString(): string { return `Vector3D(${this.value0},${this.value1},${this.value2})`; } /** * Enumerate this vector */ public *[Symbol.iterator](): Iterator { yield this.value0; yield this.value1; yield this.value2; } /** * The first component of this vector */ public get [0](): number { return this.value0; } public set [0](newValue: number) { if (!this.updateFlag && this.value0 !== newValue) { this.updateFlag = true; } this.value0 = newValue; } /** * The second component of this vector */ public get [1](): number { return this.value1; } public set [1](newValue: number) { if (!this.updateFlag && this.value1 !== newValue) { this.updateFlag = true; } this.value1 = newValue; } /** * The third component of this vector */ public get [2](): number { return this.value2; } public set [2](newValue: number) { if (!this.updateFlag && this.value2 !== newValue) { this.updateFlag = true; } this.value2 = newValue; } /** * X component of the vector */ public get x(): number { return this.value0; } public set x(newValue: number) { this[0] = newValue; } /** * Y component of the vector */ public get y(): number { return this.value1; } public set y(newValue: number) { this[1] = newValue; } /** * Z component of the vector */ public get z(): number { return this.value2; } public set z(newValue: number) { this[2] = newValue; } } export { Vector3D };