| 1 | // The familiar Vec type. |
| 2 | |
| 3 | class Vec { |
| 4 | constructor(x, y) { |
| 5 | this.x = x; this.y = y; |
| 6 | } |
| 7 | plus(other) { |
| 8 | return new Vec(this.x + other.x, this.y + other.y); |
| 9 | } |
| 10 | minus(other) { |
| 11 | return new Vec(this.x - other.x, this.y - other.y); |
| 12 | } |
| 13 | times(factor) { |
| 14 | return new Vec(this.x * factor, this.y * factor); |
| 15 | } |
| 16 | get length() { |
| 17 | return Math.sqrt(this.x * this.x + this.y * this.y); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // Since we will want to inspect the layouts our code produces, let's |
| 22 | // first write code to draw a graph onto a canvas. Since we don't know |
nothing calls this directly
no outgoing calls
no test coverage detected