Skip to content

Commit

Permalink
feat:Only arrow functions in the class can be packaged
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Mar 23, 2020
1 parent 84bbd9d commit 70c50c8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/graphin/src/layout/force/Point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class Point {
this.data = data;
}

updateAcc(force: Vector) {
updateAcc = (force: Vector) => {
/**
* 加速度也是一个向量,根据力的平行四边形法则进行力的合成,用向量运算就是加运算
*/
this.a = this.a.add(force.divide(this.m)); // a = a + F/m
}
};
}
export default Point;
28 changes: 14 additions & 14 deletions packages/graphin/src/layout/force/Vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,33 @@ class Vector {
this.y = y;
}

getvec() {
getvec = () => {
return this;
}
};

add(v2: Vector) {
add = (v2: Vector) => {
return new Vector(this.x + v2.x, this.y + v2.y);
}
};

subtract(v2: Vector) {
subtract = (v2: Vector) => {
return new Vector(this.x - v2.x, this.y - v2.y);
}
};

magnitude() {
magnitude = () => {
return Math.sqrt(this.x * this.x + this.y * this.y);
}
};

normalise() {
normalise = () => {
return this.divide(this.magnitude());
}
};

divide(n: number) {
divide = (n: number) => {
return new Vector(this.x / n || 0, this.y / n || 0);
}
};

scalarMultip(n: number) {
scalarMultip = (n: number) => {
return new Vector(this.x * n, this.y * n);
}
};
}

export default Vector;

0 comments on commit 70c50c8

Please sign in to comment.