Created
February 25, 2018 09:26
-
-
Save radzionc/4891be4ae3151d4e6fc1be2ceea90e30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Point { | |
constructor(x, y) { | |
this.x = x | |
this.y = y | |
} | |
equalTo(other) { | |
return areEqual(this.x, other.x) && areEqual(this.y, other.y) | |
} | |
addVector(vector) { | |
return new Point(this.x + vector.x, this.y + vector.y) | |
} | |
distanceTo(other) { | |
return Math.hypot(this.x - other.x, this.y - other.y) | |
} | |
array() { | |
return [this.x, this.y] | |
} | |
vectorTo({ x, y }) { | |
return new Vector(x - this.x, y - this.y) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment