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