Skip to content

Commit

Permalink
Add Point#copy and Vector#copy
Browse files Browse the repository at this point in the history
  • Loading branch information
una-ada committed Jun 3, 2021
1 parent aacc885 commit ccffba8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions js/modules/Utils.js
Expand Up @@ -18,6 +18,17 @@ export class Point {
/** @var {number} Point#y - The point's y coordinate. */
this.y = y;
}



/*----- Methods ------------------------------------------------------------*/
/**
* Create a point of the point.
* @returns {Point} A copy of the point.
*/
copy() {
return new Point(this.x, this.y);
}
/**
* Update coordinates.
* @arg {number} x - New x coordinate.
Expand Down Expand Up @@ -62,4 +73,13 @@ export class Vector extends Point {
this.x = magnitude * Math.cos(direction);
this.y = magnitude * Math.sin(direction);
}

/*----- Methods ------------------------------------------------------------*/
/**
* Create a copy of the vector.
* @returns {Vector} A copy of the vector.
*/
copy() {
return new Vector(this.x, this.y);
}
}

0 comments on commit ccffba8

Please sign in to comment.