MCPcopy
hub / github.com/graphif/project-graph / normalize

Method normalize

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

* 获得向量的单位向量 * 如果向量的模长为0,则返回(0,0) * @returns

()

Source from the content-addressed store, hash-verified

52 * @returns
53 */
54 normalize(): Vector {
55 const mag = this.magnitude();
56 const x = this.x / mag;
57 const y = this.y / mag;
58
59 if (Number.isNaN(x) || Number.isNaN(y)) {
60 return Vector.getZero();
61 }
62
63 return new Vector(x, y);
64 }
65
66 dot(vector: Vector): number {
67 return this.x * vector.x + this.y * vector.y;

Callers 15

splitVectorMethod · 0.95
bezierMethod · 0.80
getPerpendicularMethod · 0.80
Vector.test.tsFile · 0.80
collectFanNodesMethod · 0.80
logicTickMethod · 0.80
constructorMethod · 0.80
constructorMethod · 0.80
tickMethod · 0.80
renderCuttingFlashMethod · 0.80
renderArrowMethod · 0.80

Calls 2

magnitudeMethod · 0.95
getZeroMethod · 0.80

Tested by

no test coverage detected