All files Point.js

100% Statements 8/8
100% Branches 0/0
100% Functions 6/6
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51                                  5681x         5681x       400x             800x       400x       800x       400x       8x  
/**
 * Represents a set of co-ordinates on a 2D plane
 *
 * @class Point
 */
class Point {
    /**
     * Creates an instance of Point.
     * @param {number} x X position
     * @param {number} y Y position
     *
     * @memberof Point
     */
    constructor (x, y) {
        /**
         * @type {number}
         */
        this.x = x;
 
        /**
         * @type {number}
         */
        this.y = y;
    }
 
    distance(pt) {
        return Math.sqrt(
            Math.pow(pt.x-this.x,2)+
            Math.pow(pt.y-this.y,2)
        )
    }
 
    subtract(pt) {
        return new Point(this.x-pt.x, this.y-pt.y)
    }
 
    magnitude() {
        return Math.sqrt(this.dotProduct(this))
    }
 
    dotProduct(v) {
        return this.x*v.x + this.y*v.y
    }
 
    divide(scalar) {
        return new Point(this.x/scalar, this.y/scalar)
    }
}
 
module.exports = Point;