Skip to content

Commit

Permalink
Add vector functions to Point
Browse files Browse the repository at this point in the history
  • Loading branch information
una-ada committed Jun 3, 2021
1 parent c678eb5 commit 3ad606d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions js/modules/Utils.js
Expand Up @@ -71,6 +71,21 @@ export class Point {
this.y *= scalar;
return this;
}
/**
* Get a copy of this Point as a Vector.
* @returns {Vector} Copy of this Point as a Vector.
*/
copyAsVector() {
return new Vector(this.x, this.y);
}
/**
* Get a Vector between two points.
* @param {Point} point
* @returns {Vector} A Vector between this Point and another Point.
*/
vectorTo(point) {
return point.copyAsVector().subtract(this);
}

/*----- Methods ------------------------------------------------------------*/
/**
Expand Down

0 comments on commit 3ad606d

Please sign in to comment.