diff --git a/viz/ts/svg/thinkChart/Math/Vector.ts b/viz/ts/svg/thinkChart/Math/Vector.ts index 8beca98..13f6164 100644 --- a/viz/ts/svg/thinkChart/Math/Vector.ts +++ b/viz/ts/svg/thinkChart/Math/Vector.ts @@ -1,6 +1,38 @@ -namespace Math2D { +/// - export class Vector { +namespace Math2D { + export class Vector extends IEnumerator { + + public constructor(x: number[] | IEnumerator) { + super(x); + } + + public Add(x: number | IEnumerator | Vector): Vector { + var type = TypeInfo.typeof(x); + var out: number[] = []; + + if (type.typeOf == "number") { + x = x; + + for (var i: number = 0; i < this.Count; i++) { + out.push(x + this.sequence[i]); + } + } else if (type.IsEnumerator || type.class == "Vector") { + x = >x; + + if (x.Count != this.Count) { + throw `Two sequence length not agree!`; + } + + for (var i: number = 0; i < this.Count; i++) { + out.push(x.ElementAt(i) + this.sequence[i]); + } + } else { + throw `Unsupported type: ${type.class}!`; + } + + return new Vector(out); + } } } \ No newline at end of file