From 7b3ceb03ff66ff1b7d784a7dadc96989a2ca4e82 Mon Sep 17 00:00:00 2001 From: xieguigang Date: Wed, 12 Sep 2018 08:16:40 +0800 Subject: [PATCH] vector add --- viz/ts/svg/thinkChart/Math/Vector.ts | 36 ++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) 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