Skip to content

Instantly share code, notes, and snippets.

@radzionc
Created February 25, 2018 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radzionc/4891be4ae3151d4e6fc1be2ceea90e30 to your computer and use it in GitHub Desktop.
Save radzionc/4891be4ae3151d4e6fc1be2ceea90e30 to your computer and use it in GitHub Desktop.
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