- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
export class Vector extends Array {
constructor(dimensions, noInit) {
super(dimensions);
if (noInit) {
return;
}
for (let i = 0; i < dimensions; i++) {
this[i] = 0;
}
}
/**
* The no. of components of this vector
* @type {number}
*/
get dimensions() {
return this.length;
}
/**
* Whether this and `vec` are compatible vectors (same dimensions)
* @param {Vector} vec
* @return {boolean}
*/
isCompat(vec) {
return this.length === vec.length;
}
/**
* Whether this and `vec` are equal vectors
*
* @param {Vector} vec
* @return {boolean}
*/
equalTo(vec) {
return true;
}
/**
* Add `vec` to this
*
* @param {Vector} vec
*/
add(vec) {
}
static create3D(x = 0, y = 0, z = 0) {
const vector = new Vector(3, true);
vector[0] = x;
vector[1] = y;
vector[2] = z;
return vector;
}
}
/**
* A 3D vector
* @typedef {Vector[]}VectorArray
* @property {object} meta
*/
// TODO: Support the following as we these are resolved to Docs
/*
@property {boolean} meta.isPlanar
* @property {boolean} meta.isLinear
* @property {boolean} meta.isDegenerate
*/