MCPcopy Index your code
hub / github.com/graphif/project-graph / averageMultiple

Method averageMultiple

packages/data-structures/src/Vector.ts:244–253  ·  view source on GitHub ↗

* 计算多个向量所代表位置的平均点 * @param vectors 向量数组 * @returns 平均位置向量

(vectors: Vector[])

Source from the content-addressed store, hash-verified

242 * @returns 平均位置向量
243 */
244 static averageMultiple(vectors: Vector[]): Vector {
245 if (vectors.length === 0) {
246 return Vector.getZero();
247 }
248
249 const sumX = vectors.reduce((sum, vec) => sum + vec.x, 0);
250 const sumY = vectors.reduce((sum, vec) => sum + vec.y, 0);
251
252 return new Vector(sumX / vectors.length, sumY / vectors.length);
253 }
254 /**
255 * 将自己这个向量转换成角度数字
256 * 例如当自己 x=1 y=1 时,返回 45

Callers 3

Vector.test.tsFile · 0.80
renderCircleMethod · 0.80
collisionBoxMethod · 0.80

Calls 1

getZeroMethod · 0.80

Tested by

no test coverage detected